Example project with dependency injection container and routing samples.
Install deps via composer
composer install
Start php server
php -S localhost:8080 -t web/
PHP-DI is a dependency injection container meant to be practical, powerful, and framework-agnostic. In project there are two classes registered one for ServerRequestInterface and other one for custom ItemService class. Definitions are located in config/services.php file as an array. More information here
return [
ItemService::class => create(ItemService::class),
ServerRequestInterface::class => ServerRequestFactory::fromGlobals(),
];
In project is used middleware to handle FastRoute route definitions. Configuration is located in config/routes.php. Very intuitive and easy to use, controller class is matched to the routes and invoked as a handler. More information here.
return simpleDispatcher(function (RouteCollector $r) {
$r->get('/item/list', ItemList::class);
$r->get('/item/{id:\d+}', ItemSingle::class);
});