1 | <?php |
||
21 | class SelectExclusionStrategy implements ExclusionStrategyInterface |
||
22 | { |
||
23 | /** |
||
24 | * @var RequestStack $requestStack |
||
25 | */ |
||
26 | protected $requestStack; |
||
27 | |||
28 | /** |
||
29 | * @var Array $selectedFields contains all the selected fields and its combinations with nested fields |
||
30 | */ |
||
31 | protected $selectedFields; |
||
32 | |||
33 | /** |
||
34 | * @var Array $selectedLeafs contains the leafs of the selection "tree" |
||
35 | */ |
||
36 | protected $selectedLeafs; |
||
37 | |||
38 | /** |
||
39 | * @var Boolean $isSelect |
||
40 | */ |
||
41 | protected $isSelect; |
||
42 | |||
43 | /** |
||
44 | * @var array $currentPath |
||
45 | */ |
||
46 | protected $currentPath; |
||
47 | |||
48 | /** |
||
49 | * @var Integer $currentDepth |
||
50 | */ |
||
51 | protected $currentDepth; |
||
52 | |||
53 | /** |
||
54 | * SelectExclusionStrategy constructor. |
||
55 | * Comstructor Injection of the global request_stack to access the selected Fields via Query-Object |
||
56 | * @param RequestStack $requestStack the global request_stack |
||
57 | */ |
||
58 | 4 | public function __construct(RequestStack $requestStack) |
|
65 | |||
66 | /** |
||
67 | * Initializing $this->selectedFields and $this->isSelect |
||
68 | * getting the fields that should be really serialized and setting the switch that there is actually a select |
||
69 | * called once in the object, so shouldSkipProperty can use the information for every field |
||
70 | * @return void |
||
71 | */ |
||
72 | 4 | private function getSelectedFieldsFromRQL() |
|
103 | |||
104 | /** |
||
105 | * @InheritDoc: Whether the class should be skipped. |
||
106 | * @param ClassMetadata $metadata the ClassMetadata for the Class of the property to be serialized |
||
107 | * @param Context $navigatorContext the context for serialization |
||
108 | * @return boolean |
||
109 | */ |
||
110 | public function shouldSkipClass(ClassMetadata $metadata, Context $navigatorContext) |
||
114 | |||
115 | /** |
||
116 | * @InheritDoc: Whether the property should be skipped. |
||
117 | * Skipping properties who are not selected if there is a select in rql. |
||
118 | * @param PropertyMetadata $property the property to be serialized |
||
119 | * @param Context $context the context for serialization |
||
120 | * @return boolean |
||
121 | */ |
||
122 | public function shouldSkipProperty(PropertyMetadata $property, Context $context) |
||
156 | } |
||
157 |
If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration: