modufolio / appkit

Appkit

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PHP-DI and Fast-Route example

Example project with dependency injection container and routing samples.

Getting Started

Installing

Install deps via composer

composer install

Running

Start php server

php -S localhost:8080 -t web/

Container

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(),
];

Routes

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);
});

Built With

License

This project is licensed under the MIT License - see the LICENSE.md file for details

About

Appkit

License:MIT License


Languages

Language:PHP 100.0%