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\Definition\Dependent; |
11
|
|
|
|
12
|
|
|
use Railt\Reflection\Contracts\Definition\Dependent\ArgumentDefinition as ArgumentDefinitionInterface; |
13
|
|
|
use Railt\Reflection\Contracts\Definition\TypeDefinition; |
14
|
|
|
use Railt\Reflection\Contracts\Type as TypeInterface; |
15
|
|
|
use Railt\Reflection\Definition\Behaviour\HasTypeIndication; |
16
|
|
|
use Railt\Reflection\Document; |
17
|
|
|
use Railt\Reflection\Type; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Class ArgumentDefinition |
21
|
|
|
*/ |
22
|
|
|
class ArgumentDefinition extends AbstractDependentTypeDefinition implements ArgumentDefinitionInterface |
23
|
|
|
{ |
24
|
|
|
use HasTypeIndication; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var mixed |
28
|
|
|
*/ |
29
|
|
|
protected $defaultValue; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var bool |
33
|
|
|
*/ |
34
|
|
|
protected $hasDefaultValue = false; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* ArgumentDefinition constructor. |
38
|
|
|
* @param TypeDefinition $parent |
39
|
|
|
* @param Document $document |
40
|
|
|
* @param string $name |
41
|
|
|
* @param string $type |
42
|
|
|
*/ |
43
|
|
|
public function __construct(TypeDefinition $parent, Document $document, string $name, string $type) |
44
|
|
|
{ |
45
|
|
|
parent::__construct($parent, $document, $name); |
46
|
|
|
|
47
|
|
|
$this->setTypeDefinition($type); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @return TypeInterface |
52
|
|
|
*/ |
53
|
|
|
public static function getType(): TypeInterface |
54
|
|
|
{ |
55
|
|
|
return Type::of(Type::ARGUMENT_DEFINITION); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @return mixed |
60
|
|
|
*/ |
61
|
|
|
public function getDefaultValue() |
62
|
|
|
{ |
63
|
|
|
return $this->defaultValue; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param $value |
68
|
|
|
* @return void |
69
|
|
|
*/ |
70
|
|
|
public function setDefaultValue($value): void |
71
|
|
|
{ |
72
|
|
|
$this->defaultValue = $value; |
73
|
|
|
$this->hasDefaultValue = true; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @return bool |
78
|
|
|
*/ |
79
|
|
|
public function hasDefaultValue(): bool |
80
|
|
|
{ |
81
|
|
|
return $this->hasDefaultValue; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @return void |
86
|
|
|
*/ |
87
|
|
|
public function removeDefaultValue(): void |
88
|
|
|
{ |
89
|
|
|
$this->defaultValue = null; |
90
|
|
|
$this->hasDefaultValue = false; |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|