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