dkx / slim-injectable-routes
This package is abandoned and no longer maintained.
No replacement package was suggested.
Inject custom arguments into route callbacks
0.0.1
2019-02-03 13:39 UTC
Requires
- php: ^7.2
- dkx/method-injector: ^0.0.1
- psr/http-message: ^1.0
- slim/slim: ^3.12
Requires (Dev)
- mockery/mockery: dev-master
- phpunit/phpunit: ^8.0
This package is auto-updated.
Last update: 2024-02-05 01:58:32 UTC
README
Inject custom arguments into slim route callbacks
Supports only class routes!
Installation
$ composer require dkx/slim-injectable-routes
Usage
<?php
use DKX\SlimInjectableRoutes\InjectableRoutes;
use DKX\MethodInjector\MethodInjector;
use Slim\Container;
$c = new Container();
$c['foundHandler'] = function() {
$routes = new InjectableRoutes;
$routes->provideInjectableSetup(function(MethodInjector $injector) {
$injector->provideValue(\stdClass::class, new \stdClass);
});
return $routes;
};
Now you will be able to automatically inject the stdClass
into your route like this:
<?php
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;
final class MyRoute
{
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, array $args, \stdClass $std): ResponseInterface
{
// ...
return $response;
}
}
To find more information about the MethodInjector
see the documentation for
dkx/method-injector.