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 string |
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
|
380 |
|
public function __construct(Generator $generator, $name, $type, Struct $struct) |
35
|
|
|
{ |
36
|
380 |
|
parent::__construct($generator, $name); |
37
|
380 |
|
$this->setType($type); |
38
|
380 |
|
$this->setOwner($struct); |
39
|
380 |
|
} |
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
|
72 |
|
public function getUniqueName() |
49
|
|
|
{ |
50
|
72 |
|
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
|
68 |
|
public function getGetterName() |
58
|
|
|
{ |
59
|
68 |
|
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
|
68 |
|
public function getSetterName() |
67
|
|
|
{ |
68
|
68 |
|
return sprintf('set%s', ucfirst(self::getUniqueName())); |
69
|
|
|
} |
70
|
|
|
/** |
71
|
|
|
* Returns the type value |
72
|
|
|
* @return string |
73
|
|
|
*/ |
74
|
244 |
|
public function getType() |
75
|
|
|
{ |
76
|
244 |
|
return $this->type; |
77
|
|
|
} |
78
|
|
|
/** |
79
|
|
|
* Sets the type value |
80
|
|
|
* @param string $type |
81
|
|
|
* @return StructAttribute |
82
|
|
|
*/ |
83
|
380 |
|
public function setType($type) |
84
|
|
|
{ |
85
|
380 |
|
$this->type = $type; |
86
|
380 |
|
return $this; |
87
|
|
|
} |
88
|
|
|
/** |
89
|
|
|
* Returns the type value |
90
|
|
|
* @return string |
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 string |
100
|
|
|
*/ |
101
|
232 |
|
public function setContainsElements($containsElements) |
102
|
|
|
{ |
103
|
232 |
|
$this->containsElements = $containsElements; |
|
|
|
|
104
|
232 |
|
return $this; |
105
|
|
|
} |
106
|
|
|
/** |
107
|
|
|
* Returns potential default value |
108
|
|
|
* @uses AbstractModel::getMetaValueFirstSet() |
109
|
|
|
* @uses Utils::getValueWithinItsType() |
110
|
|
|
* @uses StructAttribute::getType() |
111
|
|
|
* @return mixed |
112
|
|
|
*/ |
113
|
48 |
|
public function getDefaultValue() |
114
|
|
|
{ |
115
|
48 |
|
return Utils::getValueWithinItsType($this->getMetaValueFirstSet(array( |
116
|
48 |
|
'default', |
117
|
36 |
|
'Default', |
118
|
36 |
|
'DefaultValue', |
119
|
36 |
|
'defaultValue', |
120
|
36 |
|
'defaultvalue', |
121
|
48 |
|
)), $this->getType()); |
122
|
|
|
} |
123
|
|
|
/** |
124
|
|
|
* Returns true or false depending on minOccurs information associated to the attribute |
125
|
|
|
* @uses AbstractModel::getMetaValueFirstSet() |
126
|
|
|
* @uses AbstractModel::getMetaValue() |
127
|
|
|
* @return bool true|false |
128
|
|
|
*/ |
129
|
68 |
|
public function isRequired() |
130
|
|
|
{ |
131
|
68 |
|
return ($this->getMetaValue('use', '') === 'required' || $this->getMetaValueFirstSet(array( |
132
|
68 |
|
'minOccurs', |
133
|
51 |
|
'minoccurs', |
134
|
51 |
|
'MinOccurs', |
135
|
51 |
|
'Minoccurs', |
136
|
68 |
|
), false)); |
137
|
|
|
} |
138
|
|
|
/** |
139
|
|
|
* Returns the owner model object, meaning a Struct object |
140
|
|
|
* @see AbstractModel::getOwner() |
141
|
|
|
* @uses AbstractModel::getOwner() |
142
|
|
|
* @return Struct |
143
|
|
|
*/ |
144
|
72 |
|
public function getOwner() |
145
|
|
|
{ |
146
|
72 |
|
return parent::getOwner(); |
147
|
|
|
} |
148
|
|
|
/** |
149
|
|
|
* @return bool |
150
|
|
|
*/ |
151
|
68 |
|
public function isXml() |
152
|
|
|
{ |
153
|
68 |
|
return stripos($this->getType(), '\DOM') === 0; |
154
|
|
|
} |
155
|
|
|
} |
156
|
|
|
|
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.