|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Swaggest\PhpCodeBuilder; |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
use Swaggest\PhpCodeBuilder\Traits\Description; |
|
7
|
|
|
use Swaggest\PhpCodeBuilder\Traits\StaticFlag; |
|
8
|
|
|
use Swaggest\PhpCodeBuilder\Traits\Visibility; |
|
9
|
|
|
|
|
10
|
|
|
class PhpClassProperty extends PhpTemplate |
|
11
|
|
|
{ |
|
12
|
|
|
use Visibility; |
|
13
|
|
|
use StaticFlag; |
|
14
|
|
|
|
|
15
|
|
|
/** @var PhpNamedVar */ |
|
16
|
|
|
private $namedVar; |
|
17
|
|
|
|
|
18
|
11 |
|
/** @var bool Magical property is rendered as phpdoc */ |
|
19
|
|
|
private $isMagical = false; |
|
20
|
11 |
|
|
|
21
|
11 |
|
/** |
|
22
|
11 |
|
* @return bool |
|
23
|
|
|
*/ |
|
24
|
|
|
public function isMagical() |
|
25
|
|
|
{ |
|
26
|
|
|
return $this->isMagical; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @param bool $isMagical |
|
31
|
|
|
*/ |
|
32
|
|
|
public function setIsMagical($isMagical) |
|
33
|
|
|
{ |
|
34
|
|
|
$this->isMagical = $isMagical; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function __construct($name, PhpAnyType $type = null, $visibility = PhpFlags::VIS_PUBLIC) |
|
38
|
|
|
{ |
|
39
|
|
|
$this->namedVar = new PhpNamedVar($name, $type); |
|
40
|
|
|
$this->visibility = $visibility; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
|
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
5 |
|
* @param mixed $value |
|
47
|
|
|
* @return $this |
|
48
|
5 |
|
*/ |
|
49
|
|
|
public function setDefault($value) |
|
50
|
|
|
{ |
|
51
|
|
|
$this->namedVar->setDefault($value); |
|
52
|
|
|
return $this; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @return $this |
|
57
|
|
|
*/ |
|
58
|
|
|
public function clearDefault() |
|
59
|
|
|
{ |
|
60
|
|
|
$this->namedVar->clearDefault(); |
|
61
|
3 |
|
return $this; |
|
62
|
|
|
} |
|
63
|
3 |
|
|
|
64
|
3 |
|
/** |
|
65
|
|
|
* @return PhpNamedVar |
|
66
|
|
|
*/ |
|
67
|
11 |
|
public function getNamedVar() |
|
68
|
|
|
{ |
|
69
|
11 |
|
return $this->namedVar; |
|
70
|
11 |
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @param PhpNamedVar $namedVar |
|
74
|
|
|
* @return PhpClassProperty |
|
75
|
|
|
*/ |
|
76
|
11 |
|
public function setNamedVar($namedVar) |
|
77
|
|
|
{ |
|
78
|
|
|
$this->namedVar = $namedVar; |
|
79
|
11 |
|
return $this; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
public function setDescription($description) |
|
83
|
|
|
{ |
|
84
|
|
|
$this->namedVar->setDescription($description); |
|
85
|
|
|
return $this; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
private function renderPhpDoc() |
|
89
|
|
|
{ |
|
90
|
|
|
if ($tagValue = $this->namedVar->renderPhpDocValue()) { |
|
91
|
|
|
return (new PhpDocTag(PhpDoc::TAG_VAR, $tagValue)) . "\n"; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
return ''; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
protected function toString() |
|
98
|
|
|
{ |
|
99
|
|
|
return <<<PHP |
|
100
|
|
|
{$this->renderPhpDoc()}{$this->renderVisibility()}{$this->renderIsStatic()}\${$this->namedVar->getName()}{$this->namedVar->renderDefault()}; |
|
101
|
|
|
|
|
102
|
|
|
|
|
103
|
|
|
PHP; |
|
104
|
|
|
|
|
105
|
|
|
} |
|
106
|
|
|
} |