InterceptorGenerator
in package
Utility to create pre- and post- method interceptors around a given method body
Tags
Table of Contents
- TEMPLATE = <<<'PHP' if (isset($this->{{$prefixInterceptorsName}}[{{$name}}])) { $returnEarly = false; $prefixReturnValue = $this->{{$prefixInterceptorsName}}[{{$name}}]->__invoke($this, $this->{{$valueHolderName}}, {{$name}}, {{$paramsString}}, $returnEarly); if ($returnEarly) { {{$returnEarlyPrefixExpression}} } } {{$methodBody}} if (isset($this->{{$suffixInterceptorsName}}[{{$name}}])) { $returnEarly = false; $suffixReturnValue = $this->{{$suffixInterceptorsName}}[{{$name}}]->__invoke($this, $this->{{$valueHolderName}}, {{$name}}, {{$paramsString}}, $returnValue, $returnEarly); if ($returnEarly) { {{$returnEarlySuffixExpression}} } } {{$returnExpression}} PHP
- createInterceptedMethodBody() : string
Constants
TEMPLATE
private
mixed
TEMPLATE
= <<<'PHP'
if (isset($this->{{$prefixInterceptorsName}}[{{$name}}])) {
$returnEarly = false;
$prefixReturnValue = $this->{{$prefixInterceptorsName}}[{{$name}}]->__invoke($this, $this->{{$valueHolderName}}, {{$name}}, {{$paramsString}}, $returnEarly);
if ($returnEarly) {
{{$returnEarlyPrefixExpression}}
}
}
{{$methodBody}}
if (isset($this->{{$suffixInterceptorsName}}[{{$name}}])) {
$returnEarly = false;
$suffixReturnValue = $this->{{$suffixInterceptorsName}}[{{$name}}]->__invoke($this, $this->{{$valueHolderName}}, {{$name}}, {{$paramsString}}, $returnValue, $returnEarly);
if ($returnEarly) {
{{$returnEarlySuffixExpression}}
}
}
{{$returnExpression}}
PHP
Methods
createInterceptedMethodBody()
public
static createInterceptedMethodBody(string $methodBody, MethodGenerator $method, PropertyGenerator $valueHolder, PropertyGenerator $prefixInterceptors, PropertyGenerator $suffixInterceptors, ReflectionMethod|null $originalMethod) : string
Parameters
- $methodBody : string
-
the body of the previously generated code. It MUST assign the return value to a variable
$returnValueinstead of directly returning - $method : MethodGenerator
- $valueHolder : PropertyGenerator
- $prefixInterceptors : PropertyGenerator
- $suffixInterceptors : PropertyGenerator
- $originalMethod : ReflectionMethod|null