Neos\Flow\Aop\Pointcut\PointcutClassNameFilter::matches PHP Метод

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

Checks if the specified class matches with the class filter pattern
public matches ( string $className, string $methodName, string $methodDeclaringClassName, mixed $pointcutQueryIdentifier ) : boolean
$className string Name of the class to check against
$methodName string Name of the method - not used here
$methodDeclaringClassName string Name of the class the method was originally declared in - not used here
$pointcutQueryIdentifier mixed Some identifier for this query - must at least differ from a previous identifier. Used for circular reference detection.
Результат boolean TRUE if the class matches, otherwise FALSE
    public function matches($className, $methodName, $methodDeclaringClassName, $pointcutQueryIdentifier)
    {
        try {
            $matchResult = preg_match($this->classFilterExpression, $className);
        } catch (\Exception $exception) {
            throw new Exception('Error in regular expression "' . $this->classFilterExpression . '" in pointcut class filter', 1292324509, $exception);
        }
        if ($matchResult === false) {
            throw new Exception('Error in regular expression "' . $this->classFilterExpression . '" in pointcut class filter', 1168876955);
        }
        return $matchResult === 1;
    }

Usage Example

 /**
  * Checks if the class filter fires on a concrete and simple class expression
  *
  * @test
  */
 public function matchesTellsIfTheSpecifiedRegularExpressionMatchesTheGivenClassName()
 {
     $mockReflectionService = $this->getMockBuilder(ReflectionService::class)->disableOriginalConstructor()->getMock();
     $classFilter = new Aop\Pointcut\PointcutClassNameFilter('Neos\\Virtual\\Foo\\Bar');
     $classFilter->injectReflectionService($mockReflectionService);
     $this->assertTrue($classFilter->matches('Neos\\Virtual\\Foo\\Bar', '', '', 1), 'No. 1');
     $classFilter = new Aop\Pointcut\PointcutClassNameFilter('.*Virtual.*');
     $classFilter->injectReflectionService($mockReflectionService);
     $this->assertTrue($classFilter->matches('Neos\\Virtual\\Foo\\Bar', '', '', 1), 'No. 2');
     $classFilter = new Aop\Pointcut\PointcutClassNameFilter('Neos\\Firtual.*');
     $classFilter->injectReflectionService($mockReflectionService);
     $this->assertFalse($classFilter->matches('Neos\\Virtual\\Foo\\Bar', '', '', 1), 'No. 3');
 }