1 | <?php |
||
22 | abstract class AbstractProxy |
||
23 | { |
||
24 | |||
25 | /** |
||
26 | * Indent for source code |
||
27 | * |
||
28 | * @var int |
||
29 | */ |
||
30 | protected $indent = 4; |
||
31 | |||
32 | /** |
||
33 | * List of advices that are used for generation of child |
||
34 | * |
||
35 | * @var array |
||
36 | */ |
||
37 | protected $advices = []; |
||
38 | |||
39 | /** |
||
40 | * PHP expression string for accessing LSB information |
||
41 | * |
||
42 | * @var string |
||
43 | */ |
||
44 | protected static $staticLsbExpression = 'static::class'; |
||
45 | |||
46 | /** |
||
47 | * Whether or not proxy should use parameter widening |
||
48 | * |
||
49 | * @see https://wiki.php.net/rfc/parameter-no-type-variance |
||
50 | * |
||
51 | * @var bool |
||
52 | */ |
||
53 | private $useParameterWidening; |
||
54 | |||
55 | /** |
||
56 | * Constructs an abstract proxy class |
||
57 | * |
||
58 | * @param array $advices List of advices |
||
59 | * @param bool $useParameterWidening Should proxy use parameter widening feature |
||
60 | */ |
||
61 | 5 | public function __construct(array $advices = [], bool $useParameterWidening = false) |
|
66 | |||
67 | /** |
||
68 | * Returns text representation of class |
||
69 | * |
||
70 | * @return string |
||
71 | */ |
||
72 | abstract public function __toString(); |
||
73 | |||
74 | /** |
||
75 | * Indent block of code |
||
76 | * |
||
77 | * @param string $text Non-indented text |
||
78 | * |
||
79 | * @return string Indented text |
||
80 | */ |
||
81 | 5 | protected function indent(string $text): string |
|
90 | |||
91 | /** |
||
92 | * Returns list of string representation of parameters |
||
93 | * |
||
94 | * @param array|ReflectionParameter[] $parameters List of parameters |
||
95 | * |
||
96 | * @return array|string[] |
||
97 | */ |
||
98 | 5 | protected function getParameters(array $parameters): array |
|
107 | |||
108 | /** |
||
109 | * Return string representation of parameter |
||
110 | * |
||
111 | * @param ReflectionParameter $parameter Reflection parameter |
||
112 | * |
||
113 | * @return string |
||
114 | */ |
||
115 | 3 | protected function getParameterCode(ReflectionParameter $parameter): string |
|
142 | |||
143 | /** |
||
144 | * Replace concrete advices with list of ids |
||
145 | * |
||
146 | * @param array $advices List of advices |
||
147 | * |
||
148 | * @return array flatten list of advices |
||
149 | */ |
||
150 | 5 | private function flattenAdvices(array $advices): array |
|
163 | |||
164 | /** |
||
165 | * Prepares a line with args from the method definition |
||
166 | * |
||
167 | * @param ReflectionFunctionAbstract $functionLike |
||
168 | * |
||
169 | * @return string |
||
170 | */ |
||
171 | 5 | protected function prepareArgsLine(ReflectionFunctionAbstract $functionLike): string |
|
199 | |||
200 | /** |
||
201 | * Creates a function code from Reflection |
||
202 | * |
||
203 | * @param ReflectionFunctionAbstract $functionLike Reflection for method |
||
204 | * @param string $body Body of method |
||
205 | * |
||
206 | * @return string |
||
207 | */ |
||
208 | 5 | protected function getOverriddenFunction(ReflectionFunctionAbstract $functionLike, string $body): string |
|
240 | } |
||
241 |