1 | <?php |
||
12 | class RestRequestParser |
||
13 | { |
||
14 | /** |
||
15 | * @var MetadataFactory |
||
16 | */ |
||
17 | private $ddrRestMetadataFactory; |
||
18 | |||
19 | /** |
||
20 | * @var PropertyAccessor |
||
21 | */ |
||
22 | private $propertyAccessor; |
||
23 | |||
24 | 2 | public function __construct(MetadataFactory $ddrRestMetadataFactory, PropertyAccessor $propertyAccessor) |
|
29 | |||
30 | /** |
||
31 | * @param Request $request |
||
32 | * @param string $entityClass |
||
33 | * @param object|null $entity |
||
34 | * |
||
35 | * @return object |
||
36 | */ |
||
37 | 2 | public function parseEntity( |
|
59 | |||
60 | /** |
||
61 | * @param Request $request |
||
62 | * |
||
63 | * @return array |
||
64 | */ |
||
65 | 2 | protected function getRequestContent(Request $request) |
|
74 | |||
75 | /** |
||
76 | * @param object $object Access by reference. |
||
77 | * @param string $method |
||
78 | * @param array $data |
||
79 | */ |
||
80 | 2 | protected function updateObject( |
|
99 | |||
100 | /** |
||
101 | * @param object $object Access by reference. |
||
102 | * @param string $method |
||
103 | * @param string $propertyName |
||
104 | * @param mixed $value |
||
105 | * @param PropertyMetadata $propertyMetadata |
||
106 | */ |
||
107 | 1 | protected function updateProperty( |
|
108 | &$object, |
||
109 | $method, |
||
110 | $propertyName, |
||
|
|||
111 | $value, |
||
112 | PropertyMetadata $propertyMetadata |
||
113 | ) { |
||
114 | |||
115 | // TODO: Reenable embedded |
||
116 | // if (array_key_exists($propertyName, $doctrineClassMetadata->embeddedClasses)) { |
||
117 | // $embeddedClass = $doctrineClassMetadata->embeddedClasses[$propertyName]['class']; |
||
118 | // $this->updatePropertyObject($object, $method, $embeddedClass, $propertyName, $value); |
||
119 | // |
||
120 | // return; |
||
121 | // } |
||
122 | |||
123 | //TODO: Reenable associations |
||
124 | // if (array_key_exists($propertyName, $doctrineClassMetadata->associationMappings)) { |
||
125 | // $associatedClass = $doctrineClassMetadata->associationMappings[$propertyName]['targetEntity']; |
||
126 | // $this->updatePropertyObject($object, $method, $associatedClass, $propertyName, $value); |
||
127 | // |
||
128 | // return; |
||
129 | // } |
||
130 | |||
131 | 1 | if (array_key_exists($propertyMetadata->getType(), Type::getTypesMap())) { |
|
132 | 1 | $convertedValue = $this->convert($propertyMetadata->getType(), $value); |
|
133 | 1 | $this->propertyAccessor->setValue($object, $propertyMetadata->name, $convertedValue); |
|
134 | } else { |
||
135 | 1 | $this->updatePropertyObject($object, $method, $propertyMetadata, $value); |
|
136 | } |
||
137 | 1 | } |
|
138 | |||
139 | 1 | protected function updatePropertyObject( |
|
140 | &$object, |
||
141 | string $method, |
||
142 | PropertyMetadata $propertyMetadata, |
||
143 | $value |
||
144 | ) { |
||
145 | 1 | $propertyObject = $this->propertyAccessor->getValue($object, $propertyMetadata->name); |
|
146 | 1 | if (null === $propertyObject) { |
|
147 | $type = $propertyMetadata->getType(); |
||
148 | $propertyObject = new $type; |
||
149 | } |
||
150 | |||
151 | 1 | $this->updateObject($propertyObject, $method, $value); |
|
152 | 1 | $this->propertyAccessor->setValue($object, $propertyMetadata->name, $propertyObject); |
|
153 | 1 | } |
|
154 | |||
155 | /** |
||
156 | * @param string $method |
||
157 | * @param PropertyMetadata $propertyMetadata |
||
158 | * |
||
159 | * @return bool |
||
160 | */ |
||
161 | 1 | protected function isUpdateable( |
|
174 | |||
175 | 1 | private function convert(?string $type, $value) |
|
176 | { |
||
190 | } |
||
191 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.