Skip to content

Commit 566a0ac

Browse files
committed
issue #33 - auto initialize internArray
in order to be able to loop on the object without having to call manually initInternArray
1 parent f90f261 commit 566a0ac

File tree

6 files changed

+109
-152
lines changed

6 files changed

+109
-152
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# CHANGELOG
22

3+
## 5.0.0 - 2021/02/xx
4+
- Issue #13 - Auto initialize AbstractStructArrayBase::internArray
5+
- BC: read [UPGRADE-5.0.md](/UPGRADE-5.0.md)
6+
37
## 4.0.0 - 2021/02/03
48
- BC:
59
- `WsdlToPhp\PackageBase\AbstractStructBase::_set` has been renamed to `WsdlToPhp\PackageBase\AbstractStructBase::setPropertyValue`

README.md

Lines changed: 32 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,12 @@ It defines five methods:
131131

132132
#### Usage
133133
```php
134-
$item = \Api\StructType\Item::__set_state(array(
134+
$item = \Api\StructType\Item::__set_state([
135135
'id' => 1,
136136
'name' => 'Entity #1',
137137
'label' => 'Entity #1',
138138
'_href' => 'http://www.entity.com',
139-
));
139+
]);
140140
// $item is now an \Api\StructType\Item object
141141
```
142142

@@ -147,87 +147,83 @@ This class is the base class for any ```ArrayType``` class generated by [Package
147147
#### Usage
148148
As soon as you have an element that is an array of items such as:
149149
```php
150-
$items = \Api\ArrayType\Items::__set_state(array(
151-
'items' => array(
152-
\Api\StructType\Item::__set_state(array(
150+
$items = \Api\ArrayType\Items::__set_state([
151+
'items' => [
152+
\Api\StructType\Item::__set_state([
153153
'id' => 1,
154154
'name' => 'Entity #1',
155155
'label' => 'Entity #1',
156156
'_href' => 'http://www.entity-1.com',
157-
),
158-
\Api\StructType\Item::__set_state(array(
157+
]),
158+
\Api\StructType\Item::__set_state([
159159
'id' => 2,
160160
'name' => 'Entity #2',
161161
'label' => 'Entity #2',
162162
'_href' => 'http://www.entity-2.com',
163-
),
164-
\Api\StructType\Item::__set_state(array(
163+
]),
164+
\Api\StructType\Item::__set_state([
165165
'id' => 3,
166166
'name' => 'Entity #3',
167167
'label' => 'Entity #3',
168168
'_href' => 'http://www.entity-3.com',
169-
),
170-
)
171-
));
169+
]),
170+
],
171+
]);
172172
// 'items' is the unique property of the object
173173
// Its name is returned by the getAttributeName method
174174
// defined in the generated \Api\ArrayType\Items class
175175
```
176-
- **You MUST call first** ```initInternArray``` method on your ArrayType object otherwise you'll get nothing working for the implemented methods:
177-
```php
178-
$items->initInternArray();
179-
```
180-
- then you can call ```count```, ```length``` methods: gives you the number of items contained by your object
181-
- you can iterate through the items:
176+
- **You can call ```count```, ```length``` methods: gives you the number of items contained by your object
177+
- You can iterate through the items:
182178
```php
183179
foreach ($items as $item) {
184180
// $items->current() and $item is an \Api\StructType\Item object
185181
// $items->key() is the current index
186182
}
187183
```
188-
- you can get the first item:
184+
- You can get the first item:
189185
```php
190186
$items->first();
191187
```
192-
- you can get the last item:
188+
- You can get the last item:
193189
```php
194190
$items->last();
195191
```
196-
- you can get any item:
192+
- You can get any item:
197193
```php
198194
$items->item($index);
199195
```
200-
- you can add a new item:
196+
- You can add a new item:
201197
```php
202-
$items->add(\Api\StructType\Item::__set_state(array(
198+
$items->add(\Api\StructType\Item::__set_state([
203199
'id' => 4,
204200
'name' => 'Entity #4',
205201
'label' => 'Entity #4',
206202
'_href' => 'http://www.entity-4.com',
207-
)));
203+
]));
208204
```
209-
- you can even reset the items:
205+
- You can even reset the items:
210206
```php
211-
$items->initInternArray(array(
212-
\Api\StructType\Item::__set_state(array(
207+
$items->initInternArray([
208+
\Api\StructType\Item::__set_state([
213209
'id' => 0,
214210
'name' => 'Entity #0',
215211
'label' => 'Entity #0',
216212
'_href' => 'http://www.entity-0.com',
217-
),
218-
\Api\StructType\Item::__set_state(array(
213+
]),
214+
\Api\StructType\Item::__set_state([
219215
'id' => 1,
220216
'name' => 'Entity #1',
221217
'label' => 'Entity #1',
222218
'_href' => 'http://www.entity-1.com',
223-
),
224-
\Api\StructType\Item::__set_state(array(
219+
]),
220+
\Api\StructType\Item::__set_state([
225221
'id' => 2,
226222
'name' => 'Entity #2',
227223
'label' => 'Entity #2',
228224
'_href' => 'http://www.entity-2.com',
229-
),
230-
));
225+
]),
226+
]);
231227
```
232228

233229
### AbstractSoapClientBase
@@ -246,7 +242,7 @@ class ApiUpdate extends AbstractSoapClientBase
246242
public function UpdateBulkOrder(\Api\StructType\ApiUpdateBulkOrder $parameters)
247243
{
248244
try {
249-
$this->setResult(self::getSoapClient()->UpdateBulkOrder($parameters));
245+
$this->setResult($this->getSoapClient()->UpdateBulkOrder($parameters));
250246
return $this->getResult();
251247
} catch (\SoapFault $soapFault) {
252248
$this->saveLastError(__METHOD__, $soapFault);
@@ -258,10 +254,10 @@ class ApiUpdate extends AbstractSoapClientBase
258254
You can do:
259255
```php
260256
use \WsdlToPhp\PackageBase\AbstractSoapClientBase;
261-
$options = array(
257+
$options = [
262258
AbstractSoapClientBase::WSDL_URL => '__WSDL_URL__',
263259
AbstractSoapClientBase::WSDL_CLASSMAP => \Api\ApiClassMap::classMap(),
264-
);
260+
];
265261
// sets the first instance of SoapClient within AbstractSoapClientBase
266262
$update = new \Api\ServiceType\ApiUpdate($options);
267263
// resets the SoapClient instance

UPGRADE-4.0.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# UPGRADE FROM 3.0 to 4.0
22

3-
The previsouly `_set` and `_get` methods are to be used internally and are not intended to be used externally, at your own risks ;)
3+
The previously `_set` and `_get` methods are to be used internally and are not intended to be used externally, at your own risks ;)
44

55
**Previously**:
66
```php

UPGRADE-5.0.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# UPGRADE FROM 4.0 to 5.0
2+
3+
Internal properties and methods are now private:
4+
- Properties:
5+
- $internArray
6+
- $internArrayIsArray
7+
- $internArrayOffset
8+
- Methods:
9+
- getInternArray
10+
- setInternArray
11+
- getInternArrayOffset
12+
- initInternArray
13+
- setInternArrayOffset
14+
- getInternArrayIsArray
15+
- setInternArrayIsArray
16+
17+
You don't have to manually call `initInternArray` before looping on the current object.

0 commit comments

Comments
 (0)