1
|
|
|
<?php |
2
|
|
|
declare(strict_types = 1); |
3
|
|
|
/* |
4
|
|
|
* Go! AOP framework |
5
|
|
|
* |
6
|
|
|
* @copyright Copyright 2011, 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\Aop\Framework; |
13
|
|
|
|
14
|
|
|
use Go\Core\AspectContainer; |
15
|
|
|
use ReflectionClass; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Static initialization joinpoint is invoked after class is loaded into memory |
19
|
|
|
*/ |
20
|
|
|
class StaticInitializationJoinpoint extends AbstractJoinpoint |
21
|
|
|
{ |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var ReflectionClass |
25
|
|
|
*/ |
26
|
|
|
protected $reflectionClass; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Constructor for the class static initialization joinpoint |
30
|
|
|
* |
31
|
|
|
* @param $advices array List of advices for this invocation |
32
|
|
|
*/ |
33
|
1 |
|
public function __construct(string $className, string $unusedType, array $advices) |
34
|
|
|
{ |
35
|
1 |
|
$originalClass = $className; |
36
|
1 |
|
if (strpos($originalClass, AspectContainer::AOP_PROXIED_SUFFIX)) { |
37
|
1 |
|
$originalClass = substr($originalClass, 0, -strlen(AspectContainer::AOP_PROXIED_SUFFIX)); |
38
|
|
|
} |
39
|
1 |
|
$this->reflectionClass = new \ReflectionClass($originalClass); |
40
|
1 |
|
parent::__construct($advices); |
41
|
1 |
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Proceeds to the next interceptor in the chain. |
45
|
|
|
* |
46
|
|
|
* @return void Static initializtion could not return anything |
47
|
|
|
*/ |
48
|
1 |
|
public function proceed() |
49
|
|
|
{ |
50
|
1 |
|
if (isset($this->advices[$this->current])) { |
51
|
1 |
|
$currentInterceptor = $this->advices[$this->current++]; |
52
|
1 |
|
$currentInterceptor->invoke($this); |
53
|
|
|
} |
54
|
1 |
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Invokes current joinpoint with all interceptors |
58
|
|
|
*/ |
59
|
1 |
|
final public function __invoke(): void |
60
|
|
|
{ |
61
|
1 |
|
$this->current = 0; |
62
|
1 |
|
$this->proceed(); |
63
|
1 |
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Returns the object that holds the current joinpoint's static |
67
|
|
|
* part. |
68
|
|
|
* |
69
|
|
|
* @return object|null the object (can be null if the accessible object is |
70
|
|
|
* static). |
71
|
|
|
*/ |
72
|
|
|
public function getThis() |
73
|
|
|
{ |
74
|
|
|
return null; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Returns the static part of this joinpoint. |
79
|
|
|
* |
80
|
|
|
* @return ReflectionClass |
81
|
|
|
*/ |
82
|
|
|
public function getStaticPart() |
83
|
|
|
{ |
84
|
|
|
return $this->reflectionClass; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Returns a friendly description of current joinpoint |
89
|
|
|
*/ |
90
|
|
|
final public function __toString(): string |
91
|
|
|
{ |
92
|
|
|
return sprintf( |
93
|
|
|
'staticinitialization(%s)', |
94
|
|
|
$this->reflectionClass->getName() |
95
|
|
|
); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|