public matchRequest ( Neos\Flow\Mvc\RequestInterface $request ) : boolean | ||
$request | Neos\Flow\Mvc\RequestInterface | The request that should be matched |
Résultat | boolean | TRUE if the pattern matched, FALSE otherwise |
public function matchRequest(RequestInterface $request)
{
if (!$request instanceof ActionRequest) {
return false;
}
if (!isset($this->options['uriPattern'])) {
throw new InvalidRequestPatternException('Missing option "uriPattern" in the Uri request pattern configuration', 1446224530);
}
return (bool) preg_match('/^' . str_replace('/', '\\/', $this->options['uriPattern']) . '$/', $request->getHttpRequest()->getUri()->getPath());
}
/** * @test * @dataProvider matchRequestDataProvider */ public function matchRequestTests($uriPath, $pattern, $shouldMatch) { $mockActionRequest = $this->getMockBuilder(ActionRequest::class)->disableOriginalConstructor()->getMock(); $mockHttpRequest = $this->getMockBuilder(Request::class)->disableOriginalConstructor()->getMock(); $mockActionRequest->expects($this->atLeastOnce())->method('getHttpRequest')->will($this->returnValue($mockHttpRequest)); $mockUri = $this->getMockBuilder(Uri::class)->disableOriginalConstructor()->getMock(); $mockHttpRequest->expects($this->atLeastOnce())->method('getUri')->will($this->returnValue($mockUri)); $mockUri->expects($this->atLeastOnce())->method('getPath')->will($this->returnValue($uriPath)); $requestPattern = new UriPattern(['uriPattern' => $pattern]); if ($shouldMatch) { $this->assertTrue($requestPattern->matchRequest($mockActionRequest)); } else { $this->assertFalse($requestPattern->matchRequest($mockActionRequest)); } }