|
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
|
|
|
/** |
|
11
|
|
|
* A raw definition is a wrapper for an associative array of strings used to build `Definition`s |
|
12
|
|
|
* |
|
13
|
|
|
* @see \PhUml\Parser\Raw\Builders\RawClassBuilder To check how a `RawDefinition` for a class is built |
|
14
|
|
|
* @see \PhUml\Parser\Raw\Builders\RawInterfaceBuilder To check how a `RawDefinition` for an interface is built |
|
15
|
|
|
*/ |
|
16
|
|
|
class RawDefinition |
|
17
|
|
|
{ |
|
18
|
|
|
private static $classDefaults = [ |
|
19
|
|
|
'attributes' => [], |
|
20
|
|
|
'constants' => [], |
|
21
|
|
|
'methods' => [], |
|
22
|
|
|
'implements' => [], |
|
23
|
|
|
'extends' => null, |
|
24
|
|
|
]; |
|
25
|
|
|
|
|
26
|
|
|
private static $interfaceDefaults = [ |
|
27
|
|
|
'constants' => [], |
|
28
|
|
|
'methods' => [], |
|
29
|
|
|
'extends' => null, |
|
30
|
|
|
]; |
|
31
|
|
|
|
|
32
|
|
|
/** @var array */ |
|
33
|
|
|
private $definition; |
|
34
|
|
|
|
|
35
|
|
|
private function __construct(array $definition) |
|
36
|
|
|
{ |
|
37
|
|
|
$this->definition = $definition; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public static function class(array $definition): RawDefinition |
|
|
|
|
|
|
41
|
|
|
{ |
|
42
|
|
|
return new RawDefinition([ |
|
43
|
|
|
'class' => $definition['class'], |
|
44
|
|
|
'constants' => $definition['constants'] ?? self::$classDefaults['constants'], |
|
45
|
|
|
'attributes' => $definition['attributes'] ?? self::$classDefaults['attributes'], |
|
46
|
|
|
'methods' => $definition['methods'] ?? self::$classDefaults['methods'], |
|
47
|
|
|
'implements' => $definition['implements'] ?? self::$classDefaults['implements'], |
|
48
|
|
|
'extends' => $definition['extends'] ?? self::$classDefaults['extends'], |
|
49
|
|
|
]); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public static function interface(array $definition): RawDefinition |
|
|
|
|
|
|
53
|
|
|
{ |
|
54
|
|
|
return new RawDefinition([ |
|
55
|
|
|
'interface' => $definition['interface'], |
|
56
|
|
|
'constants' => $definition['constants'] ?? self::$interfaceDefaults['constants'], |
|
57
|
|
|
'methods' => $definition['methods'] ?? self::$interfaceDefaults['methods'], |
|
58
|
|
|
'extends' => $definition['extends'] ?? self::$interfaceDefaults['extends'], |
|
59
|
|
|
]); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public static function externalClass(string $name): RawDefinition |
|
63
|
|
|
{ |
|
64
|
|
|
return new RawDefinition(array_merge(['class' => $name], self::$classDefaults)); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public static function externalInterface(string $name): RawDefinition |
|
68
|
|
|
{ |
|
69
|
|
|
return new RawDefinition(array_merge(['interface' => $name], self::$interfaceDefaults)); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
public function name(): string |
|
73
|
|
|
{ |
|
74
|
|
|
return $this->definition['class'] ?? $this->definition['interface']; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** @return string[] */ |
|
78
|
|
|
public function interfaces(): array |
|
79
|
|
|
{ |
|
80
|
|
|
return $this->definition['implements']; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
public function hasParent(): bool |
|
84
|
|
|
{ |
|
85
|
|
|
return isset($this->definition['extends']); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
public function parent(): ?string |
|
89
|
|
|
{ |
|
90
|
|
|
return $this->definition['extends'] ?? null; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
public function isClass(): bool |
|
94
|
|
|
{ |
|
95
|
|
|
return isset($this->definition['class']); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
public function isInterface(): bool |
|
99
|
|
|
{ |
|
100
|
|
|
return isset($this->definition['interface']); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
public function attributes(): array |
|
104
|
|
|
{ |
|
105
|
|
|
return $this->definition['attributes']; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
public function methods(): array |
|
109
|
|
|
{ |
|
110
|
|
|
return $this->definition['methods']; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
public function constants(): array |
|
114
|
|
|
{ |
|
115
|
|
|
return $this->definition['constants']; |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
|