1 | <?php |
||
27 | class ClassMetaData implements \Serializable |
||
28 | { |
||
29 | |||
30 | /** |
||
31 | * An array of RouteMetaData objects defined on this entity |
||
32 | * @var array $routes |
||
33 | */ |
||
34 | protected $routes = []; |
||
35 | |||
36 | /** |
||
37 | * An array of \DrestCommon\Representation\AbstractRepresentation object defined on this entity |
||
38 | * @var array $representations |
||
39 | */ |
||
40 | protected $representations = []; |
||
41 | |||
42 | /** |
||
43 | * Name of the class that we collected metadata for (eg Entities\User) |
||
44 | * @var string $className |
||
45 | */ |
||
46 | protected $className; |
||
47 | |||
48 | /** |
||
49 | * A reflection of the class |
||
50 | * @var \ReflectionClass $reflection |
||
51 | */ |
||
52 | protected $reflection; |
||
53 | |||
54 | /** |
||
55 | * File path used to load this metadata |
||
56 | * @var string $fileResources |
||
57 | */ |
||
58 | public $filePath; |
||
59 | |||
60 | /** |
||
61 | * time this instance was created - current Unix timestamp |
||
62 | * @var integer $createdAt |
||
63 | */ |
||
64 | public $createdAt; |
||
65 | |||
66 | /** |
||
67 | * The origin route name - null if one isn't found |
||
68 | * @vat string $originRouteName |
||
69 | */ |
||
70 | public $originRouteName; |
||
71 | |||
72 | |||
73 | /** |
||
74 | * Construct an instance of this classes metadata |
||
75 | * @param \ReflectionClass $classRefl |
||
76 | */ |
||
77 | 62 | public function __construct(\ReflectionClass $classRefl) |
|
85 | |||
86 | /** |
||
87 | * Add a route metadata object |
||
88 | * @param RouteMetaData $route |
||
89 | */ |
||
90 | 43 | public function addRouteMetaData(RouteMetaData $route) |
|
95 | |||
96 | /** |
||
97 | * Get an array of all route metadata information. |
||
98 | * @return RouteMetaData[]|false $routes |
||
99 | */ |
||
100 | 34 | public function getRoutesMetaData() |
|
104 | |||
105 | /** |
||
106 | * Get metadata for a specific route. Returns false if entry cannot be found |
||
107 | * @param $name |
||
108 | * @return RouteMetaData|false $routes |
||
109 | */ |
||
110 | 45 | public function getRouteMetaData($name) |
|
118 | |||
119 | /** |
||
120 | * get the origin route (if one is available), otherwise attempts to determine it from a GET {path}/{primary_key} route |
||
121 | * @param EntityManager $em - Optionally pass the entity manager to assist in determining a GET origin location |
||
122 | * @return null|RouteMetaData $route |
||
123 | */ |
||
124 | 6 | public function getOriginRoute(EntityManager $em = null) |
|
149 | |||
150 | /** |
||
151 | * Add an array of representations |
||
152 | * @param array $representations |
||
153 | */ |
||
154 | 40 | public function addRepresentations(array $representations) |
|
160 | |||
161 | /** |
||
162 | * Set a representation instance to be used on this resource |
||
163 | * @param object|string $representation - can be either an instance of DrestCommon\Representation\AbstractRepresentation or a string (shorthand allowed - Json / Xml) referencing the class. |
||
164 | * @throws RepresentationException |
||
165 | */ |
||
166 | 44 | public function addRepresentation($representation) |
|
179 | |||
180 | /** |
||
181 | * Get the representations available on this resource |
||
182 | * @return array representations can be strings or an already instantiated object |
||
183 | */ |
||
184 | 29 | public function getRepresentations() |
|
188 | |||
189 | /** |
||
190 | * Get the metadata class name (immutable) |
||
191 | * @return string $className |
||
192 | */ |
||
193 | 37 | public function getClassName() |
|
197 | |||
198 | /** |
||
199 | * Get the text name that represents a single element. eg: user |
||
200 | * @return string $element_name |
||
201 | */ |
||
202 | 15 | public function getElementName() |
|
212 | |||
213 | /** |
||
214 | * Get an alias for this entity - used for DQL / QueryBuilder |
||
215 | * @param string $fieldName - The field the relation is on. Typical to root when using top level. |
||
216 | * @return string alias unique string representing this entity |
||
217 | */ |
||
218 | 24 | public function getEntityAlias($fieldName = 'rt') |
|
222 | |||
223 | /** |
||
224 | * Get a plural term for the element name |
||
225 | * @return string $collection_name |
||
226 | */ |
||
227 | 13 | public function getCollectionName() |
|
233 | |||
234 | /** |
||
235 | * Serialise this object |
||
236 | * @return string |
||
237 | */ |
||
238 | 1 | public function serialize() |
|
251 | |||
252 | /** |
||
253 | * Un-serialise this object and reestablish it's state |
||
254 | * @param string $string |
||
255 | */ |
||
256 | 1 | public function unserialize($string) |
|
273 | |||
274 | /** |
||
275 | * Check to see if this classes metadata has expired (file has been modified or deleted) |
||
276 | * @param timestamp |
||
277 | * @return bool |
||
278 | */ |
||
279 | 1 | public function expired($timestamp = null) |
|
291 | } |
||
292 |