|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Mado\QueryBundle\Component\Meta; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
6
|
|
|
use Doctrine\ORM\Mapping\ClassMetadata; |
|
7
|
|
|
use Psr\Log\LoggerInterface; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* @since Class available since Release 2.1.0 |
|
11
|
|
|
*/ |
|
12
|
|
|
class MapBuilder implements DataMapper |
|
13
|
|
|
{ |
|
14
|
|
|
private $manager; |
|
15
|
|
|
|
|
16
|
|
|
private $map = []; |
|
17
|
|
|
|
|
18
|
3 |
|
public function __construct( |
|
19
|
|
|
EntityManagerInterface $manager, |
|
20
|
|
|
LoggerInterface $logger = null |
|
|
|
|
|
|
21
|
|
|
) { |
|
22
|
3 |
|
$this->manager = $manager; |
|
23
|
3 |
|
} |
|
24
|
|
|
|
|
25
|
|
|
public function setMap(array $map) : bool |
|
26
|
|
|
{ |
|
27
|
|
|
$this->map = $map; |
|
28
|
|
|
|
|
29
|
|
|
return true; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
3 |
|
public function getMap() : array |
|
33
|
|
|
{ |
|
34
|
3 |
|
if (!$this->map) { |
|
|
|
|
|
|
35
|
2 |
|
$this->rebuildRelationMap(); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
3 |
|
return $this->map; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
1 |
|
public function forceCache(array $map) |
|
42
|
|
|
{ |
|
43
|
1 |
|
$this->map = $map; |
|
44
|
1 |
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** @codeCoverageIgnore */ |
|
47
|
|
|
public static function relations(ClassMetadata $classMetadata) { |
|
48
|
|
|
$encoded = json_encode($classMetadata); |
|
49
|
|
|
$decoded = json_decode($encoded, true); |
|
50
|
|
|
$relations = $decoded['associationMappings']; |
|
51
|
|
|
|
|
52
|
|
|
$relMap = []; |
|
53
|
|
|
|
|
54
|
|
|
foreach ($relations as $name => $meta) { |
|
55
|
|
|
$relMap[$name] = $meta['targetEntity']; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
return $relMap; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
2 |
|
public function rebuildRelationMap() : bool |
|
62
|
|
|
{ |
|
63
|
2 |
|
$allMetadata = $this->manager |
|
64
|
2 |
|
->getMetadataFactory() |
|
65
|
2 |
|
->getAllMetadata(); |
|
66
|
|
|
|
|
67
|
2 |
|
foreach ($allMetadata as $singleEntityMetadata) { |
|
68
|
|
|
// @codeCoverageIgnoreStart |
|
69
|
|
|
$this->map[$singleEntityMetadata->getName()]['relations'] = self::relations($singleEntityMetadata); |
|
70
|
|
|
// @codeCoverageIgnoreEnd |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
2 |
|
return true; |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.