1 | <?php |
||
12 | class StructArray extends Struct |
||
13 | { |
||
14 | /** |
||
15 | * @var string |
||
16 | */ |
||
17 | const METHOD_GET_ATTRIBUTE_NAME = 'getAttributeName'; |
||
18 | /** |
||
19 | * @var string |
||
20 | */ |
||
21 | const METHOD_CURRENT = 'current'; |
||
22 | /** |
||
23 | * @var string |
||
24 | */ |
||
25 | const METHOD_ITEM = 'item'; |
||
26 | /** |
||
27 | * @var string |
||
28 | */ |
||
29 | const METHOD_FIRST = 'first'; |
||
30 | /** |
||
31 | * @var string |
||
32 | */ |
||
33 | const METHOD_LAST = 'last'; |
||
34 | /** |
||
35 | * @var string |
||
36 | */ |
||
37 | const METHOD_OFFSET_GET = 'offsetGet'; |
||
38 | /** |
||
39 | * @var string |
||
40 | */ |
||
41 | const METHOD_ADD = 'add'; |
||
42 | /** |
||
43 | * @see \WsdlToPhp\PackageGenerator\File\Struct::addStructMethodsSetAndGet() |
||
44 | */ |
||
45 | 28 | public function addStructMethodsSetAndGet(MethodContainer $methods) |
|
46 | { |
||
47 | 28 | parent::addStructMethodsSetAndGet($methods); |
|
48 | 21 | $this |
|
49 | 28 | ->addArrayMethodCurrent($methods) |
|
50 | 28 | ->addArrayMethodItem($methods) |
|
51 | 28 | ->addArrayMethodFirst($methods) |
|
52 | 28 | ->addArrayMethodLast($methods) |
|
53 | 28 | ->addArrayMethodOffsetGet($methods) |
|
54 | 28 | ->addArrayMethodAdd($methods) |
|
55 | 28 | ->addArrayMethodGetAttributeName($methods); |
|
56 | 28 | return $this; |
|
57 | } |
||
58 | /** |
||
59 | * @param MethodContainer $methods |
||
60 | * @return StructArray |
||
61 | */ |
||
62 | 28 | protected function addArrayMethodCurrent(MethodContainer $methods) |
|
63 | { |
||
64 | 28 | return $this->addArrayMethodGenericMethod($methods, self::METHOD_CURRENT, $this->getArrayMethodBody(self::METHOD_CURRENT)); |
|
65 | } |
||
66 | /** |
||
67 | * @param MethodContainer $methods |
||
68 | * @return StructArray |
||
69 | */ |
||
70 | 28 | protected function addArrayMethodItem(MethodContainer $methods) |
|
71 | { |
||
72 | 28 | return $this->addArrayMethodGenericMethod($methods, self::METHOD_ITEM, $this->getArrayMethodBody(self::METHOD_ITEM, '$index'), array( |
|
73 | 28 | 'index', |
|
74 | 21 | )); |
|
75 | } |
||
76 | /** |
||
77 | * @param MethodContainer $methods |
||
78 | * @return StructArray |
||
79 | */ |
||
80 | 28 | protected function addArrayMethodFirst(MethodContainer $methods) |
|
81 | { |
||
82 | 28 | return $this->addArrayMethodGenericMethod($methods, self::METHOD_FIRST, $this->getArrayMethodBody(self::METHOD_FIRST)); |
|
83 | } |
||
84 | /** |
||
85 | * @param MethodContainer $methods |
||
86 | * @return StructArray |
||
87 | */ |
||
88 | 28 | protected function addArrayMethodLast(MethodContainer $methods) |
|
89 | { |
||
90 | 28 | return $this->addArrayMethodGenericMethod($methods, self::METHOD_LAST, $this->getArrayMethodBody(self::METHOD_LAST)); |
|
91 | } |
||
92 | /** |
||
93 | * @param MethodContainer $methods |
||
94 | * @return StructArray |
||
95 | */ |
||
96 | 28 | protected function addArrayMethodOffsetGet(MethodContainer $methods) |
|
97 | { |
||
98 | 28 | return $this->addArrayMethodGenericMethod($methods, self::METHOD_OFFSET_GET, $this->getArrayMethodBody(self::METHOD_OFFSET_GET, '$offset'), array( |
|
99 | 28 | 'offset', |
|
100 | 21 | )); |
|
101 | } |
||
102 | /** |
||
103 | * @param MethodContainer $methods |
||
104 | * @return StructArray |
||
105 | */ |
||
106 | 28 | protected function addArrayMethodGetAttributeName(MethodContainer $methods) |
|
107 | { |
||
108 | 28 | return $this->addArrayMethodGenericMethod($methods, self::METHOD_GET_ATTRIBUTE_NAME, sprintf('return \'%s\';', $this->getModel()->getAttributes()->offsetGet(0)->getName())); |
|
109 | } |
||
110 | /** |
||
111 | * @param MethodContainer $methods |
||
112 | * @return StructArray |
||
113 | */ |
||
114 | 28 | protected function addArrayMethodAdd(MethodContainer $methods) |
|
115 | { |
||
116 | 28 | if ($this->getRestrictionFromStructAttribute() instanceof StructModel) { |
|
117 | 12 | $method = new PhpMethod(self::METHOD_ADD, array( |
|
118 | 12 | 'item', |
|
119 | 9 | )); |
|
120 | 12 | $this->addStructMethodSetBodyForRestriction($method, $this->getModel()->getAttributes()->offsetGet(0), 'item'); |
|
121 | 12 | $method->addChild('return parent::add($item);'); |
|
122 | 12 | $methods->add($method); |
|
123 | 9 | } |
|
124 | 28 | return $this; |
|
125 | } |
||
126 | /** |
||
127 | * @param MethodContainer $methods |
||
128 | * @param string $name |
||
129 | * @param string $body |
||
130 | * @param string[] $methodParameters |
||
131 | * @return StructArray |
||
132 | */ |
||
133 | 28 | protected function addArrayMethodGenericMethod(MethodContainer $methods, $name, $body, array $methodParameters = array()) |
|
140 | /** |
||
141 | * @return PhpAnnotationBlock |
||
142 | */ |
||
143 | 28 | protected function getArrayMethodGetAttributeNameAnnotationBlock() |
|
151 | /** |
||
152 | * @return PhpAnnotationBlock |
||
153 | */ |
||
154 | 28 | protected function getArrayMethodCurrentAnnotationBlock() |
|
158 | /** |
||
159 | * @return PhpAnnotationBlock |
||
160 | */ |
||
161 | 28 | protected function getArrayMethodFirstAnnotationBlock() |
|
165 | /** |
||
166 | * @return PhpAnnotationBlock |
||
167 | */ |
||
168 | 28 | protected function getArrayMethodLastAnnotationBlock() |
|
172 | /** |
||
173 | * @return PhpAnnotationBlock |
||
174 | */ |
||
175 | 28 | protected function getArrayMethodItemAnnotationBlock() |
|
179 | /** |
||
180 | * @return PhpAnnotationBlock |
||
181 | */ |
||
182 | 28 | protected function getArrayMethodOffsetGetAnnotationBlock() |
|
186 | /** |
||
187 | * @return PhpAnnotationBlock |
||
188 | */ |
||
189 | 12 | protected function getArrayMethodAddAnnotationBlock() |
|
190 | { |
||
191 | 12 | return new PhpAnnotationBlock(array( |
|
192 | 12 | 'Add element to array', |
|
193 | 12 | new PhpAnnotation(self::ANNOTATION_SEE, sprintf('%s::add()', $this->getModel()->getExtends(true))), |
|
194 | 12 | new PhpAnnotation(self::ANNOTATION_THROWS, '\InvalidArgumentException'), |
|
195 | 12 | new PhpAnnotation(self::ANNOTATION_USES, sprintf('%s::valueIsValid()', $this->getModelFromStructAttribute()->getPackagedName(true))), |
|
196 | 12 | new PhpAnnotation(self::ANNOTATION_PARAM, sprintf('%s $item', $this->getStructAttributeType())), |
|
197 | 12 | new PhpAnnotation(self::ANNOTATION_RETURN, sprintf('%s', $this->getModel()->getPackagedName(true))), |
|
198 | 9 | )); |
|
199 | } |
||
200 | /** |
||
201 | * @param string $name |
||
202 | * @param string $description |
||
203 | * @param string $param |
||
204 | * @return PhpAnnotationBlock |
||
205 | */ |
||
206 | 28 | protected function getArrayMethodGenericAnnotationBlock($name, $description, $param = null) |
|
207 | { |
||
208 | 28 | $annotationBlock = new PhpAnnotationBlock(array( |
|
209 | 28 | $description, |
|
210 | 28 | new PhpAnnotation(self::ANNOTATION_SEE, sprintf('%s::%s()', $this->getModel()->getExtends(true), $name)), |
|
211 | 21 | )); |
|
212 | 28 | if (!empty($param)) { |
|
213 | 28 | $annotationBlock->addChild(new PhpAnnotation(self::ANNOTATION_PARAM, $param)); |
|
214 | 21 | } |
|
215 | 28 | $annotationBlock->addChild(new PhpAnnotation(self::ANNOTATION_RETURN, $this->getStructAttributeTypeGetAnnotation(null, false))); |
|
216 | 28 | return $annotationBlock; |
|
217 | } |
||
218 | /** |
||
219 | * @param PhpMethod $method |
||
220 | * @return PhpAnnotationBlock|null |
||
221 | */ |
||
222 | 28 | protected function getStructMethodAnnotationBlock(PhpMethod $method) |
|
258 | /** |
||
259 | * @param string $method |
||
260 | * @param string $var |
||
261 | * @return string |
||
262 | */ |
||
263 | 28 | protected function getArrayMethodBody($method, $var = '') |
|
267 | /** |
||
268 | * @see \WsdlToPhp\PackageGenerator\File\AbstractModelFile::setModel() |
||
269 | * @throws \InvalidaArgumentException |
||
270 | * @param AbstractModel $model |
||
271 | * @return StructArray |
||
272 | */ |
||
273 | 40 | public function setModel(AbstractModel $model) |
|
280 | } |
||
281 |