Neos\Flow\Security\RequestPattern\Ip::matchRequest PHP Метод

matchRequest() публичный Метод

Matches a \Neos\Flow\Mvc\RequestInterface against the set IP pattern rules
public matchRequest ( Neos\Flow\Mvc\RequestInterface $request ) : boolean
$request Neos\Flow\Mvc\RequestInterface The request that should be matched
Результат boolean TRUE if the pattern matched, FALSE otherwise
    public function matchRequest(RequestInterface $request)
    {
        if (!isset($this->options['cidrPattern'])) {
            throw new InvalidRequestPatternException('Missing option "cidrPattern" in the Ip request pattern configuration', 1446224520);
        }
        if (!$request instanceof ActionRequest) {
            return false;
        }
        return (bool) IpUtility::cidrMatch($request->getHttpRequest()->getClientIpAddress(), $this->options['cidrPattern']);
    }

Usage Example

Пример #1
0
 /**
  * @dataProvider validAndInvalidIpPatterns
  * @test
  */
 public function requestMatchingBasicallyWorks($pattern, $ip, $expected)
 {
     $requestMock = $this->getMockBuilder(Request::class)->disableOriginalConstructor()->setMethods(array('getClientIpAddress'))->getMock();
     $requestMock->expects($this->once())->method('getClientIpAddress')->will($this->returnValue($ip));
     $actionRequestMock = $this->getMockBuilder(ActionRequest::class)->disableOriginalConstructor()->getMock();
     $actionRequestMock->expects($this->any())->method('getHttpRequest')->will($this->returnValue($requestMock));
     $requestPattern = new Ip(['cidrPattern' => $pattern]);
     $this->assertEquals($expected, $requestPattern->matchRequest($actionRequestMock));
 }