1 | <?php |
||
11 | class StructValue extends AbstractModel |
||
12 | { |
||
13 | /** |
||
14 | * @var string |
||
15 | */ |
||
16 | const MATCH_PATTERN = '/([[:upper:]]+[[:lower:]]*)|([[:lower:]]+)|(\d+)/'; |
||
17 | /** |
||
18 | * @var string |
||
19 | */ |
||
20 | const REPLACEMENT_PATTERN = '$1$2$3_'; |
||
21 | /** |
||
22 | * Store the constants generated per structName |
||
23 | * @var array |
||
24 | */ |
||
25 | private static $uniqueConstants = array(); |
||
26 | /** |
||
27 | * The index of the value in the enumeration struct |
||
28 | * @var int |
||
29 | */ |
||
30 | private $index = 0; |
||
31 | /** |
||
32 | * Main constructor |
||
33 | * @see AbstractModel::__construct() |
||
34 | * @uses AbstractModel::setOwner() |
||
35 | * @uses StructValue::setIndex() |
||
36 | * @param Generator $generator |
||
37 | * @param string $name the original name |
||
38 | * @param string $index the index of the value in the enumeration struct |
||
39 | * @param Struct $struct defines the struct which owns this value |
||
40 | */ |
||
41 | public function __construct(Generator $generator, $name, $index = 0, Struct $struct = null) |
||
42 | { |
||
43 | parent::__construct($generator, $name); |
||
44 | $this->setIndex($index)->setOwner($struct); |
||
45 | } |
||
46 | /** |
||
47 | * Returns the name of the value as constant |
||
48 | * @see AbstractModel::getCleanName() |
||
49 | * @uses AbstractModel::getCleanName() |
||
50 | * @uses AbstractModel::getName() |
||
51 | * @uses AbstractModel::getOwner() |
||
52 | * @uses StructValue::constantSuffix() |
||
53 | * @uses StructValue::getIndex() |
||
54 | * @uses StructValue::getOwner() |
||
55 | * @uses Generator::getOptionGenericConstantsNames() |
||
56 | * @param bool $keepMultipleUnderscores optional, allows to keep the multiple consecutive underscores |
||
57 | * @return string |
||
58 | */ |
||
59 | public function getCleanName($keepMultipleUnderscores = false) |
||
69 | /** |
||
70 | * @param bool $keepMultipleUnderscores optional, allows to keep the multiple consecutive underscores |
||
71 | * @return string |
||
72 | */ |
||
73 | public function getNameWithSeparatedWords($keepMultipleUnderscores = false) |
||
77 | /** |
||
78 | * Returns the value with good type |
||
79 | * @uses AbstractModel::getName() |
||
80 | * @uses Utils::getValueWithinItsType() |
||
81 | * @return mixed |
||
82 | */ |
||
83 | public function getValue() |
||
87 | /** |
||
88 | * Gets the index attribute value |
||
89 | * @return int |
||
90 | */ |
||
91 | public function getIndex() |
||
95 | /** |
||
96 | * Sets the index attribute value |
||
97 | * @throws \InvalidArgumentException |
||
98 | * @param int $index |
||
99 | * @return StructValue |
||
100 | */ |
||
101 | public function setIndex($index) |
||
109 | /** |
||
110 | * Returns the index which has to be added at the end of natural constant name defined with the value cleaned |
||
111 | * Allows to avoid multiple constant name to be indentic |
||
112 | * @param string $structName the struct name |
||
113 | * @param string $value the value |
||
114 | * @param int $index the position of the value |
||
115 | * @return int |
||
116 | */ |
||
117 | private static function constantSuffix($structName, $value, $index) |
||
131 | /** |
||
132 | * Returns the owner model object, meaning a Struct object |
||
133 | * @see AbstractModel::getOwner() |
||
134 | * @uses AbstractModel::getOwner() |
||
135 | * @return Struct |
||
136 | */ |
||
137 | public function getOwner() |
||
141 | /** |
||
142 | * {@inheritDoc} |
||
143 | * @see \WsdlToPhp\PackageGenerator\Model\AbstractModel::toJsonSerialize() |
||
144 | */ |
||
145 | protected function toJsonSerialize() |
||
151 | } |
||
152 |