1 | <?php |
||
24 | class Representation |
||
25 | { |
||
26 | |||
27 | /** |
||
28 | * Drest configuration object - referenced to same instance used in Manager |
||
29 | * @var Configuration $config |
||
30 | */ |
||
31 | protected $config; |
||
32 | |||
33 | /** |
||
34 | * A request instance for inspection |
||
35 | * Reset on each getDeterminedRepresentation() |
||
36 | * @var Request $request |
||
37 | */ |
||
38 | protected $request; |
||
39 | |||
40 | /** |
||
41 | * Doctrine Entity Manager Registry |
||
42 | * @var EntityManagerRegistry $emr |
||
43 | */ |
||
44 | protected $emr; |
||
45 | |||
46 | /** |
||
47 | * @param Configuration $config |
||
48 | */ |
||
49 | 31 | public function __construct(Configuration &$config) |
|
53 | |||
54 | /** |
||
55 | * Static call to create a representation instance |
||
56 | * @param Configuration $config |
||
57 | * @return Representation |
||
58 | */ |
||
59 | 31 | public static function create(Configuration &$config) |
|
63 | |||
64 | /** |
||
65 | * @param Request $request |
||
66 | * @param RouteMetaData $route |
||
67 | * @param EntityManagerRegistry $emr |
||
68 | * @return AbstractRepresentation |
||
69 | */ |
||
70 | 25 | public function handleExposureSettingsFromHttpMethod($request, $route, EntityManagerRegistry $emr) |
|
97 | |||
98 | /** |
||
99 | * Detect an instance of a representation class using a matched route, or default representation classes |
||
100 | * @param Request $request |
||
101 | * @param RouteMetaData $route |
||
102 | * @throws UnableToMatchRepresentationException |
||
103 | * @throws RepresentationException - if unable to instantiate a representation object from config settings |
||
104 | * @return AbstractRepresentation $representation |
||
105 | */ |
||
106 | 26 | public function getDeterminedRepresentation(Request $request, RouteMetaData &$route = null) |
|
126 | |||
127 | |||
128 | /** |
||
129 | * Handle a pull requests' exposure configuration (GET) |
||
130 | * @param RouteMetaData $route (referenced object) |
||
131 | */ |
||
132 | 18 | protected function handlePullExposureConfiguration(RouteMetaData &$route) |
|
145 | |||
146 | /** |
||
147 | * Handle a push requests' exposure configuration (POST/PUT/PATCH) |
||
148 | * @param RouteMetaData $route - the matched route |
||
149 | * @param AbstractRepresentation $representation - the representation class to be used |
||
150 | * @return AbstractRepresentation $representation |
||
151 | */ |
||
152 | 3 | protected function handlePushExposureConfiguration(RouteMetaData $route, AbstractRepresentation $representation) |
|
168 | |||
169 | /** |
||
170 | * Get representation options. Determined from route or config |
||
171 | * @param RouteMetaData|null $route |
||
172 | * @return array |
||
173 | */ |
||
174 | 26 | protected function getRepresentationClasses(RouteMetaData &$route = null) |
|
180 | |||
181 | |||
182 | /** |
||
183 | * Iterate through an array of representations and return a match |
||
184 | * @param array $representations |
||
185 | * @return AbstractRepresentation|null |
||
186 | * @throws RepresentationException |
||
187 | * @throws UnableToMatchRepresentationException |
||
188 | */ |
||
189 | 26 | protected function searchAndValidateRepresentations(array $representations) |
|
211 | |||
212 | |||
213 | /** |
||
214 | * Attempt to match a representation |
||
215 | * |
||
216 | * @param AbstractRepresentation|string $representation |
||
217 | * @param array $representationObjects |
||
218 | * @return AbstractRepresentation|null |
||
219 | * @throws RepresentationException |
||
220 | */ |
||
221 | 26 | protected function matchRepresentation($representation, array &$representationObjects) |
|
237 | |||
238 | /** |
||
239 | * Determine the representation by inspecting the HTTP method |
||
240 | * @param AbstractRepresentation $representation |
||
241 | * @param array $detectContentOptions - Eg array(self::DETECT_CONTENT_HEADER => 'Accept') |
||
242 | * @return AbstractRepresentation|null |
||
243 | */ |
||
244 | 26 | protected function determineRepresentationByHttpMethod(AbstractRepresentation $representation, array $detectContentOptions = []) |
|
265 | |||
266 | |||
267 | /** |
||
268 | * Get's the representation class name. |
||
269 | * Removes any root NS chars |
||
270 | * Falls back to a DrestCommon Representation lookup |
||
271 | * |
||
272 | * @param string $representation |
||
273 | * @return string |
||
274 | * @throws RepresentationException |
||
275 | */ |
||
276 | 26 | protected function getRepresentationClassName($representation) |
|
289 | } |
If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe: