1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Codeburner Framework. |
5
|
|
|
* |
6
|
|
|
* @author Alex Rohleder <[email protected]> |
7
|
|
|
* @copyright 2016 Alex Rohleder |
8
|
|
|
* @license http://opensource.org/licenses/MIT |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Codeburner\Annotator\Reflection; |
12
|
|
|
|
13
|
|
|
use ReflectionClass; |
14
|
|
|
use ReflectionProperty; |
15
|
|
|
use ReflectionMethod; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Avoid the autoload by manually including the required files. |
19
|
|
|
* This bust significantly the performance. |
20
|
|
|
*/ |
21
|
|
|
|
22
|
|
|
if (!trait_exists('Codeburner\Annotator\Reflection\AnnotationTrait', false)) { |
23
|
|
|
include __DIR__ . '/AnnotationTrait.php'; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Implements the annotation methods into the reflection. |
28
|
|
|
* |
29
|
|
|
* @author Alex Rohleder <[email protected]> |
30
|
|
|
*/ |
31
|
|
|
|
32
|
|
|
class ReflectionAnnotatedClass extends ReflectionClass |
33
|
|
|
{ |
34
|
|
|
|
35
|
|
|
use AnnotationTrait; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* {inheritDoc} |
39
|
|
|
*/ |
40
|
|
|
|
41
|
|
|
public function getProperties($filter = null) |
42
|
|
|
{ |
43
|
|
|
$defaultFilter = ReflectionProperty::IS_STATIC | ReflectionProperty::IS_PUBLIC | |
44
|
|
|
ReflectionProperty::IS_PROTECTED | ReflectionProperty::IS_PRIVATE; |
45
|
|
|
$properties = parent::getProperties($filter === null ? $defaultFilter : $filter); |
46
|
|
|
$annotatedProperties = []; |
47
|
|
|
|
48
|
|
|
foreach ($properties as $property) { |
49
|
|
|
$annotatedProperties[] = new ReflectionAnnotatedProperty($this->name, $property->name); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
return $annotatedProperties; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* {inheritDoc} |
57
|
|
|
*/ |
58
|
|
|
|
59
|
|
|
public function getProperty($name) |
60
|
|
|
{ |
61
|
|
|
return new ReflectionAnnotatedProperty($this->name, $name); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* {inheritDoc} |
66
|
|
|
*/ |
67
|
|
|
|
68
|
|
|
public function getMethods($filter = null) |
69
|
|
|
{ |
70
|
|
|
$defaultFilter = ReflectionMethod::IS_STATIC | ReflectionMethod::IS_PUBLIC | ReflectionMethod::IS_PROTECTED | |
71
|
|
|
ReflectionMethod::IS_PRIVATE | ReflectionMethod::IS_ABSTRACT | ReflectionMethod::IS_FINAL; |
72
|
|
|
$methods = parent::getMethods($filter === null ? $defaultFilter : $filter); |
73
|
|
|
$annotatedMethods = []; |
74
|
|
|
|
75
|
|
|
foreach ($methods as $method) { |
76
|
|
|
$annotatedMethods[] = new ReflectionAnnotatedMethod($this->name, $method->name); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
return $annotatedMethods; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* {inheritDoc} |
84
|
|
|
*/ |
85
|
|
|
|
86
|
|
|
public function getMethod($name) |
87
|
|
|
{ |
88
|
|
|
return new ReflectionAnnotatedMethod($this->name, $name); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* {inheritDoc} |
93
|
|
|
*/ |
94
|
|
|
|
95
|
|
|
public function getTraits($filter = null) |
|
|
|
|
96
|
|
|
{ |
97
|
|
|
$traits = parent::getTraits(); |
98
|
|
|
$annotatedTraits = []; |
99
|
|
|
|
100
|
|
|
foreach ($traits as $trait) { |
101
|
|
|
$annotatedTraits[] = new ReflectionAnnotatedClass($trait->name); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
return $annotatedTraits; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
} |
108
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.