diff --git a/README.md b/README.md index f163789..39fd69b 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ Middleware to use [FastRoute](https://github.com/nikic/FastRoute). * PHP >= 5.6 * A [PSR-7](https://packagist.org/providers/psr/http-message-implementation) http mesage implementation ([Diactoros](https://github.com/zendframework/zend-diactoros), [Guzzle](https://github.com/guzzle/psr7), [Slim](https://github.com/slimphp/Slim), etc...) * A [PSR-15 middleware dispatcher](https://github.com/middlewares/awesome-psr15-middlewares#dispatcher) +* Optionally, a [PSR-11](https://github.com/php-fig/container) container to resolve the route handlers ## Installation @@ -56,8 +57,7 @@ $response = $dispatcher->dispatch(new ServerRequest('/hello/world')); * If the string is the name of a existing class (like: `Namespace\Class`) and contains the method `__invoke`, create a instance and execute that method. * Otherwise, treat it as a callable. -If you want to change this behaviour, use a container implementing the [container-interop](https://github.com/container-interop/container-interop) to return the route callable. - +If you want to change this behaviour, use a container implementing the [PSR-11 spec](https://github.com/php-fig/container) to return the route callable. ## Options @@ -65,9 +65,9 @@ If you want to change this behaviour, use a container implementing the [containe The dispatcher instance to use. -#### `resolver(Interop\Container\ContainerInterface $resolver)` +#### `resolver(Psr\Container\ContainerInterface $resolver)` -To use a container implementing [container-interop](https://github.com/container-interop/container-interop) to resolve the route handlers. +To use a container implementing [PSR-11 interface](https://github.com/php-fig/container) to resolve the route handlers. #### `arguments(...$args)` diff --git a/src/FastRoute.php b/src/FastRoute.php index 43795c5..0fd006f 100644 --- a/src/FastRoute.php +++ b/src/FastRoute.php @@ -2,6 +2,8 @@ namespace Middlewares; +use Middlewares\Utils\Factory; +use Middlewares\Utils\CallableHandler; use Middlewares\Utils\CallableResolver\CallableResolverInterface; use Middlewares\Utils\CallableResolver\ContainerResolver; use Middlewares\Utils\CallableResolver\ReflectionResolver; @@ -78,11 +80,11 @@ public function process(ServerRequestInterface $request, DelegateInterface $dele $route = $this->router->dispatch($request->getMethod(), $request->getUri()->getPath()); if ($route[0] === Dispatcher::NOT_FOUND) { - return Utils\Factory::createResponse(404); + return Factory::createResponse(404); } if ($route[0] === Dispatcher::METHOD_NOT_ALLOWED) { - return Utils\Factory::createResponse(405); + return Factory::createResponse(405); } foreach ($route[2] as $name => $value) { @@ -93,7 +95,7 @@ public function process(ServerRequestInterface $request, DelegateInterface $dele $callable = $this->getResolver()->resolve($route[1], $arguments); - return Utils\CallableHandler::execute($callable, $arguments); + return CallableHandler::execute($callable, $arguments); } /**