1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Micro framework package. |
7
|
|
|
* |
8
|
|
|
* (c) Stanislau Komar <[email protected]> |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Micro\Library\DTO\ClassDef; |
15
|
|
|
|
16
|
|
|
use Micro\Library\DTO\Helper\ClassMetadataHelperInterface; |
17
|
|
|
|
18
|
|
|
class ClassDefinition |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
private string $extends = ClassMetadataHelperInterface::PROPERTY_TYPE_ABSTRACT_CLASS; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
private string $namespace = ''; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
private string $name = ''; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var array<string, string|null> |
37
|
|
|
*/ |
38
|
|
|
private array $useStatements = []; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var array<PropertyDefinition> |
42
|
|
|
*/ |
43
|
|
|
private array $properties = []; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var array<MethodDefinition> |
47
|
|
|
*/ |
48
|
|
|
private array $methods = []; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @var array<string> |
52
|
|
|
*/ |
53
|
|
|
private array $comments = []; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @return string |
57
|
|
|
*/ |
58
|
1 |
|
public function getExtends(): string |
59
|
|
|
{ |
60
|
1 |
|
return $this->extends; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @param string $extends |
65
|
|
|
*/ |
66
|
|
|
public function setExtends(string $extends): void |
67
|
|
|
{ |
68
|
|
|
$this->extends = $extends; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @return string |
73
|
|
|
*/ |
74
|
3 |
|
public function getNamespace(): string |
75
|
|
|
{ |
76
|
3 |
|
return $this->namespace; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @param string $namespace |
81
|
|
|
*/ |
82
|
3 |
|
public function setNamespace(string $namespace): void |
83
|
|
|
{ |
84
|
3 |
|
$this->namespace = $namespace; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @return string |
89
|
|
|
*/ |
90
|
3 |
|
public function getName(): string |
91
|
|
|
{ |
92
|
3 |
|
return $this->name; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @param string $name |
97
|
|
|
*/ |
98
|
3 |
|
public function setName(string $name): void |
99
|
|
|
{ |
100
|
3 |
|
$this->name = $name; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @return PropertyDefinition[] |
105
|
|
|
*/ |
106
|
1 |
|
public function getProperties(): iterable |
107
|
|
|
{ |
108
|
1 |
|
return $this->properties; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @param PropertyDefinition $propertyDefinition |
113
|
|
|
* |
114
|
|
|
* @return $this |
115
|
|
|
*/ |
116
|
3 |
|
public function addProperty(PropertyDefinition $propertyDefinition): self |
117
|
|
|
{ |
118
|
3 |
|
$this->properties[] = $propertyDefinition; |
119
|
|
|
|
120
|
3 |
|
return $this; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @return MethodDefinition[] |
125
|
|
|
*/ |
126
|
1 |
|
public function getMethods(): iterable |
127
|
|
|
{ |
128
|
1 |
|
return $this->methods; |
129
|
|
|
} |
130
|
|
|
|
131
|
1 |
|
public function addMethod(MethodDefinition $methodDefinition): self |
132
|
|
|
{ |
133
|
1 |
|
if (!\in_array($methodDefinition, $this->methods)) { |
134
|
1 |
|
$this->methods[] = $methodDefinition; |
135
|
|
|
} |
136
|
|
|
|
137
|
1 |
|
return $this; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @return string[] |
142
|
|
|
*/ |
143
|
1 |
|
public function getComments(): iterable |
144
|
|
|
{ |
145
|
1 |
|
return $this->comments; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* @param string $comment |
150
|
|
|
* |
151
|
|
|
* @return $this |
152
|
|
|
*/ |
153
|
3 |
|
public function addComment(string $comment): self |
154
|
|
|
{ |
155
|
3 |
|
if (!\in_array($comment, $this->comments)) { |
156
|
3 |
|
$this->comments[] = $comment; |
157
|
|
|
} |
158
|
|
|
|
159
|
3 |
|
return $this; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* @return array<string, null>|array<string, string> |
164
|
|
|
*/ |
165
|
1 |
|
public function getUseStatements(): array |
166
|
|
|
{ |
167
|
1 |
|
return $this->useStatements; |
168
|
|
|
} |
169
|
|
|
|
170
|
1 |
|
public function addUseStatement(string $useStatement, string $alias = null): self |
171
|
|
|
{ |
172
|
1 |
|
if (!\array_key_exists($useStatement, $this->useStatements)) { |
173
|
1 |
|
$this->useStatements[$useStatement] = $alias; |
174
|
|
|
} |
175
|
|
|
|
176
|
1 |
|
return $this; |
177
|
|
|
} |
178
|
|
|
} |
179
|
|
|
|