1 | <?php |
||
9 | class StringGenerator implements StringGeneratorInterface |
||
10 | { |
||
11 | |||
12 | /** |
||
13 | * @var array |
||
14 | */ |
||
15 | protected $classStrings; |
||
16 | |||
17 | |||
18 | /** |
||
19 | * @var ClassStoreInterface |
||
20 | */ |
||
21 | protected $classStore; |
||
22 | |||
23 | /** |
||
24 | * @var VisitedAssociationLoggerInterface |
||
25 | */ |
||
26 | protected $associationLogger; |
||
27 | |||
28 | /** |
||
29 | * @param ClassStoreInterface $classStore |
||
30 | */ |
||
31 | 9 | public function __construct(ClassStoreInterface $classStore) |
|
32 | { |
||
33 | 9 | $this->classStore = $classStore; |
|
34 | 9 | $this->associationLogger = new VisitedAssociationLogger(); |
|
35 | 9 | } |
|
36 | |||
37 | /** |
||
38 | * @return VisitedAssociationLoggerInterface |
||
39 | */ |
||
40 | 1 | public function getAssociationLogger() |
|
41 | { |
||
42 | 1 | return $this->associationLogger; |
|
43 | } |
||
44 | |||
45 | /** |
||
46 | * Build the string representing the single graph item |
||
47 | * |
||
48 | * @param ClassMetadata $class |
||
49 | * |
||
50 | * @return string |
||
51 | */ |
||
52 | 7 | public function getClassString(ClassMetadata $class) |
|
53 | { |
||
54 | 7 | $className = $class->getName(); |
|
55 | 7 | if (!isset($this->classStrings[$className])) { |
|
56 | 7 | $this->associationLogger->visitAssociation($className); |
|
57 | |||
58 | 7 | $classText = '[' . str_replace('\\', '.', $className); |
|
59 | 7 | $fields = array(); |
|
60 | 7 | $parent = $this->classStore->getParent($class); |
|
61 | 7 | $parentFields = $parent ? $parent->getFieldNames() : array(); |
|
62 | |||
63 | 7 | foreach ($class->getFieldNames() as $fieldName) { |
|
64 | 1 | if (in_array($fieldName, $parentFields)) { |
|
65 | 1 | continue; |
|
66 | } |
||
67 | |||
68 | 1 | if ($class->isIdentifier($fieldName)) { |
|
69 | 1 | $fields[] = '+' . $fieldName; |
|
70 | 1 | } else { |
|
71 | 1 | $fields[] = $fieldName; |
|
72 | } |
||
73 | 7 | } |
|
74 | |||
75 | 7 | if (!empty($fields)) { |
|
76 | 1 | $classText .= '|' . implode(';', $fields); |
|
77 | 1 | } |
|
78 | |||
79 | 7 | $classText .= ']'; |
|
80 | |||
81 | 7 | $this->classStrings[$className] = $classText; |
|
82 | 7 | } |
|
83 | |||
84 | 7 | return $this->classStrings[$className]; |
|
85 | } |
||
86 | |||
87 | /** |
||
88 | * @param ClassMetadata $class1 |
||
89 | * @param string $association |
||
90 | * @return string |
||
91 | */ |
||
92 | 6 | public function getAssociationString(ClassMetadata $class1, $association) |
|
131 | |||
132 | |||
133 | |||
134 | /** |
||
135 | * Returns the $class2 association name for $class1 if reverse related (or null if not) |
||
136 | * |
||
137 | * @param ClassMetadata $class1 |
||
138 | * @param string $association |
||
139 | * |
||
140 | * @return string|null |
||
141 | */ |
||
142 | 5 | private function getClassReverseAssociationName(ClassMetadata $class1, $association) |
|
150 | |||
151 | /** |
||
152 | * @param ClassMetadata $class1 |
||
153 | * @param boolean $isInverse |
||
154 | * @param string $association |
||
155 | * @param int $class1Count |
||
156 | * @param string $targetClassName |
||
157 | * @return string |
||
158 | */ |
||
159 | 2 | private function makeSingleSidedLinkString( |
|
170 | |||
171 | /** |
||
172 | * @param ClassMetadata $class1 |
||
173 | * @param ClassMetadata $class2 |
||
174 | * @param boolean $bidirectional |
||
175 | * @param boolean $isInverse |
||
176 | * @param string $class2SideName |
||
177 | * @param integer $class2Count |
||
178 | * @param string $class1SideName |
||
179 | * @param integer $class1Count |
||
180 | * |
||
181 | * @return string |
||
182 | */ |
||
183 | 5 | private function makeDoubleSidedLinkString( |
|
198 | } |
||
199 |