1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ScayTrase\Api\Cruds\Adaptors\DoctrineOrm; |
4
|
|
|
|
5
|
|
|
use Symfony\Bridge\Doctrine\ManagerRegistry; |
6
|
|
|
use Symfony\Component\PropertyAccess\PropertyAccessorInterface; |
7
|
|
|
|
8
|
|
|
final class AssociationPropertyAccessor implements PropertyAccessorInterface |
9
|
|
|
{ |
10
|
|
|
/** @var PropertyAccessorInterface */ |
11
|
|
|
private $delegate; |
12
|
|
|
/** @var AssociationNormalizer */ |
13
|
|
|
private $normalizer; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* AssociationPropertyAccessor constructor. |
17
|
|
|
* |
18
|
|
|
* @param PropertyAccessorInterface $delegate |
19
|
|
|
* @param ManagerRegistry $registry |
20
|
|
|
*/ |
21
|
|
|
public function __construct(PropertyAccessorInterface $delegate, ManagerRegistry $registry) |
22
|
|
|
{ |
23
|
|
|
$this->delegate = $delegate; |
24
|
|
|
$this->normalizer = new AssociationNormalizer($registry); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** {@inheritdoc} */ |
28
|
|
|
public function setValue(&$objectOrArray, $propertyPath, $value) |
29
|
|
|
{ |
30
|
|
|
$value = $this->normalizer->denormalize($objectOrArray, $propertyPath, $value); |
31
|
|
|
|
32
|
|
|
return $this->delegate->setValue($objectOrArray, $propertyPath, $value); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** {@inheritdoc} */ |
36
|
|
|
public function getValue($objectOrArray, $propertyPath) |
37
|
|
|
{ |
38
|
|
|
return $this->normalizer->normalize( |
39
|
|
|
$this->delegate->getValue($objectOrArray, $propertyPath), |
40
|
|
|
$objectOrArray, |
41
|
|
|
$propertyPath |
42
|
|
|
); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** {@inheritdoc} */ |
46
|
|
|
public function isWritable($objectOrArray, $propertyPath) |
47
|
|
|
{ |
48
|
|
|
return $this->delegate->isWritable($objectOrArray, $propertyPath); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** {@inheritdoc} */ |
52
|
|
|
public function isReadable($objectOrArray, $propertyPath) |
53
|
|
|
{ |
54
|
|
|
return $this->delegate->isReadable($objectOrArray, $propertyPath); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|