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

Sample project with php-di and fast-route components.

License

Notifications You must be signed in to change notification settings

igornast/di-fast-route-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Sample project with php-di and fast-route components.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages