Checks if the specified class and method match the registered class-
and method filter patterns.
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 to check against |
$methodDeclaringClassName | string | Name of the class the method was originally declared in |
$pointcutQueryIdentifier | mixed | Some identifier for this query - must at least differ from a previous identifier. Used for circular reference detection. |
Résultat | boolean | TRUE if class and method match the pattern, otherwise FALSE |
/** * Checks if the given class and method match this pointcut. * Before each match run, reset() must be called to reset the circular references guard. * * @param string $className Class to check against * @param string $methodName Method to check against * @param string $methodDeclaringClassName Name of the class the method was originally declared in * @param mixed $pointcutQueryIdentifier Some identifier for this query - must at least differ from a previous identifier. Used for circular reference detection. * @return boolean TRUE if class and method match this point cut, otherwise FALSE * @throws CircularPointcutReferenceException if a circular pointcut reference was detected */ public function matches($className, $methodName, $methodDeclaringClassName, $pointcutQueryIdentifier) { if ($this->pointcutQueryIdentifier === $pointcutQueryIdentifier) { $this->recursionLevel++; if ($this->recursionLevel > self::MAXIMUM_RECURSIONS) { throw new CircularPointcutReferenceException('Circular pointcut reference detected in ' . $this->aspectClassName . '->' . $this->pointcutMethodName . ', too many recursions (Query identifier: ' . $pointcutQueryIdentifier . ').', 1172416172); } } else { $this->pointcutQueryIdentifier = $pointcutQueryIdentifier; $this->recursionLevel = 0; } return $this->pointcutFilterComposite->matches($className, $methodName, $methodDeclaringClassName, $pointcutQueryIdentifier); }
/** * @test */ public function matchesReturnsFalseEarlyForAndedNegatedSubfilters() { $mockPointcutFilter1 = $this->getMockBuilder(Pointcut\PointcutFilterInterface::class)->disableOriginalConstructor()->getMock(); $mockPointcutFilter1->expects($this->any())->method('getRuntimeEvaluationsDefinition')->will($this->returnValue(['eval'])); $mockPointcutFilter1->expects($this->once())->method('matches')->will($this->returnValue(true)); $mockPointcutFilter2 = $this->getMockBuilder(Pointcut\PointcutFilterInterface::class)->disableOriginalConstructor()->getMock(); $mockPointcutFilter2->expects($this->any())->method('getRuntimeEvaluationsDefinition')->will($this->returnValue(['eval'])); $mockPointcutFilter2->expects($this->never())->method('matches')->will($this->returnValue(true)); $pointcutFilterComposite = new Pointcut\PointcutFilterComposite(); $pointcutFilterComposite->addFilter('&&!', $mockPointcutFilter1); $pointcutFilterComposite->addFilter('&&', $mockPointcutFilter2); $this->assertFalse($pointcutFilterComposite->matches('someClass', 'someMethod', 'someDeclaringClass', 1)); }