1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
/* |
4
|
|
|
* Go! AOP framework |
5
|
|
|
* |
6
|
|
|
* @copyright Copyright 2018, Lisachenko Alexander <[email protected]> |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the license that is bundled |
9
|
|
|
* with this source code in the file LICENSE. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Go\Proxy\Part; |
13
|
|
|
|
14
|
|
|
use Laminas\Code\Generator\TypeGenerator; |
15
|
|
|
use ReflectionMethod; |
16
|
|
|
use Laminas\Code\Generator\DocBlockGenerator; |
17
|
|
|
use Laminas\Code\Generator\MethodGenerator; |
18
|
|
|
use Laminas\Code\Reflection\DocBlockReflection; |
19
|
|
|
use ReflectionNamedType; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Prepares the definition of intercepted method |
23
|
|
|
*/ |
24
|
|
|
final class InterceptedMethodGenerator extends MethodGenerator |
25
|
|
|
{ |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* InterceptedMethod constructor. |
29
|
|
|
* |
30
|
|
|
* @param ReflectionMethod $reflectionMethod Instance of original method |
31
|
|
|
* @param string $body Method body |
32
|
17 |
|
* @param bool $useTypeWidening Should generator use parameter widening for PHP>=7.2 |
33
|
|
|
*/ |
34
|
17 |
|
public function __construct(ReflectionMethod $reflectionMethod, string $body, bool $useTypeWidening = false) |
35
|
|
|
{ |
36
|
17 |
|
parent::__construct($reflectionMethod->getName()); |
37
|
|
|
|
38
|
17 |
|
$declaringClass = $reflectionMethod->getDeclaringClass(); |
39
|
1 |
|
|
40
|
|
|
if ($reflectionMethod->hasReturnType()) { |
41
|
|
|
$reflectionReturnType = $reflectionMethod->getReturnType(); |
42
|
17 |
|
if ($reflectionReturnType instanceof ReflectionNamedType) { |
|
|
|
|
43
|
4 |
|
$returnTypeName = $reflectionReturnType->getName(); |
44
|
4 |
|
} else { |
45
|
|
|
$returnTypeName = (string) $reflectionReturnType; |
46
|
|
|
} |
47
|
17 |
|
$this->setReturnType($returnTypeName); |
48
|
|
|
} |
49
|
17 |
|
|
50
|
1 |
|
if ($reflectionMethod->getDocComment()) { |
51
|
16 |
|
$reflectionDocBlock = new DocBlockReflection($reflectionMethod->getDocComment()); |
52
|
4 |
|
$this->setDocBlock(DocBlockGenerator::fromReflection($reflectionDocBlock)); |
53
|
|
|
} |
54
|
13 |
|
|
55
|
|
|
$this->setFinal($reflectionMethod->isFinal()); |
56
|
|
|
|
57
|
17 |
|
if ($reflectionMethod->isPrivate()) { |
58
|
17 |
|
$this->setVisibility(self::VISIBILITY_PRIVATE); |
59
|
17 |
|
} elseif ($reflectionMethod->isProtected()) { |
60
|
17 |
|
$this->setVisibility(self::VISIBILITY_PROTECTED); |
61
|
|
|
} else { |
62
|
17 |
|
$this->setVisibility(self::VISIBILITY_PUBLIC); |
63
|
17 |
|
} |
64
|
17 |
|
|
65
|
17 |
|
$this->setInterface($declaringClass->isInterface()); |
66
|
|
|
$this->setStatic($reflectionMethod->isStatic()); |
67
|
|
|
$this->setReturnsReference($reflectionMethod->returnsReference()); |
68
|
|
|
$this->setName($reflectionMethod->getName()); |
69
|
|
|
|
70
|
|
|
$parameterList = new FunctionParameterList($reflectionMethod, $useTypeWidening); |
71
|
|
|
$this->setParameters($parameterList->getGeneratedParameters()); |
72
|
|
|
$this->setBody($body); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|