1 | <?php |
||
11 | final class SymfonyPropertyMapper implements PropertyMapperInterface |
||
12 | { |
||
13 | /** @var ClassMetadataFactoryInterface */ |
||
14 | private $factory; |
||
15 | /** @var NameConverterInterface */ |
||
16 | private $strategy; |
||
17 | |||
18 | /** |
||
19 | * SymfonyPropertyMapper constructor. |
||
20 | * |
||
21 | * @param ClassMetadataFactoryInterface $factory |
||
22 | * @param NameConverterInterface $strategy |
||
23 | */ |
||
24 | 2 | public function __construct(ClassMetadataFactoryInterface $factory, NameConverterInterface $strategy) |
|
29 | |||
30 | /** {@inheritdoc} */ |
||
31 | 2 | public function getEntityProperty($className, $apiProperty) |
|
32 | { |
||
33 | 2 | if (!$this->factory->hasMetadataFor($className)) { |
|
34 | return null; |
||
35 | } |
||
36 | |||
37 | 2 | if (!in_array($apiProperty, $this->getApiProperties($className), true)) { |
|
38 | return null; |
||
39 | } |
||
40 | |||
41 | 2 | return $this->strategy->denormalize($apiProperty); |
|
42 | } |
||
43 | |||
44 | /** {@inheritdoc} */ |
||
45 | public function getApiProperty($className, $objectProperty) |
||
46 | { |
||
47 | if (!$this->factory->hasMetadataFor($className)) { |
||
48 | return null; |
||
49 | } |
||
50 | |||
51 | if (!in_array($objectProperty, $this->getEntityProperties($className), true)) { |
||
52 | return null; |
||
53 | } |
||
54 | |||
55 | return $this->strategy->normalize($objectProperty); |
||
56 | } |
||
57 | |||
58 | /** {@inheritdoc} */ |
||
59 | 2 | public function getApiProperties($className) |
|
68 | |||
69 | /** {@inheritdoc} */ |
||
70 | 1 | public function getEntityProperties($className) |
|
71 | { |
||
72 | 1 | $properties = []; |
|
73 | foreach ($this->getMetadata($className) as $property) { |
||
74 | $properties[] = $property->getName(); |
||
75 | } |
||
76 | |||
77 | return $properties; |
||
78 | } |
||
79 | |||
80 | /** |
||
81 | * @param $className |
||
82 | * |
||
83 | * @return AttributeMetadataInterface[] |
||
84 | */ |
||
85 | 2 | private function getMetadata($className) |
|
93 | } |
||
94 |