1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of Railt package. |
4
|
|
|
* |
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
*/ |
8
|
|
|
declare(strict_types=1); |
9
|
|
|
|
10
|
|
|
namespace Railt\Reflection; |
11
|
|
|
|
12
|
|
|
use Railt\Io\Exception\ExternalFileException; |
13
|
|
|
use Railt\Reflection\Contracts\Definition\TypeDefinition; |
14
|
|
|
use Railt\Reflection\Contracts\Dictionary; |
15
|
|
|
use Railt\Reflection\Definition\Behaviour\HasDeprecation; |
16
|
|
|
use Railt\Reflection\Definition\Behaviour\HasInheritance; |
17
|
|
|
use Railt\Reflection\Exception\TypeConflictException; |
18
|
|
|
use Railt\Reflection\Invocation\Behaviour\HasDirectives; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Class AbstractTypeDefinition |
22
|
|
|
*/ |
23
|
|
|
abstract class AbstractTypeDefinition extends AbstractDefinition implements TypeDefinition |
24
|
|
|
{ |
25
|
|
|
use HasDirectives; |
26
|
|
|
use HasDeprecation; |
27
|
|
|
use HasInheritance; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var string |
31
|
|
|
*/ |
32
|
|
|
protected $name; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var string|null |
36
|
|
|
*/ |
37
|
|
|
protected $description; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* AbstractTypeDefinition constructor. |
41
|
|
|
* @param Document|\Railt\Reflection\Contracts\Document $document |
42
|
|
|
* @param string $name |
43
|
|
|
*/ |
44
|
9 |
|
public function __construct(Document $document, string $name) |
45
|
|
|
{ |
46
|
9 |
|
$this->name = $name; |
47
|
|
|
|
48
|
9 |
|
parent::__construct($document); |
49
|
9 |
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @return string |
53
|
|
|
*/ |
54
|
|
|
public function getDescription(): string |
55
|
|
|
{ |
56
|
|
|
return (string)$this->description; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param null|string $description |
61
|
|
|
* @return TypeDefinition|$this |
62
|
|
|
*/ |
63
|
9 |
|
public function withDescription(?string $description): TypeDefinition |
64
|
|
|
{ |
65
|
9 |
|
$this->description = $description; |
66
|
|
|
|
67
|
9 |
|
return $this; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @param string $name |
72
|
|
|
* @return TypeDefinition|$this |
73
|
|
|
*/ |
74
|
8 |
|
public function renameTo(string $name): TypeDefinition |
75
|
|
|
{ |
76
|
8 |
|
$this->name = $name; |
77
|
|
|
|
78
|
8 |
|
return $this; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @return Dictionary |
83
|
|
|
*/ |
84
|
8 |
|
public function getDictionary(): Dictionary |
85
|
|
|
{ |
86
|
8 |
|
return $this->document->getDictionary(); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @param TypeDefinition $definition |
91
|
|
|
* @return bool |
92
|
|
|
*/ |
93
|
8 |
|
public function instanceOf(TypeDefinition $definition): bool |
94
|
|
|
{ |
95
|
8 |
|
if ($definition::getType()->is(Type::ANY)) { |
96
|
8 |
|
return true; |
97
|
|
|
} |
98
|
|
|
|
99
|
8 |
|
if ($this->getName() === $definition->getName()) { |
100
|
8 |
|
return true; |
101
|
|
|
} |
102
|
|
|
|
103
|
8 |
|
return $this->isExtends($definition); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @return string |
108
|
|
|
*/ |
109
|
64 |
|
public function __toString(): string |
110
|
|
|
{ |
111
|
64 |
|
return \sprintf('%s<%s>', $this->name ?? '?', static::getType()); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @return string |
116
|
|
|
*/ |
117
|
25 |
|
public function getName(): string |
118
|
|
|
{ |
119
|
25 |
|
return $this->name; |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|