3 ms·
What is nice is that it easier than ever to write minimal framework, somethings I think you should accept, like using composer and some of the common libraries,
by tored 4y ago
What is nice is that it easier than ever to write minimal framework, somethings I think you should accept, like using composer and some of the common libraries, however bootstrapping is something I prefer to do myself. I'm having a renaissance with minimal PHP framework.
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.