weew / router-entities-resolver
Resolves doctrine entities in the weew/router package.
v1.0.2
2016-07-21 11:18 UTC
Requires
- doctrine/orm: ^2.5
- weew/router-container-aware: ^1.2
Requires (Dev)
- phpunit/phpunit: ^4.7
- satooshi/php-coveralls: ^0.6.1
This package is not auto-updated.
Last update: 2024-11-19 23:00:12 UTC
README
Table of contents
Installation
composer require weew/router-entities-resolver
Introduction
This package provides a convenient way to resolve doctrine entities in the weew/router package.
Usage
Pick an identifier for the entity to be referenced in the router and register a new resolver.
$router = new Router(new Container()); $resolver = new EntitiesResolver($router); $resolver ->resolve('user', UserRepository::class) ->resolve('role', RoleRepository::class);
Now you can resolve entities as with any regular parameter resolver.
$router->get('api/v1/users/{user}', function(User $user) { // entitiy will be injected instead of a user id }); // or $route = $router->match(HttpRequestMethod::GET, new Url('api/v1/users/1')); $user = $route->getParameter('user');