|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace ScayTrase\Api\Cruds\Adaptors\DoctrineOrm; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\Common\Persistence\ManagerRegistry; |
|
6
|
|
|
use ScayTrase\Api\Cruds\Exception\MapperException; |
|
7
|
|
|
use ScayTrase\Api\Cruds\PropertyMapperInterface; |
|
8
|
|
|
|
|
9
|
|
|
final class DoctrineAwarePropertyMapperDecorator implements PropertyMapperInterface |
|
10
|
|
|
{ |
|
11
|
|
|
/** @var PropertyMapperInterface */ |
|
12
|
|
|
private $decorated; |
|
13
|
|
|
/** @var ManagerRegistry */ |
|
14
|
|
|
private $registry; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* DoctrineAwarePropertyMapperDecorator constructor. |
|
18
|
|
|
* |
|
19
|
|
|
* @param PropertyMapperInterface $decorated |
|
20
|
|
|
* @param ManagerRegistry $registry |
|
21
|
|
|
*/ |
|
22
|
4 |
|
public function __construct(PropertyMapperInterface $decorated, ManagerRegistry $registry) |
|
23
|
|
|
{ |
|
24
|
4 |
|
$this->decorated = $decorated; |
|
25
|
4 |
|
$this->registry = $registry; |
|
26
|
4 |
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** {@inheritdoc} */ |
|
29
|
4 |
|
public function getEntityProperty($className, $apiProperty) |
|
30
|
|
|
{ |
|
31
|
4 |
|
return $this->decorated->getEntityProperty($this->normalizeClassName($className), $apiProperty); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** {@inheritdoc} */ |
|
35
|
|
|
public function getApiProperty($className, $objectProperty) |
|
36
|
|
|
{ |
|
37
|
|
|
return $this->decorated->getApiProperty($this->normalizeClassName($className), $objectProperty); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** {@inheritdoc} */ |
|
41
|
|
|
public function getApiProperties($className) |
|
42
|
|
|
{ |
|
43
|
|
|
return $this->decorated->getApiProperties($this->normalizeClassName($className)); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** {@inheritdoc} */ |
|
47
|
|
|
public function getEntityProperties($className) |
|
48
|
|
|
{ |
|
49
|
|
|
return $this->decorated->getEntityProperties($this->normalizeClassName($className)); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
4 |
|
private function normalizeClassName($className) |
|
53
|
|
|
{ |
|
54
|
4 |
|
$manager = $this->registry->getManagerForClass($className); |
|
55
|
|
|
|
|
56
|
4 |
|
if (null === $manager) { |
|
57
|
|
|
throw MapperException::unsupportedClass($className); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
4 |
|
$metadata = $manager->getClassMetadata($className); |
|
61
|
|
|
|
|
62
|
4 |
|
return $metadata->getName(); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|