Neos\Flow\Aop\Advice\AroundAdvice::invoke PHP Метод

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

Invokes the advice method
public invoke ( Neos\Flow\Aop\JoinPointInterface $joinPoint ) : mixed
$joinPoint Neos\Flow\Aop\JoinPointInterface The current join point which is passed to the advice method
Результат mixed Result of the advice method
    public function invoke(JoinPointInterface $joinPoint)
    {
        if ($this->runtimeEvaluator !== null && $this->runtimeEvaluator->__invoke($joinPoint, $this->objectManager) === false) {
            return $joinPoint->getAdviceChain()->proceed($joinPoint);
        }
        $adviceObject = $this->objectManager->get($this->aspectObjectName);
        $methodName = $this->adviceMethodName;
        return $adviceObject->{$methodName}($joinPoint);
    }

Usage Example

 /**
  * @test
  * @return void
  */
 public function invokeDoesNotInvokeTheAdviceIfTheRuntimeEvaluatorReturnsFalse()
 {
     $mockAdviceChain = $this->getMockBuilder(Aop\Advice\AdviceChain::class)->disableOriginalConstructor()->getMock();
     $mockAdviceChain->expects($this->once())->method('proceed')->will($this->returnValue('result'));
     $mockJoinPoint = $this->getMockBuilder(Aop\JoinPointInterface::class)->disableOriginalConstructor()->getMock();
     $mockJoinPoint->expects($this->any())->method('getAdviceChain')->will($this->returnValue($mockAdviceChain));
     $mockAspect = $this->createMock(Fixtures\SomeClass::class);
     $mockAspect->expects($this->never())->method('someMethod');
     $mockObjectManager = $this->getMockBuilder(ObjectManagerInterface::class)->disableOriginalConstructor()->getMock();
     $mockObjectManager->expects($this->any())->method('get')->will($this->returnValue($mockAspect));
     $advice = new Aop\Advice\AroundAdvice('aspectObjectName', 'someMethod', $mockObjectManager, function (Aop\JoinPointInterface $joinPoint) {
         if ($joinPoint !== null) {
             return false;
         }
     });
     $result = $advice->invoke($mockJoinPoint);
     $this->assertEquals($result, 'result', 'The around advice did not return the result value as expected.');
 }
AroundAdvice