Skip to content

Commit

Permalink
updated utils to 2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarotero committed Aug 2, 2018
1 parent 1fd6587 commit e840b82
Showing 1 changed file with 5 additions and 21 deletions.
26 changes: 5 additions & 21 deletions src/FastRoute.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
namespace Middlewares;

use FastRoute\Dispatcher;
use Middlewares\Utils\Factory;
use Psr\Http\Message\ResponseFactoryInterface;
use Middlewares\Utils\Traits\HasResponseFactory;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;

class FastRoute implements MiddlewareInterface
{
use HasResponseFactory;

/**
* @var Dispatcher FastRoute dispatcher
*/
Expand All @@ -23,11 +24,6 @@ class FastRoute implements MiddlewareInterface
*/
private $attribute = 'request-handler';

/**
* @var ResponseFactoryInterface
*/
private $responseFactory;

/**
* Set the Dispatcher instance.
*/
Expand All @@ -46,16 +42,6 @@ public function attribute(string $attribute): self
return $this;
}

/**
* Set the response factory to return the error responses.
*/
public function responseFactory(ResponseFactoryInterface $responseFactory): self
{
$this->responseFactory = $responseFactory;

return $this;
}

/**
* Process a server request and return a response.
*/
Expand All @@ -64,13 +50,11 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
$route = $this->router->dispatch($request->getMethod(), $request->getUri()->getPath());

if ($route[0] === Dispatcher::NOT_FOUND) {
$responseFactory = $this->responseFactory ?: Factory::getResponseFactory();
return $responseFactory->createResponse(404);
return $this->createResponse(404);
}

if ($route[0] === Dispatcher::METHOD_NOT_ALLOWED) {
$responseFactory = $this->responseFactory ?: Factory::getResponseFactory();
return $responseFactory->createResponse(405)->withHeader('Allow', implode(', ', $route[1]));
return $this->createResponse(405)->withHeader('Allow', implode(', ', $route[1]));
}

foreach ($route[2] as $name => $value) {
Expand Down

0 comments on commit e840b82

Please sign in to comment.