Neos\Flow\Aop\Builder\AdvicedConstructorInterceptorBuilder::build PHP Method

build() public method

Builds interception PHP code for an adviced constructor
public build ( string $methodName, array $interceptedMethods, string $targetClassName ) : string
$methodName string Name of the method to build an interceptor for
$interceptedMethods array An array of method names and their meta information, including advices for the method (if any)
$targetClassName string Name of the target class to build the interceptor for
return string PHP code of the interceptor
    public function build($methodName, array $interceptedMethods, $targetClassName)
    {
        if ($methodName !== '__construct') {
            throw new Exception('The ' . __CLASS__ . ' can only build constructor interceptor code.', 1231789021);
        }
        $declaringClassName = $interceptedMethods[$methodName]['declaringClassName'];
        $proxyMethod = $this->compiler->getProxyClass($targetClassName)->getConstructor();
        if ($declaringClassName !== $targetClassName) {
            $proxyMethod->setMethodParametersCode($this->buildMethodParametersCode($declaringClassName, $methodName, true));
        }
        $groupedAdvices = $interceptedMethods[$methodName]['groupedAdvices'];
        $advicesCode = $this->buildAdvicesCode($groupedAdvices, $methodName, $targetClassName, $declaringClassName);
        if ($methodName !== null) {
            $proxyMethod->addPreParentCallCode('
        if (isset($this->Flow_Aop_Proxy_methodIsInAdviceMode[\'' . $methodName . '\'])) {
');
            $proxyMethod->addPostParentCallCode('
        } else {
            $this->Flow_Aop_Proxy_methodIsInAdviceMode[\'' . $methodName . '\'] = TRUE;
            try {
            ' . $advicesCode . '
            } catch (\\Exception $exception) {
                unset($this->Flow_Aop_Proxy_methodIsInAdviceMode[\'' . $methodName . '\']);
                throw $exception;
            }
            unset($this->Flow_Aop_Proxy_methodIsInAdviceMode[\'' . $methodName . '\']);
            return;
        }
');
        }
    }
AdvicedConstructorInterceptorBuilder