1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* Copyright 2011 Johannes M. Schmitt <[email protected]> |
4
|
|
|
* |
5
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
6
|
|
|
* you may not use this file except in compliance with the License. |
7
|
|
|
* You may obtain a copy of the License at |
8
|
|
|
* |
9
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
10
|
|
|
* |
11
|
|
|
* Unless required by applicable law or agreed to in writing, software |
12
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
13
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14
|
|
|
* See the License for the specific language governing permissions and |
15
|
|
|
* limitations under the License. |
16
|
|
|
*/ |
17
|
|
|
declare(strict_types=1); |
18
|
|
|
|
19
|
|
|
namespace gossi\codegen\model; |
20
|
|
|
|
21
|
|
|
use gossi\codegen\model\parts\DocblockPart; |
22
|
|
|
use gossi\codegen\model\parts\LongDescriptionPart; |
23
|
|
|
use gossi\codegen\model\parts\NamePart; |
24
|
|
|
use gossi\codegen\model\parts\TypePart; |
25
|
|
|
use gossi\docblock\Docblock; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Abstract PHP member class. |
29
|
|
|
* |
30
|
|
|
* @author Johannes M. Schmitt <[email protected]> |
31
|
|
|
* @author Thomas Gossmann |
32
|
|
|
*/ |
33
|
|
|
abstract class AbstractPhpMember extends AbstractModel implements DocblockInterface { |
34
|
|
|
|
35
|
|
|
use DocblockPart; |
36
|
|
|
use LongDescriptionPart; |
37
|
|
|
use NamePart; |
38
|
|
|
use TypePart; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Private visibility |
42
|
|
|
* |
43
|
|
|
* @var string |
44
|
|
|
*/ |
45
|
|
|
const VISIBILITY_PRIVATE = 'private'; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Protected visibility |
49
|
|
|
* |
50
|
|
|
* @var string |
51
|
|
|
*/ |
52
|
|
|
const VISIBILITY_PROTECTED = 'protected'; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Public visibility |
56
|
|
|
* |
57
|
|
|
* @var string |
58
|
|
|
*/ |
59
|
|
|
const VISIBILITY_PUBLIC = 'public'; |
60
|
|
|
|
61
|
|
|
/** @var bool */ |
62
|
|
|
private $static = false; |
63
|
|
|
|
64
|
|
|
/** @var string */ |
65
|
|
|
private $visibility = self::VISIBILITY_PUBLIC; |
66
|
|
|
|
67
|
|
|
/** @var AbstractPhpStruct */ |
68
|
|
|
private $parent; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Creates a new member |
72
|
|
|
* |
73
|
|
|
* @param string $name the name of the member |
74
|
|
|
*/ |
75
|
52 |
|
public function __construct(string $name) { |
76
|
52 |
|
$this->setName($name); |
77
|
52 |
|
$this->docblock = new Docblock(); |
78
|
52 |
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Sets the members visibility |
82
|
|
|
* |
83
|
|
|
* @see self::VISIBILITY_PUBLIC |
84
|
|
|
* @see self::VISIBILITY_PROTECTED |
85
|
|
|
* @see self::VISIBILITY_PRIVATE |
86
|
|
|
* @param string $visibility the new visibility |
87
|
|
|
* @return $this |
88
|
|
|
*/ |
89
|
17 |
|
public function setVisibility(string $visibility) { |
90
|
17 |
|
if ($visibility !== self::VISIBILITY_PRIVATE |
91
|
17 |
|
&& $visibility !== self::VISIBILITY_PROTECTED |
92
|
17 |
|
&& $visibility !== self::VISIBILITY_PUBLIC) { |
93
|
1 |
|
throw new \InvalidArgumentException(sprintf('The visibility "%s" does not exist.', $visibility)); |
94
|
|
|
} |
95
|
|
|
|
96
|
16 |
|
$this->visibility = $visibility; |
97
|
|
|
|
98
|
16 |
|
return $this; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Returns the visibility state of this member |
103
|
|
|
* |
104
|
|
|
* @return string the visibility |
105
|
|
|
*/ |
106
|
19 |
|
public function getVisibility(): string { |
107
|
19 |
|
return $this->visibility; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Sets whether or not this member is static |
112
|
|
|
* |
113
|
|
|
* @param bool $static |
114
|
|
|
* @return $this |
115
|
|
|
*/ |
116
|
13 |
|
public function setStatic(bool $static) { |
117
|
13 |
|
$this->static = $static; |
118
|
|
|
|
119
|
13 |
|
return $this; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* Returns whether this member is static |
124
|
|
|
* |
125
|
|
|
* @return bool `true` if static and `false` if not |
126
|
|
|
*/ |
127
|
18 |
|
public function isStatic(): bool { |
128
|
18 |
|
return $this->static; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Sets the parent structure to which this member belongs |
133
|
|
|
* |
134
|
|
|
* @internal |
135
|
|
|
* @param AbstractPhpStruct|null $parent |
136
|
|
|
* @return $this |
137
|
|
|
*/ |
138
|
16 |
|
public function setParent(?AbstractPhpStruct $parent) { |
139
|
16 |
|
$this->parent = $parent; |
140
|
16 |
|
return $this; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* Returns the parent structure to which this member belongs |
145
|
|
|
* |
146
|
|
|
* @internal |
147
|
|
|
* @return AbstractPhpStruct |
148
|
|
|
*/ |
149
|
12 |
|
public function getParent(): ?AbstractPhpStruct { |
150
|
12 |
|
return $this->parent; |
151
|
|
|
} |
152
|
|
|
} |
153
|
|
|
|