1 | <?php |
||
31 | class ExtraPropertyAnnotator { |
||
32 | |||
33 | /** |
||
34 | * @var AppFactory |
||
35 | */ |
||
36 | private $appFactory; |
||
37 | |||
38 | /** |
||
39 | * @var PropertyAnnotator[] |
||
40 | */ |
||
41 | private $propertyAnnotators = array(); |
||
42 | |||
43 | /** |
||
44 | * @var PropertyAnnotator |
||
45 | */ |
||
46 | private $localPropertyAnnotator; |
||
47 | |||
48 | /** |
||
49 | * @var array |
||
50 | */ |
||
51 | private $options; |
||
|
|||
52 | |||
53 | /** |
||
54 | * @since 2.0 |
||
55 | * |
||
56 | * @param AppFactory $appFactory |
||
57 | */ |
||
58 | 17 | public function __construct( AppFactory $appFactory ) { |
|
59 | 17 | $this->appFactory = $appFactory; |
|
60 | 17 | } |
|
61 | |||
62 | /** |
||
63 | * @since 2.0 |
||
64 | * |
||
65 | * @param SemanticData $semanticData |
||
66 | */ |
||
67 | 2 | public function addAnnotation( SemanticData $semanticData ) { |
|
68 | |||
69 | 2 | $time = microtime( true ); |
|
70 | |||
71 | 2 | if ( !$this->canAnnotate( $semanticData->getSubject() ) ) { |
|
72 | 1 | return; |
|
73 | } |
||
74 | |||
75 | 1 | $propertyDefinitions = $this->appFactory->getPropertyDefinitions(); |
|
76 | |||
77 | 1 | foreach ( $this->appFactory->getOption( 'sespSpecialProperties', array() ) as $key ) { |
|
78 | |||
79 | 1 | if ( !$propertyDefinitions->deepHas( $key, 'id' ) ) { |
|
80 | 1 | continue; |
|
81 | } |
||
82 | |||
83 | $property = new DIProperty( |
||
84 | $propertyDefinitions->deepGet( $key, 'id' ) |
||
85 | ); |
||
86 | |||
87 | if ( $propertyDefinitions->isLocalDef( $key ) ) { |
||
88 | $this->localPropertyAnnotator->addAnnotation( $property, $semanticData ); |
||
89 | } else { |
||
90 | $this->findPropertyAnnotator( $property )->addAnnotation( $property, $semanticData ); |
||
91 | } |
||
92 | 1 | } |
|
93 | |||
94 | 1 | $this->appFactory->getLogger()->info( |
|
95 | 1 | __METHOD__ . ' (procTime in sec: '. ( microtime( true ) - $time ) . ')' |
|
96 | 1 | ); |
|
97 | 1 | } |
|
98 | |||
99 | /** |
||
100 | * @since 2.0 |
||
101 | * |
||
102 | * @param DIProperty $property |
||
103 | * |
||
104 | * @return PropertyAnnotator |
||
105 | */ |
||
106 | 14 | public function findPropertyAnnotator( DIProperty $property ) { |
|
107 | |||
108 | 14 | $key = $property->getKey(); |
|
109 | |||
110 | 14 | if ( $this->propertyAnnotators === array() ) { |
|
111 | 14 | $this->initDefaultPropertyAnnotators(); |
|
112 | 14 | } |
|
113 | |||
114 | 14 | if ( isset( $this->propertyAnnotators[$key] ) && is_callable( $this->propertyAnnotators[$key] ) ) { |
|
115 | 13 | return call_user_func( $this->propertyAnnotators[$key], $this->appFactory ); |
|
116 | 1 | } elseif( isset( $this->propertyAnnotators[$key] ) ) { |
|
117 | return $this->propertyAnnotators[$key]; |
||
118 | } |
||
119 | |||
120 | 1 | return new NullPropertyAnnotator(); |
|
121 | } |
||
122 | |||
123 | /** |
||
124 | * @since 2.0 |
||
125 | * |
||
126 | * @param string $key |
||
127 | * @param Closure $callbak |
||
128 | */ |
||
129 | public function addPropertyAnnotator( $key, Closure $callback ) { |
||
132 | |||
133 | 2 | private function canAnnotate( $subject ) { |
|
134 | |||
135 | 2 | if ( $subject === null || $subject->getTitle() === null || $subject->getTitle()->isSpecialPage() ) { |
|
136 | 1 | return false; |
|
137 | } |
||
138 | |||
139 | 1 | $this->initDefaultPropertyAnnotators(); |
|
140 | |||
141 | 1 | return true; |
|
142 | } |
||
143 | |||
144 | 15 | private function initDefaultPropertyAnnotators() { |
|
208 | |||
209 | } |
||
210 |
This check marks private properties in classes that are never used. Those properties can be removed.