1 | <?php |
||
11 | class ClassMetadata |
||
12 | { |
||
13 | const LOGIN_PROPERTY = 1; |
||
14 | const PASSWORD_PROPERTY = 2; |
||
15 | const API_KEY_PROPERTY = 3; |
||
16 | const LAST_ACTION_PROPERTY = 4; |
||
17 | |||
18 | /** |
||
19 | * @var int[] |
||
20 | */ |
||
21 | private static $necessaryProperties = array( |
||
22 | self::LOGIN_PROPERTY => 'login', |
||
23 | self::PASSWORD_PROPERTY => 'password', |
||
24 | self::API_KEY_PROPERTY => 'apiKey', |
||
25 | ); |
||
26 | |||
27 | /** |
||
28 | * @var ReflectionClass |
||
29 | */ |
||
30 | private $reflectionInstance; |
||
31 | |||
32 | /** |
||
33 | * @var string |
||
34 | */ |
||
35 | private $className; |
||
36 | |||
37 | /** |
||
38 | * @var ReflectionProperty[] |
||
39 | */ |
||
40 | private $properties = array(); |
||
41 | |||
42 | /** |
||
43 | * @var string[] |
||
44 | */ |
||
45 | private $lazyPropertyNameCache = array(); |
||
46 | |||
47 | /** |
||
48 | * @var string[] |
||
49 | */ |
||
50 | private $lazyValueCache = array(); |
||
51 | |||
52 | /** |
||
53 | * Constructor. |
||
54 | * |
||
55 | * @param ReflectionClass $reflection |
||
56 | * @param string $className |
||
57 | * @param ReflectionProperty[] $properties |
||
58 | * |
||
59 | * @throws \InvalidArgumentException If one necessary property is missing |
||
60 | */ |
||
61 | 9 | public function __construct(ReflectionClass $reflection, $className, array $properties) |
|
76 | |||
77 | /** |
||
78 | * Gets the value of the given property. |
||
79 | * |
||
80 | * @param object $user |
||
81 | * @param int $property |
||
82 | * @param bool $strict |
||
83 | * |
||
84 | * @return mixed |
||
85 | */ |
||
86 | 3 | public function getPropertyValue($user, $property = self::LOGIN_PROPERTY, $strict = false) |
|
105 | |||
106 | /** |
||
107 | * Gets the name of a specific property by its metadata constant. |
||
108 | * |
||
109 | * @param int $property |
||
110 | * @param bool $strict |
||
111 | * |
||
112 | * @return null|string |
||
113 | */ |
||
114 | 6 | public function getPropertyName($property = self::LOGIN_PROPERTY, $strict = false) |
|
126 | |||
127 | /** |
||
128 | * Modifies a property and clears the cache. |
||
129 | * |
||
130 | * @param object $user |
||
131 | * @param mixed $newValue |
||
132 | * @param int $property |
||
133 | */ |
||
134 | 4 | public function modifyProperty($user, $newValue, $property = self::LOGIN_PROPERTY) |
|
144 | |||
145 | /** |
||
146 | * Validates a property. |
||
147 | * |
||
148 | * @param int $property |
||
149 | * @param bool $strict |
||
150 | * |
||
151 | * @return bool |
||
152 | */ |
||
153 | 7 | private function checkProperty($property = self::LOGIN_PROPERTY, $strict = false) |
|
168 | } |
||
169 |