Skip to content
This repository has been archived by the owner on Oct 23, 2022. It is now read-only.

Latest commit

 

History

History
59 lines (41 loc) · 1.62 KB

README.md

File metadata and controls

59 lines (41 loc) · 1.62 KB

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