|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace WsdlToPhp\PackageGenerator\Model; |
|
4
|
|
|
|
|
5
|
|
|
use WsdlToPhp\PackageGenerator\Generator\Utils; |
|
6
|
|
|
use WsdlToPhp\PackageGenerator\Generator\Generator; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Class StructAttribute stands for an available struct attribute described in the WSDL |
|
10
|
|
|
*/ |
|
11
|
|
|
class StructAttribute extends AbstractModel |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* Type of the struct attribute |
|
15
|
|
|
* @var string |
|
16
|
|
|
*/ |
|
17
|
|
|
private $type = ''; |
|
18
|
|
|
/** |
|
19
|
|
|
* Defines that this property is not a simple value but an array of values |
|
20
|
|
|
* Infos at {@link https://www.w3.org/TR/xmlschema-0/#OccurrenceConstraints} |
|
21
|
|
|
* @var bool |
|
22
|
|
|
*/ |
|
23
|
|
|
private $containsElements = false; |
|
24
|
|
|
/** |
|
25
|
|
|
* Main constructor |
|
26
|
|
|
* @see AbstractModel::__construct() |
|
27
|
|
|
* @uses StructAttribute::setType() |
|
28
|
|
|
* @uses AbstractModel::setOwner() |
|
29
|
|
|
* @param Generator $generator |
|
30
|
|
|
* @param string $name the original name |
|
31
|
|
|
* @param string $type the type |
|
32
|
|
|
* @param Struct $struct defines the struct which owns this value |
|
33
|
|
|
*/ |
|
34
|
412 |
|
public function __construct(Generator $generator, $name, $type, Struct $struct) |
|
35
|
|
|
{ |
|
36
|
412 |
|
parent::__construct($generator, $name); |
|
37
|
412 |
|
$this->setType($type); |
|
38
|
412 |
|
$this->setOwner($struct); |
|
39
|
412 |
|
} |
|
40
|
|
|
/** |
|
41
|
|
|
* Returns the unique name in the current struct (for setters/getters and struct contrusctor array) |
|
42
|
|
|
* @uses AbstractModel::getCleanName() |
|
43
|
|
|
* @uses AbstractModel::getName() |
|
44
|
|
|
* @uses AbstractModel::uniqueName() |
|
45
|
|
|
* @uses StructAttribute::getOwner() |
|
46
|
|
|
* @return string |
|
47
|
|
|
*/ |
|
48
|
84 |
|
public function getUniqueName() |
|
49
|
|
|
{ |
|
50
|
84 |
|
return self::uniqueName($this->getCleanName(), $this->getOwner()->getName()); |
|
51
|
|
|
} |
|
52
|
|
|
/** |
|
53
|
|
|
* Returns the getter name for this attribute |
|
54
|
|
|
* @uses StructAttribute::getUniqueName() |
|
55
|
|
|
* @return string |
|
56
|
|
|
*/ |
|
57
|
80 |
|
public function getGetterName() |
|
58
|
|
|
{ |
|
59
|
80 |
|
return sprintf('get%s', ucfirst(self::getUniqueName())); |
|
60
|
|
|
} |
|
61
|
|
|
/** |
|
62
|
|
|
* Returns the getter name for this attribute |
|
63
|
|
|
* @uses StructAttribute::getUniqueName() |
|
64
|
|
|
* @return string |
|
65
|
|
|
*/ |
|
66
|
80 |
|
public function getSetterName() |
|
67
|
|
|
{ |
|
68
|
80 |
|
return sprintf('set%s', ucfirst(self::getUniqueName())); |
|
69
|
|
|
} |
|
70
|
|
|
/** |
|
71
|
|
|
* Returns the type value |
|
72
|
|
|
* @return string |
|
73
|
|
|
*/ |
|
74
|
260 |
|
public function getType() |
|
75
|
|
|
{ |
|
76
|
260 |
|
return $this->type; |
|
77
|
|
|
} |
|
78
|
|
|
/** |
|
79
|
|
|
* Sets the type value |
|
80
|
|
|
* @param string $type |
|
81
|
|
|
* @return StructAttribute |
|
82
|
|
|
*/ |
|
83
|
412 |
|
public function setType($type) |
|
84
|
|
|
{ |
|
85
|
412 |
|
$this->type = $type; |
|
86
|
412 |
|
return $this; |
|
87
|
|
|
} |
|
88
|
|
|
/** |
|
89
|
|
|
* Returns the type value |
|
90
|
|
|
* @return bool |
|
91
|
|
|
*/ |
|
92
|
4 |
|
public function getContainsElements() |
|
93
|
|
|
{ |
|
94
|
4 |
|
return $this->containsElements; |
|
95
|
|
|
} |
|
96
|
|
|
/** |
|
97
|
|
|
* Sets the type value |
|
98
|
|
|
* @param bool $containsElements |
|
99
|
|
|
* @return StructAttribute |
|
100
|
|
|
*/ |
|
101
|
248 |
|
public function setContainsElements($containsElements) |
|
102
|
|
|
{ |
|
103
|
248 |
|
$this->containsElements = $containsElements; |
|
104
|
248 |
|
return $this; |
|
105
|
|
|
} |
|
106
|
|
|
/** |
|
107
|
|
|
* If this attribute contains elements then it's an array |
|
108
|
|
|
* only if its parent, the Struct, is not itself an array, |
|
109
|
|
|
* if the parent is an array, then it is certainly not an array too |
|
110
|
|
|
* @return bool |
|
111
|
|
|
*/ |
|
112
|
80 |
|
public function isArray() |
|
113
|
|
|
{ |
|
114
|
80 |
|
return $this->containsElements; |
|
115
|
|
|
} |
|
116
|
|
|
/** |
|
117
|
|
|
* Returns potential default value |
|
118
|
|
|
* @uses AbstractModel::getMetaValueFirstSet() |
|
119
|
|
|
* @uses Utils::getValueWithinItsType() |
|
120
|
|
|
* @uses StructAttribute::getType() |
|
121
|
|
|
* @uses StructAttribute::getContainsElements() |
|
122
|
|
|
* @return mixed |
|
123
|
|
|
*/ |
|
124
|
80 |
|
public function getDefaultValue() |
|
125
|
|
|
{ |
|
126
|
80 |
|
if ($this->isArray()) { |
|
127
|
44 |
|
return array(); |
|
128
|
|
|
} |
|
129
|
52 |
|
return Utils::getValueWithinItsType($this->getMetaValueFirstSet(array( |
|
130
|
52 |
|
'default', |
|
131
|
39 |
|
'Default', |
|
132
|
39 |
|
'DefaultValue', |
|
133
|
39 |
|
'defaultValue', |
|
134
|
39 |
|
'defaultvalue', |
|
135
|
52 |
|
)), $this->getType()); |
|
136
|
|
|
} |
|
137
|
|
|
/** |
|
138
|
|
|
* Returns true or false depending on minOccurs information associated to the attribute |
|
139
|
|
|
* @uses AbstractModel::getMetaValueFirstSet() |
|
140
|
|
|
* @uses AbstractModel::getMetaValue() |
|
141
|
|
|
* @return bool true|false |
|
142
|
|
|
*/ |
|
143
|
80 |
|
public function isRequired() |
|
144
|
|
|
{ |
|
145
|
80 |
|
return ($this->getMetaValue('use', '') === 'required' || $this->getMetaValueFirstSet(array( |
|
146
|
76 |
|
'minOccurs', |
|
147
|
57 |
|
'minoccurs', |
|
148
|
57 |
|
'MinOccurs', |
|
149
|
57 |
|
'Minoccurs', |
|
150
|
80 |
|
), false)); |
|
151
|
|
|
} |
|
152
|
|
|
/** |
|
153
|
|
|
* Returns the owner model object, meaning a Struct object |
|
154
|
|
|
* @see AbstractModel::getOwner() |
|
155
|
|
|
* @uses AbstractModel::getOwner() |
|
156
|
|
|
* @return Struct |
|
157
|
|
|
*/ |
|
158
|
84 |
|
public function getOwner() |
|
159
|
|
|
{ |
|
160
|
84 |
|
return parent::getOwner(); |
|
161
|
|
|
} |
|
162
|
|
|
/** |
|
163
|
|
|
* @uses StructAttribute::getType() |
|
164
|
|
|
* @return bool |
|
165
|
|
|
*/ |
|
166
|
80 |
|
public function isXml() |
|
167
|
|
|
{ |
|
168
|
80 |
|
return stripos($this->getType(), '\DOM') === 0; |
|
169
|
|
|
} |
|
170
|
|
|
/** |
|
171
|
|
|
* @return Struct|null |
|
172
|
|
|
*/ |
|
173
|
92 |
|
public function getTypeStruct() |
|
174
|
|
|
{ |
|
175
|
92 |
|
return $this->getGenerator()->getStruct($this->getType()); |
|
176
|
|
|
} |
|
177
|
|
|
/** |
|
178
|
|
|
* @return string[] |
|
179
|
|
|
*/ |
|
180
|
92 |
|
public function getTypeStructMeta() |
|
181
|
|
|
{ |
|
182
|
92 |
|
$typeStruct = $this->getTypeStruct(); |
|
183
|
92 |
|
return ($typeStruct && !$typeStruct->getIsStruct()) ? $typeStruct->getMeta() : array(); |
|
184
|
|
|
} |
|
185
|
|
|
/** |
|
186
|
|
|
* @return Struct|null |
|
187
|
|
|
*/ |
|
188
|
92 |
|
public function getInheritanceStruct() |
|
189
|
|
|
{ |
|
190
|
92 |
|
return $this->getGenerator()->getStruct($this->getInheritance()); |
|
191
|
|
|
} |
|
192
|
|
|
/** |
|
193
|
|
|
* @return string[] |
|
194
|
|
|
*/ |
|
195
|
92 |
|
public function getInheritanceStructMeta() |
|
196
|
|
|
{ |
|
197
|
92 |
|
$inheritanceStruct = $this->getInheritanceStruct(); |
|
198
|
92 |
|
return ($inheritanceStruct && !$inheritanceStruct->getIsStruct()) ? $inheritanceStruct->getMeta() : array(); |
|
199
|
|
|
} |
|
200
|
|
|
/** |
|
201
|
|
|
* @see \WsdlToPhp\PackageGenerator\Model\AbstractModel::getMeta() |
|
202
|
|
|
* @return string[] |
|
203
|
|
|
*/ |
|
204
|
92 |
|
public function getMeta() |
|
205
|
|
|
{ |
|
206
|
92 |
|
return array_merge_recursive(parent::getMeta(), $this->getTypeStructMeta(), $this->getInheritanceStructMeta()); |
|
207
|
|
|
} |
|
208
|
|
|
} |
|
209
|
|
|
|