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\Raw; |
9
|
|
|
|
10
|
|
|
use PhUml\Parser\Raw\RawDefinition; |
11
|
|
|
use PhUml\Parser\Raw\RawDefinitions; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* It checks the parent of a definition and the interfaces it implements looking for external |
15
|
|
|
* definitions |
16
|
|
|
* |
17
|
|
|
* An external definition is a class or interface that belongs to a third party library or |
18
|
|
|
* a PHP's built-in class |
19
|
|
|
*/ |
20
|
|
|
class ExternalDefinitionsResolver |
21
|
|
|
{ |
22
|
|
|
public function resolve(RawDefinitions $definitions): void |
23
|
|
|
{ |
24
|
|
|
foreach ($definitions->all() as $definition) { |
25
|
|
|
if ($definition->isClass()) { |
26
|
|
|
$this->resolveForClass($definitions, $definition); |
27
|
|
|
} else { |
28
|
|
|
$this->resolveForInterface($definitions, $definition); |
29
|
|
|
} |
30
|
|
|
} |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
private function resolveForClass(RawDefinitions $definitions, RawDefinition $definition): void |
34
|
|
|
{ |
35
|
|
|
foreach ($definition->interfaces() as $interface) { |
36
|
|
|
if (!$definitions->has($interface)) { |
37
|
|
|
$definitions->addExternalInterface($interface); |
38
|
|
|
} |
39
|
|
|
} |
40
|
|
|
$this->resolveParentClass($definitions, $definition); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
private function resolveForInterface(RawDefinitions $definitions, RawDefinition $definition): void |
44
|
|
|
{ |
45
|
|
|
$this->resolveParentInterface($definitions, $definition); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
private function resolveParentClass(RawDefinitions $definitions, RawDefinition $definition): void |
49
|
|
|
{ |
50
|
|
|
if ($definition->hasParent()) { |
51
|
|
|
$parent = $definition->parent(); |
52
|
|
|
if (!$definitions->has($parent)) { |
53
|
|
|
$definitions->addExternalClass($parent); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
private function resolveParentInterface(RawDefinitions $definitions, RawDefinition $definition): void |
59
|
|
|
{ |
60
|
|
|
if ($definition->hasParent()) { |
61
|
|
|
$parent = $definition->parent(); |
62
|
|
|
if (!$definitions->has($parent)) { |
63
|
|
|
$definitions->addExternalInterface($parent); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|