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 REAPLCEMENT_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 | 268 | public function __construct(Generator $generator, $name, $index, Struct $struct) |
|
47 | /** |
||
48 | * Returns the name of the value as constant |
||
49 | * @see AbstractModel::getCleanName() |
||
50 | * @uses AbstractModel::getCleanName() |
||
51 | * @uses AbstractModel::getName() |
||
52 | * @uses AbstractModel::getOwner() |
||
53 | * @uses StructValue::constantSuffix() |
||
54 | * @uses StructValue::getIndex() |
||
55 | * @uses StructValue::getOwner() |
||
56 | * @uses Generator::getOptionGenericConstantsNames() |
||
57 | * @param bool $keepMultipleUnderscores optional, allows to keep the multiple consecutive underscores |
||
58 | * @return string |
||
59 | */ |
||
60 | 52 | public function getCleanName($keepMultipleUnderscores = false) |
|
70 | /** |
||
71 | * @param bool $keepMultipleUnderscores optional, allows to keep the multiple consecutive underscores |
||
72 | * @return string |
||
73 | */ |
||
74 | 48 | public function getNameWithSeparatedWords($keepMultipleUnderscores = false) |
|
78 | /** |
||
79 | * Returns the value with good type |
||
80 | * @uses AbstractModel::getName() |
||
81 | * @uses Utils::getValueWithinItsType() |
||
82 | * @return mixed |
||
83 | */ |
||
84 | 52 | public function getValue() |
|
88 | /** |
||
89 | * Gets the index attribute value |
||
90 | * @return int |
||
91 | */ |
||
92 | 52 | public function getIndex() |
|
96 | /** |
||
97 | * Sets the index attribute value |
||
98 | * @throws \InvalidArgumentException |
||
99 | * @param int $index |
||
100 | * @return StructValue |
||
101 | */ |
||
102 | 268 | public function setIndex($index) |
|
110 | /** |
||
111 | * Returns the index which has to be added at the end of natural constant name defined with the value cleaned |
||
112 | * Allows to avoid multiple constant name to be indentic |
||
113 | * @param string $structName the struct name |
||
114 | * @param string $value the value |
||
115 | * @param int $index the position of the value |
||
116 | * @return int |
||
117 | */ |
||
118 | 48 | private static function constantSuffix($structName, $value, $index) |
|
132 | /** |
||
133 | * Returns the owner model object, meaning a Struct object |
||
134 | * @see AbstractModel::getOwner() |
||
135 | * @uses AbstractModel::getOwner() |
||
136 | * @return Struct |
||
137 | */ |
||
138 | 48 | public function getOwner() |
|
142 | } |
||
143 |