|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* PHP version 7.1 |
|
4
|
|
|
* |
|
5
|
|
|
* This source file is subject to the license that is bundled with this package in the file LICENSE. |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace PhUml\Parser\Code; |
|
9
|
|
|
|
|
10
|
|
|
use PhUml\Code\Attributes\Attribute; |
|
11
|
|
|
use PhUml\Code\ClassDefinition; |
|
12
|
|
|
use PhUml\Code\Codebase; |
|
13
|
|
|
use PhUml\Code\Variables\Variable; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* It checks the attributes and the constructor parameters of a class looking for external definitions |
|
17
|
|
|
* |
|
18
|
|
|
* An external definition is either a class or interface from a third party library, or a built-in |
|
19
|
|
|
* class |
|
20
|
|
|
* |
|
21
|
|
|
* In this case a `ClassDefinition` is added by default. |
|
22
|
|
|
* Although we don't really know if it's an interface since we don't have access to the source code |
|
23
|
|
|
*/ |
|
24
|
|
|
class ExternalAssociationsResolver extends ExternalDefinitionsResolver |
|
25
|
|
|
{ |
|
26
|
27 |
|
protected function resolveForClass(ClassDefinition $definition, Codebase $codebase): void |
|
27
|
|
|
{ |
|
28
|
27 |
|
parent::resolveForClass($definition, $codebase); |
|
29
|
27 |
|
$this->resolveExternalAttributes($definition, $codebase); |
|
30
|
27 |
|
$this->resolveExternalConstructorParameters($definition, $codebase); |
|
31
|
27 |
|
} |
|
32
|
|
|
|
|
33
|
|
|
private function resolveExternalAttributes(ClassDefinition $definition, Codebase $codebase): void |
|
34
|
|
|
{ |
|
35
|
27 |
|
array_map(function (Attribute $attribute) use ($codebase) { |
|
36
|
15 |
|
if ($attribute->isAReference() && !$codebase->has($attribute->typeName())) { |
|
37
|
3 |
|
$codebase->add($this->externalClass($attribute->typeName())); |
|
38
|
|
|
} |
|
39
|
27 |
|
}, $definition->attributes()); |
|
40
|
27 |
|
} |
|
41
|
|
|
|
|
42
|
|
|
private function resolveExternalConstructorParameters(ClassDefinition $definition, Codebase $codebase): void |
|
43
|
|
|
{ |
|
44
|
27 |
|
array_map(function (Variable $parameter) use ($codebase) { |
|
45
|
15 |
|
if ($parameter->isAReference() && !$codebase->has($parameter->typeName())) { |
|
46
|
3 |
|
$codebase->add($this->externalClass($parameter->typeName())); |
|
47
|
|
|
} |
|
48
|
27 |
|
}, $definition->constructorParameters()); |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
|