1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright (C) 2019 Gerrit Addiks. |
4
|
|
|
* This package (including this file) was released under the terms of the GPL-3.0. |
5
|
|
|
* You should have received a copy of the GNU General Public License along with this program. |
6
|
|
|
* If not, see <http://www.gnu.org/licenses/> or send me a mail so i can send you a copy. |
7
|
|
|
* |
8
|
|
|
* @license GPL-3.0 |
9
|
|
|
* |
10
|
|
|
* @author Gerrit Addiks <[email protected]> |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace Addiks\RDMBundle\DataLoader\BlackMagic; |
14
|
|
|
|
15
|
|
|
use ReflectionProperty; |
16
|
|
|
use Doctrine\DBAL\Schema\Column; |
17
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
18
|
|
|
use Addiks\RDMBundle\DataLoader\BlackMagic\BlackMagicDataLoader; |
19
|
|
|
use Addiks\RDMBundle\Mapping\Drivers\MappingDriverInterface; |
20
|
|
|
use ReflectionException; |
21
|
|
|
use Addiks\RDMBundle\Mapping\EntityMappingInterface; |
22
|
|
|
use Addiks\RDMBundle\DataLoader\BlackMagic\BlackMagicColumnReflectionPropertyMock; |
23
|
|
|
use Webmozart\Assert\Assert; |
24
|
|
|
use Doctrine\Persistence\Mapping\ReflectionService; |
25
|
|
|
use ReflectionClass; |
26
|
|
|
|
27
|
|
|
final class BlackMagicReflectionServiceDecorator implements ReflectionService |
28
|
|
|
{ |
29
|
|
|
|
30
|
|
|
/** @var MappingDriverInterface */ |
31
|
|
|
private $mappingDriver; |
32
|
|
|
|
33
|
|
|
/** @var ReflectionService */ |
34
|
|
|
private $innerReflectionService; |
35
|
|
|
|
36
|
|
|
/** @var EntityManagerInterface */ |
37
|
|
|
private $entityManager; |
38
|
|
|
|
39
|
|
|
/** @var BlackMagicDataLoader */ |
40
|
|
|
private $dataLoader; |
41
|
1 |
|
|
42
|
|
|
public function __construct( |
43
|
|
|
ReflectionService $innerReflectionService, |
44
|
|
|
MappingDriverInterface $mappingDriver, |
45
|
|
|
EntityManagerInterface $entityManager, |
46
|
|
|
BlackMagicDataLoader $dataLoader |
47
|
1 |
|
) { |
48
|
1 |
|
$this->innerReflectionService = $innerReflectionService; |
49
|
1 |
|
$this->mappingDriver = $mappingDriver; |
50
|
1 |
|
$this->entityManager = $entityManager; |
51
|
|
|
$this->dataLoader = $dataLoader; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function getParentClasses($class): array |
55
|
|
|
{ |
56
|
|
|
return $this->innerReflectionService->getParentClasses($class); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function getClassShortName($class): string |
60
|
|
|
{ |
61
|
|
|
return $this->innerReflectionService->getClassShortName($class); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function getClassNamespace($class): string |
65
|
|
|
{ |
66
|
|
|
return $this->innerReflectionService->getClassNamespace($class); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function getClass($class): ?ReflectionClass |
70
|
|
|
{ |
71
|
|
|
return $this->innerReflectionService->getClass($class); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function getAccessibleProperty($class, $property): ?ReflectionProperty |
75
|
|
|
{ |
76
|
|
|
/** @var ReflectionProperty|null $propertyReflection */ |
77
|
|
|
$propertyReflection = null; |
78
|
|
|
|
79
|
|
|
if ($this->dataLoader->isFakedFieldName($property)) { |
80
|
|
|
/** @var EntityMappingInterface|null $entityMapping */ |
81
|
|
|
$entityMapping = $this->mappingDriver->loadRDMMetadataForClass($class); |
82
|
|
|
|
83
|
|
|
if ($entityMapping instanceof EntityMappingInterface) { |
84
|
|
|
/** @var array<Column> $columns */ |
85
|
|
|
$columns = $entityMapping->collectDBALColumns(); |
86
|
|
|
|
87
|
|
|
/** @var Column $column */ |
88
|
|
|
foreach ($columns as $column) { |
89
|
|
|
/** @var string $fieldName */ |
90
|
|
|
$fieldName = $this->dataLoader->columnToFieldName($column); |
91
|
|
|
|
92
|
|
|
if ($property === $fieldName) { |
93
|
|
|
$propertyReflection = new BlackMagicColumnReflectionPropertyMock( |
94
|
|
|
$this->entityManager, |
95
|
|
|
$this->entityManager->getClassMetadata($class), |
96
|
|
|
$column, |
97
|
|
|
$fieldName, |
98
|
|
|
$this->dataLoader |
99
|
|
|
); |
100
|
|
|
break; |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
} else { |
106
|
|
|
$propertyReflection = $this->innerReflectionService->getAccessibleProperty($class, $property); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
return $propertyReflection; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
public function hasPublicMethod($class, $method): bool |
113
|
|
|
{ |
114
|
|
|
return $this->innerReflectionService->hasPublicMethod($class, $method); |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|