|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Accessible\Reader; |
|
4
|
|
|
|
|
5
|
|
|
class AccessReader extends Reader |
|
6
|
|
|
{ |
|
7
|
|
|
/** |
|
8
|
|
|
* The name of the annotation class that define the properties access. |
|
9
|
|
|
* |
|
10
|
|
|
* @var string |
|
11
|
|
|
*/ |
|
12
|
|
|
private static $accessAnnotationClass = "Accessible\\Annotation\\Access"; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Get a list of properties and the access that are given to them for given object. |
|
16
|
|
|
* |
|
17
|
|
|
* @param array $properties The properties of the object to read. |
|
18
|
|
|
* @param Reader $annotationReader The annotation reader to use. |
|
19
|
|
|
* |
|
20
|
|
|
* @return array The list of properties and their access. |
|
21
|
|
|
*/ |
|
22
|
7 |
|
public static function getAccessProperties($properties, $annotationReader) |
|
23
|
|
|
{ |
|
24
|
7 |
|
$objectAccessProperties = array(); |
|
25
|
|
|
|
|
26
|
7 |
|
foreach ($properties as $propertyName => $property) { |
|
27
|
7 |
|
if (empty($objectAccessProperties[$propertyName])) { |
|
28
|
7 |
|
$objectAccessProperties[$propertyName] = array(); |
|
29
|
7 |
|
} |
|
30
|
|
|
|
|
31
|
|
|
// Getters / Setters related annotations |
|
32
|
7 |
|
$propertyAccessAnnotation = $annotationReader->getPropertyAnnotation($property, self::$accessAnnotationClass); |
|
|
|
|
|
|
33
|
|
|
|
|
34
|
7 |
|
$accessProperties = array(); |
|
35
|
7 |
|
if ($propertyAccessAnnotation !== null) { |
|
36
|
7 |
|
$accessProperties = $propertyAccessAnnotation->getAccessProperties(); |
|
37
|
7 |
|
} |
|
38
|
|
|
|
|
39
|
|
|
// Collection related annotations |
|
40
|
7 |
|
$collectionAnnotation = null; |
|
41
|
7 |
|
foreach (self::$collectionAnnotationClasses as $annotationBehavior => $annotationClass) { |
|
42
|
7 |
|
$collectionAnnotation = $annotationReader->getPropertyAnnotation($property, $annotationClass); |
|
|
|
|
|
|
43
|
7 |
|
if ($collectionAnnotation !== null) { |
|
44
|
6 |
|
break; |
|
45
|
|
|
} |
|
46
|
7 |
|
} |
|
47
|
|
|
|
|
48
|
7 |
|
$collectionMethods = array(); |
|
49
|
7 |
|
if ($collectionAnnotation !== null) { |
|
50
|
6 |
|
$collectionMethods = $collectionAnnotation->getMethods(); |
|
51
|
6 |
|
} |
|
52
|
|
|
|
|
53
|
|
|
// Merge and save the two arrays |
|
54
|
7 |
|
$objectAccessProperties[$propertyName] = array_merge($accessProperties, $collectionMethods); |
|
55
|
7 |
|
} |
|
56
|
|
|
|
|
57
|
7 |
|
return $objectAccessProperties; |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.