1
1
<?php
2
- /*
3
- * This file is part of the Mouf core package.
4
- *
5
- * (c) 2012 David Negrier <[email protected] >
6
- *
7
- * For the full copyright and license information, please view the LICENSE.txt
8
- * file that was distributed with this source code.
9
- */
2
+ /*
3
+ * This file is part of the Mouf core package.
4
+ *
5
+ * (c) 2012 David Negrier <[email protected] >
6
+ *
7
+ * For the full copyright and license information, please view the LICENSE.txt
8
+ * file that was distributed with this source code.
9
+ */
10
10
namespace Mouf \Reflection ;
11
-
12
- use Mouf \MoufPropertyDescriptor ;
11
+
12
+ use Mouf \MoufPropertyDescriptor ;
13
13
14
14
/**
15
15
* Extended Reflection class for class properties that allows usage of annotations.
@@ -154,57 +154,57 @@ public function equals($compare)
154
154
* getDeclaringClass fixing the problem with traits
155
155
* (non-PHPdoc)
156
156
* @see ReflectionProperty::getDeclaringClass()
157
- */
157
+ */
158
158
function getDeclaringClass () {
159
- if ($ this ->declaringClass ) {
160
- return $ this ->declaringClass ;
161
- }
162
-
163
- // Let's scan all traits
164
- $ trait = $ this ->deepScanTraitsForProperty ($ this ->refClass ->getTraits ());
159
+ if ($ this ->declaringClass ) {
160
+ return $ this ->declaringClass ;
161
+ }
162
+
163
+ // Let's scan all traits
164
+ $ trait = $ this ->deepScanTraitsForProperty ($ this ->refClass ->getTraits ());
165
165
if ($ trait != null ) {
166
- $ this ->declaringClass = $ trait ;
167
- return $ trait ;
166
+ $ this ->declaringClass = $ trait ;
167
+ return $ trait ;
168
168
}
169
169
170
170
if ($ this ->refClass ->getParentClass ()) {
171
171
$ declaringClass = null ;
172
172
if ($ this ->refClass ->getParentClass ()->hasProperty ($ this ->getName ())) {
173
173
$ declaringClass = $ this ->refClass ->getParentClass ()->getProperty ($ this ->getName ())->getDeclaringClass ();
174
174
}
175
- if ($ declaringClass != null ) {
176
- return $ declaringClass ;
177
- }
178
- }
179
- if ($ this ->refClass ->hasProperty ($ this ->getName ())) {
180
- return $ this ->refClass ;
175
+ if ($ declaringClass != null ) {
176
+ return $ declaringClass ;
177
+ }
178
+ }
179
+ if ($ this ->refClass ->hasProperty ($ this ->getName ())) {
180
+ return $ this ->refClass ;
181
181
}
182
182
return null ;
183
-
183
+
184
184
// The property is not part of the traits, let's find in which parent it is part of.
185
185
/*$this->declaringClass = $this->getDeclaringClassWithoutTraits();
186
- return $this->declaringClass;*/
187
- }
188
-
189
- /**
190
- * Recursive method called to detect a method into a nested array of traits.
191
- *
192
- * @param $traits ReflectionClass[]
193
- * @return ReflectionClass|null
194
- */
195
- private function deepScanTraitsForProperty (array $ traits ) {
196
- foreach ($ traits as $ trait ) {
197
- // If the trait has a property, it's a win!
198
- $ result = $ this ->deepScanTraitsForProperty ($ trait ->getTraits (), $ this ->getName ());
199
- if ($ result != null ) {
200
- return $ result ;
201
- } else {
202
- if ($ trait ->hasProperty ($ this ->getName ())) {
203
- return $ trait ;
204
- }
205
- }
206
- }
207
- return null ;
186
+ return $this->declaringClass;*/
187
+ }
188
+
189
+ /**
190
+ * Recursive method called to detect a method into a nested array of traits.
191
+ *
192
+ * @param $traits ReflectionClass[]
193
+ * @return ReflectionClass|null
194
+ */
195
+ private function deepScanTraitsForProperty (array $ traits ) {
196
+ foreach ($ traits as $ trait ) {
197
+ // If the trait has a property, it's a win!
198
+ $ result = $ this ->deepScanTraitsForProperty ($ trait ->getTraits (), $ this ->getName ());
199
+ if ($ result != null ) {
200
+ return $ result ;
201
+ } else {
202
+ if ($ trait ->hasProperty ($ this ->getName ())) {
203
+ return $ trait ;
204
+ }
205
+ }
206
+ }
207
+ return null ;
208
208
}
209
209
210
210
/**
@@ -271,7 +271,7 @@ public function toXml(\SimpleXMLElement $root) {
271
271
$ node ->appendChild ($ no ->createCDATASection ($ this ->getDocComment ()));
272
272
273
273
274
- $ propertyNode ->addAttribute ("modifier " , $ this ->isPrivate () ? 'private ' : $ this ->isProtected () ? "protected " : "public " );
274
+ $ propertyNode ->addAttribute ("modifier " , $ this ->isPrivate () ? 'private ' : ( $ this ->isProtected () ? "protected " : "public " ) );
275
275
$ propertyNode ->addAttribute ("is_static " , $ this ->isStatic () ? "true " : "false " );
276
276
277
277
@@ -286,46 +286,46 @@ public function toXml(\SimpleXMLElement $root) {
286
286
}
287
287
}
288
288
289
-
290
- /**
291
- * Returns a PHP array representing the property.
292
- *
293
- * @return array
294
- */
295
- public function toJson () {
296
- $ result = array ();
297
- $ result ['name ' ] = $ this ->getName ();
298
- $ result ['comment ' ] = $ this ->getMoufPhpDocComment ()->getJsonArray ();
299
-
300
- /*$properties = $this->getAnnotations("Property");
301
- if (!empty($properties)) {
289
+
290
+ /**
291
+ * Returns a PHP array representing the property.
292
+ *
293
+ * @return array
294
+ */
295
+ public function toJson () {
296
+ $ result = array ();
297
+ $ result ['name ' ] = $ this ->getName ();
298
+ $ result ['comment ' ] = $ this ->getMoufPhpDocComment ()->getJsonArray ();
299
+
300
+ /*$properties = $this->getAnnotations("Property");
301
+ if (!empty($properties)) {
302
302
$result['moufProperty'] = true;*/
303
303
304
- try {
304
+ try {
305
305
$ result ['default ' ] = $ this ->getDefault ();
306
306
307
- // TODO: is there a need to instanciate a MoufPropertyDescriptor?
308
- $ moufPropertyDescriptor = new MoufPropertyDescriptor ($ this );
309
- $ types = $ moufPropertyDescriptor ->getTypes ();
310
- $ result ['types ' ] = $ types ->toJson ();
311
-
312
- if ($ types ->getWarningMessage ()) {
313
- $ result ['classinerror ' ] = $ types ->getWarningMessage ();
307
+ // TODO: is there a need to instanciate a MoufPropertyDescriptor?
308
+ $ moufPropertyDescriptor = new MoufPropertyDescriptor ($ this );
309
+ $ types = $ moufPropertyDescriptor ->getTypes ();
310
+ $ result ['types ' ] = $ types ->toJson ();
311
+
312
+ if ($ types ->getWarningMessage ()) {
313
+ $ result ['classinerror ' ] = $ types ->getWarningMessage ();
314
314
}
315
315
316
- } catch (\Exception $ e ) {
317
- $ result ['classinerror ' ] = $ e ->getMessage ();
318
- }
319
- /*if ($moufPropertyDescriptor->isAssociativeArray()) {
320
- $result['keytype'] = $moufPropertyDescriptor->getKeyType();
321
- }
322
- if ($moufPropertyDescriptor->isArray()) {
323
- $result['subtype'] = $moufPropertyDescriptor->getSubType();
324
- }*/
325
- //}
326
-
327
- return $ result ;
328
- }
316
+ } catch (\Exception $ e ) {
317
+ $ result ['classinerror ' ] = $ e ->getMessage ();
318
+ }
319
+ /*if ($moufPropertyDescriptor->isAssociativeArray()) {
320
+ $result['keytype'] = $moufPropertyDescriptor->getKeyType();
321
+ }
322
+ if ($moufPropertyDescriptor->isArray()) {
323
+ $result['subtype'] = $moufPropertyDescriptor->getSubType();
324
+ }*/
325
+ //}
326
+
327
+ return $ result ;
328
+ }
329
329
330
330
}
331
331
?>
0 commit comments