/** * @param $resourceName * @param $primaryKey * @dataProvider testResourceResolverWhirRoutDataProvider */ public function testResourceResolver__invokeWithRouting($resourceName, $primaryKey) { $this->request = new ServerRequest([], []); $this->request = $this->request->withAttribute("resourceName", $resourceName); $this->request = $this->request->withAttribute("id", $primaryKey); $this->next = function ($req, $resp) { return $req; }; $responseResolver = $this->object->__invoke($this->request, $this->response, $this->next); $this->assertEquals($responseResolver->getAttribute('Resource-Name'), $resourceName); $this->assertEquals($responseResolver->getAttribute('Primary-Key-Value'), $primaryKey); }
/** * @return mixed|null */ public function getRoute() { $this->_routeMap->sortRoutes(); foreach ($this->_routeMap as $route) { if ($this->_request->getMethod() !== $route->getRequestMethod()) { continue; } $route->replaceTokens(); if (preg_match(sprintf("#^%s\$#i", $route->getPattern()), $this->_request->getUri()->getPath(), $matches)) { $this->_request = $this->_request->withAttribute('match', $route->getPattern()); foreach ($matches as $key => $value) { if (!is_int($key)) { $this->_request = $this->_request->withAttribute($key, $value); } } return $route; } } return null; }