Add MethodMapInterface

This commit is contained in:
PJ Dietz 2015-04-06 20:24:59 -04:00
parent cb87660548
commit 45b13691a2
3 changed files with 38 additions and 8 deletions

View File

@ -5,22 +5,30 @@ namespace WellRESTed\Routing;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
class MethodMap implements MiddlewareInterface
class MethodMap implements MiddlewareInterface, MethodMapInterface
{
protected $map;
/**
* @param array $map
*/
public function __construct(array $map = null)
public function __construct($map = null)
{
$this->map = [];
if ($map) {
$this->addMap($map);
}
}
/**
* @param array $map
*/
public function addMap($map)
{
foreach ($map as $method => $middleware) {
$this->add($method, $middleware);
}
}
}
/**
* @param string $method

View File

@ -0,0 +1,17 @@
<?php
namespace WellRESTed\Routing;
interface MethodMapInterface
{
/**
* @param array $map
*/
public function addMap($map);
/**
* @param string $method
* @param mixed $middleware
*/
public function add($method, $middleware);
}

View File

@ -44,7 +44,9 @@ class Router implements MiddlewareInterface
public function add($target, $middleware, $extra = null)
{
if (is_array($middleware)) {
$middleware = $this->getMethodMap($middleware);
$map = $this->getMethodMap();
$map->addMap($middleware);
$middleware = $map;
}
$this->routeFactory->registerRoute($this->routeTable, $target, $middleware, $extra);
}
@ -70,9 +72,12 @@ class Router implements MiddlewareInterface
}
}
protected function getMethodMap(array $map)
/**
* @return MethodMapInterface
*/
protected function getMethodMap()
{
return new MethodMap($map);
return new MethodMap();
}
/**