1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Onurb\Doctrine\ORMMetadataGrapher\YumlMetadataGrapher\StringGenerator; |
4
|
|
|
|
5
|
|
|
class VisitedAssociationLogger implements VisitedAssociationLoggerInterface |
6
|
|
|
{ |
7
|
|
|
/** |
8
|
|
|
* Temporary array where already visited collections are stored |
9
|
|
|
* |
10
|
|
|
* @var array |
11
|
|
|
*/ |
12
|
|
|
protected $visitedAssociations = array(); |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @return array |
16
|
|
|
*/ |
17
|
2 |
|
public function getVisitedAssociations() |
18
|
|
|
{ |
19
|
2 |
|
return $this->visitedAssociations; |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Visit a given association and mark it as visited |
24
|
|
|
* |
25
|
|
|
* @param string $className |
26
|
|
|
* @param string|null $association |
27
|
|
|
* |
28
|
|
|
* @return bool true if the association was visited before |
29
|
|
|
*/ |
30
|
5 |
|
public function visitAssociation($className, $association = null) |
31
|
|
|
{ |
32
|
5 |
|
if (null === $association) { |
33
|
5 |
|
return $this->visitSingleSidedAssociation($className); |
34
|
|
|
} |
35
|
|
|
|
36
|
4 |
|
return $this->visitDoubleSidedAssociation($className, $association); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @param string $className |
41
|
|
|
* @param string|null $association |
42
|
|
|
* @return bool |
43
|
|
|
*/ |
44
|
5 |
|
protected function isVisitedAssociation($className, $association = null) |
45
|
|
|
{ |
46
|
5 |
|
return null === $association ? |
47
|
5 |
|
isset($this->visitedAssociations[$className]) : |
48
|
5 |
|
isset($this->visitedAssociations[$className][$association]); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param string $className |
53
|
|
|
* @return bool |
54
|
|
|
*/ |
55
|
5 |
|
protected function visitSingleSidedAssociation($className) |
56
|
|
|
{ |
57
|
5 |
|
if ($this->isVisitedAssociation($className)) { |
58
|
4 |
|
return false; |
59
|
|
|
} |
60
|
|
|
|
61
|
5 |
|
$this->visitedAssociations[$className] = array(); |
62
|
|
|
|
63
|
5 |
|
return true; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param string $className |
68
|
|
|
* @param string $association |
69
|
|
|
* @return bool |
70
|
|
|
*/ |
71
|
4 |
|
protected function visitDoubleSidedAssociation($className, $association) |
72
|
|
|
{ |
73
|
4 |
|
$this->visitSingleSidedAssociation($className); |
74
|
|
|
|
75
|
4 |
|
if ($this->isVisitedAssociation($className, $association)) { |
76
|
1 |
|
return false; |
77
|
|
|
} |
78
|
|
|
|
79
|
4 |
|
$this->visitedAssociations[$className][$association] = true; |
80
|
|
|
|
81
|
4 |
|
return true; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|