by dusted · 4y ago · 0 comments
I grew up on PHP, it was the first thing beyond BASIC I ever wrote, and I wrote a lot and enjoyed it so much. It really was this magic thing, that you just modified whatever file you needed to modify, throw it on the server, and hit f5 to see your changes reflected.. No processes to restart, no state to be lost, you jammed, and it was a very gentle way to learn.
Back then the "LAMP" stack was common enough that there were turnkey packages for Windows that setup "LAMP" for you. Was one called Wampp, or something? I forget. At first I liked using a particular proprietary web server for Windows called 'Sambar Server' which made learning easy due to its PHP support and web GUI config editor. Later setting up Apache, PHP and MySQL on a new Windows install became a common habit for me, once I learnt how to do it. I would make PHP websites and host them locally, then show them to people by giving them the IP (and this was over dialup!)
I really wish y'all would stop making me feel old by reminding me that there are now grown-ups who were children when PHP existed.
My current iteration looks something like this, and it is only a few functions to do it (I do use a router library, no point of reinventing that)
return
#[Route(method: 'GET', route: '/projects/{project_uid}/edit')]
#[Template(path: __DIR__ . '/template/template.php)]
function (Request $request, ProjectRepository $projectRepository) {
$projectUid = ProjectUid::of($request->vars['project_uid'] ?? '');
if ($projectUid === null) {
return [__DIR__ . '/../errorView.php', [400, 'Missing project_uid']];
}
$project = $projectRepository->getProjectByProjectUid($projectUid);
if ($project === null) {
return __DIR__ . '/../notFoundView.php';
}
?>
<div class="container">
<h1><?= escape($project->title) ?></h1>
</div>
<?php
};
Attributes is huge imporovemt to writing a small framework, attributes can not only be used for help setting up routing, HTML templating but other things as middlewares, output buffering, dependency injection.I think we should resist the takeover of large frameworks, and the thing is if you are architecting your application properly, it should be framework independent anyway. Unfortunately many ideas in large frameworks makes it harder or at least invites the developer to make the framework takeover the application.