From 45b13691a2035a58a1f1cdbe7b790fb41aeef240 Mon Sep 17 00:00:00 2001 From: PJ Dietz Date: Mon, 6 Apr 2015 20:24:59 -0400 Subject: [PATCH] Add MethodMapInterface --- src/Routing/MethodMap.php | 18 +++++++++++++----- src/Routing/MethodMapInterface.php | 17 +++++++++++++++++ src/Routing/Router.php | 11 ++++++++--- 3 files changed, 38 insertions(+), 8 deletions(-) create mode 100644 src/Routing/MethodMapInterface.php diff --git a/src/Routing/MethodMap.php b/src/Routing/MethodMap.php index 422c235..98c6598 100644 --- a/src/Routing/MethodMap.php +++ b/src/Routing/MethodMap.php @@ -5,20 +5,28 @@ 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) { - foreach ($map as $method => $middleware) { - $this->add($method, $middleware); - } + $this->addMap($map); + } + } + + /** + * @param array $map + */ + public function addMap($map) + { + foreach ($map as $method => $middleware) { + $this->add($method, $middleware); } } diff --git a/src/Routing/MethodMapInterface.php b/src/Routing/MethodMapInterface.php new file mode 100644 index 0000000..8513080 --- /dev/null +++ b/src/Routing/MethodMapInterface.php @@ -0,0 +1,17 @@ +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(); } /**