If empty all HTTP verbs are accepted
public setHttpMethods ( array $httpMethods ) : void | ||
$httpMethods | array | non-associative array in the format array('GET', 'POST', ...) |
return | void |
/** * @test */ public function routeMatchesIfRequestMethodIsAccepted() { $this->route->setUriPattern(''); $this->route->setHttpMethods(['POST', 'PUT']); /** @var Request|\PHPUnit_Framework_MockObject_MockObject $mockHttpRequest */ $mockHttpRequest = $this->getMockBuilder(Http\Request::class)->disableOriginalConstructor()->getMock(); $mockUri = $this->getMockBuilder(Http\Uri::class)->disableOriginalConstructor()->getMock(); $mockUri->expects($this->any())->method('getPath')->will($this->returnValue('/')); $mockHttpRequest->expects($this->any())->method('getUri')->will($this->returnValue($mockUri)); $mockBaseUri = $this->getMockBuilder(Http\Uri::class)->disableOriginalConstructor()->getMock(); $mockBaseUri->expects($this->any())->method('getPath')->will($this->returnValue('/')); $mockHttpRequest->expects($this->any())->method('getBaseUri')->will($this->returnValue($mockBaseUri)); $mockHttpRequest->expects($this->atLeastOnce())->method('getMethod')->will($this->returnValue('PUT')); $this->assertTrue($this->route->matches($mockHttpRequest), 'Route should match PUT requests if POST and PUT requests are accepted.'); }
/** * Creates \Neos\Flow\Mvc\Routing\Route objects from the injected routes * configuration. * * @return void * @throws InvalidRouteSetupException */ protected function createRoutesFromConfiguration() { if ($this->routesCreated === true) { return; } $this->initializeRoutesConfiguration(); $this->routes = []; $routesWithHttpMethodConstraints = []; foreach ($this->routesConfiguration as $routeConfiguration) { $route = new Route(); if (isset($routeConfiguration['name'])) { $route->setName($routeConfiguration['name']); } $uriPattern = $routeConfiguration['uriPattern']; $route->setUriPattern($uriPattern); if (isset($routeConfiguration['defaults'])) { $route->setDefaults($routeConfiguration['defaults']); } if (isset($routeConfiguration['routeParts'])) { $route->setRoutePartsConfiguration($routeConfiguration['routeParts']); } if (isset($routeConfiguration['toLowerCase'])) { $route->setLowerCase($routeConfiguration['toLowerCase']); } if (isset($routeConfiguration['appendExceedingArguments'])) { $route->setAppendExceedingArguments($routeConfiguration['appendExceedingArguments']); } if (isset($routeConfiguration['httpMethods'])) { if (isset($routesWithHttpMethodConstraints[$uriPattern]) && $routesWithHttpMethodConstraints[$uriPattern] === false) { throw new InvalidRouteSetupException(sprintf('There are multiple routes with the uriPattern "%s" and "httpMethods" option set. Please specify accepted HTTP methods for all of these, or adjust the uriPattern', $uriPattern), 1365678427); } $routesWithHttpMethodConstraints[$uriPattern] = true; $route->setHttpMethods($routeConfiguration['httpMethods']); } else { if (isset($routesWithHttpMethodConstraints[$uriPattern]) && $routesWithHttpMethodConstraints[$uriPattern] === true) { throw new InvalidRouteSetupException(sprintf('There are multiple routes with the uriPattern "%s" and "httpMethods" option set. Please specify accepted HTTP methods for all of these, or adjust the uriPattern', $uriPattern), 1365678432); } $routesWithHttpMethodConstraints[$uriPattern] = false; } $this->routes[] = $route; } $this->routesCreated = true; }
/** * Adds a route that can be used in the functional tests * * @param string $name Name of the route * @param string $uriPattern The uriPattern property of the route * @param array $defaults An array of defaults declarations * @param boolean $appendExceedingArguments If exceeding arguments may be appended * @param array $httpMethods An array of accepted http methods * @return Route * @api */ protected function registerRoute($name, $uriPattern, array $defaults, $appendExceedingArguments = false, array $httpMethods = null) { $route = new Route(); $route->setName($name); $route->setUriPattern($uriPattern); $route->setDefaults($defaults); $route->setAppendExceedingArguments($appendExceedingArguments); if ($httpMethods !== null) { $route->setHttpMethods($httpMethods); } $this->router->addRoute($route); return $route; }