Skip to content

Commit 195c3bf

Browse files
committed
Merge branch 'release/5.0.0'
2 parents 5eb27d0 + 72de482 commit 195c3bf

File tree

6 files changed

+100
-166
lines changed

6 files changed

+100
-166
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/05
4+
- Issue #13 - Auto initialize AbstractStructArrayBase::internArray
5+
- BC: read [UPGRADE-5.0.md](/UPGRADE-5.0.md)
6+
37
## 4.0.1 - 2021/02/05
48
- Add deprecation messages for next major release 5
59

README.md

Lines changed: 23 additions & 50 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,60 @@ 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-
)));
208-
```
209-
- you can even reset the items:
210-
```php
211-
$items->initInternArray(array(
212-
\Api\StructType\Item::__set_state(array(
213-
'id' => 0,
214-
'name' => 'Entity #0',
215-
'label' => 'Entity #0',
216-
'_href' => 'http://www.entity-0.com',
217-
),
218-
\Api\StructType\Item::__set_state(array(
219-
'id' => 1,
220-
'name' => 'Entity #1',
221-
'label' => 'Entity #1',
222-
'_href' => 'http://www.entity-1.com',
223-
),
224-
\Api\StructType\Item::__set_state(array(
225-
'id' => 2,
226-
'name' => 'Entity #2',
227-
'label' => 'Entity #2',
228-
'_href' => 'http://www.entity-2.com',
229-
),
230-
));
203+
]));
231204
```
232205

233206
### AbstractSoapClientBase
@@ -246,7 +219,7 @@ class ApiUpdate extends AbstractSoapClientBase
246219
public function UpdateBulkOrder(\Api\StructType\ApiUpdateBulkOrder $parameters)
247220
{
248221
try {
249-
$this->setResult(self::getSoapClient()->UpdateBulkOrder($parameters));
222+
$this->setResult($this->getSoapClient()->UpdateBulkOrder($parameters));
250223
return $this->getResult();
251224
} catch (\SoapFault $soapFault) {
252225
$this->saveLastError(__METHOD__, $soapFault);
@@ -258,10 +231,10 @@ class ApiUpdate extends AbstractSoapClientBase
258231
You can do:
259232
```php
260233
use \WsdlToPhp\PackageBase\AbstractSoapClientBase;
261-
$options = array(
234+
$options = [
262235
AbstractSoapClientBase::WSDL_URL => '__WSDL_URL__',
263236
AbstractSoapClientBase::WSDL_CLASSMAP => \Api\ApiClassMap::classMap(),
264-
);
237+
];
265238
// sets the first instance of SoapClient within AbstractSoapClientBase
266239
$update = new \Api\ServiceType\ApiUpdate($options);
267240
// 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 of [AbstractStructArrayBase](/src/AbstractStructArrayBase.php) 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, it's done automatically.

src/AbstractStructArrayBase.php

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,28 @@ abstract class AbstractStructArrayBase extends AbstractStructBase implements Str
1010
* Array that contains values when only one parameter is set when calling __construct method
1111
* @var array
1212
*/
13-
protected array $internArray = [];
13+
private array $internArray = [];
1414

1515
/**
1616
* Bool that tells if array is set or not
1717
* @var bool
1818
*/
19-
protected bool $internArrayIsArray = false;
19+
private bool $internArrayIsArray = false;
2020

2121
/**
2222
* Items index browser
2323
* @var int
2424
*/
25-
protected int $internArrayOffset = 0;
25+
private int $internArrayOffset = 0;
2626

2727
/**
2828
* Method alias to count
2929
* @return int
3030
*/
3131
public function length(): int
3232
{
33+
$this->initInternArray();
34+
3335
return $this->count();
3436
}
3537

@@ -39,6 +41,8 @@ public function length(): int
3941
*/
4042
public function count(): int
4143
{
44+
$this->initInternArray();
45+
4246
return $this->getInternArrayIsArray() ? count($this->getInternArray()) : -1;
4347
}
4448

@@ -48,6 +52,8 @@ public function count(): int
4852
*/
4953
public function current()
5054
{
55+
$this->initInternArray();
56+
5157
return $this->offsetGet($this->internArrayOffset);
5258
}
5359

@@ -57,6 +63,8 @@ public function current()
5763
*/
5864
public function next(): self
5965
{
66+
$this->initInternArray();
67+
6068
return $this->setInternArrayOffset($this->getInternArrayOffset() + 1);
6169
}
6270

@@ -66,6 +74,8 @@ public function next(): self
6674
*/
6775
public function rewind(): self
6876
{
77+
$this->initInternArray();
78+
6979
return $this->setInternArrayOffset(0);
7080
}
7181

@@ -75,6 +85,8 @@ public function rewind(): self
7585
*/
7686
public function valid(): bool
7787
{
88+
$this->initInternArray();
89+
7890
return $this->offsetExists($this->getInternArrayOffset());
7991
}
8092

@@ -84,6 +96,8 @@ public function valid(): bool
8496
*/
8597
public function key(): int
8698
{
99+
$this->initInternArray();
100+
87101
return $this->getInternArrayOffset();
88102
}
89103

@@ -94,6 +108,8 @@ public function key(): int
94108
*/
95109
public function item($index)
96110
{
111+
$this->initInternArray();
112+
97113
return $this->offsetGet($index);
98114
}
99115

@@ -127,6 +143,8 @@ public function add($item): self
127143
*/
128144
public function first()
129145
{
146+
$this->initInternArray();
147+
130148
return $this->item(0);
131149
}
132150

@@ -136,6 +154,8 @@ public function first()
136154
*/
137155
public function last()
138156
{
157+
$this->initInternArray();
158+
139159
return $this->item($this->length() - 1);
140160
}
141161

@@ -146,6 +166,8 @@ public function last()
146166
*/
147167
public function offsetExists($offset): bool
148168
{
169+
$this->initInternArray();
170+
149171
return ($this->getInternArrayIsArray() && array_key_exists($offset, $this->getInternArray()));
150172
}
151173

@@ -156,6 +178,8 @@ public function offsetExists($offset): bool
156178
*/
157179
public function offsetGet($offset)
158180
{
181+
$this->initInternArray();
182+
159183
return $this->offsetExists($offset) ? $this->internArray[$offset] : null;
160184
}
161185

@@ -167,6 +191,8 @@ public function offsetGet($offset)
167191
*/
168192
public function offsetSet($offset, $value): self
169193
{
194+
$this->initInternArray();
195+
170196
$this->internArray[$offset] = $value;
171197

172198
return $this->setPropertyValue($this->getAttributeName(), $this->internArray);
@@ -179,6 +205,8 @@ public function offsetSet($offset, $value): self
179205
*/
180206
public function offsetUnset($offset): self
181207
{
208+
$this->initInternArray();
209+
182210
if ($this->offsetExists($offset)) {
183211
unset($this->internArray[$offset]);
184212
$this->setPropertyValue($this->getAttributeName(), $this->internArray);
@@ -191,7 +219,7 @@ public function offsetUnset($offset): self
191219
* Method returning intern array to iterate trough
192220
* @return array
193221
*/
194-
public function getInternArray(): array
222+
private function getInternArray(): array
195223
{
196224
@trigger_error(sprintf('%s() will be private in WsdlToPhp/PackageBase 5.0.', __METHOD__), E_USER_DEPRECATED);
197225

@@ -203,7 +231,7 @@ public function getInternArray(): array
203231
* @param array $internArray
204232
* @return AbstractStructArrayBase
205233
*/
206-
public function setInternArray(array $internArray): self
234+
private function setInternArray(array $internArray): self
207235
{
208236
@trigger_error(sprintf('%s() will be private in WsdlToPhp/PackageBase 5.0.', __METHOD__), E_USER_DEPRECATED);
209237

@@ -216,7 +244,7 @@ public function setInternArray(array $internArray): self
216244
* Method returns intern array index when iterating trough
217245
* @return int
218246
*/
219-
public function getInternArrayOffset(): int
247+
private function getInternArrayOffset(): int
220248
{
221249
@trigger_error(sprintf('%s() will be private in WsdlToPhp/PackageBase 5.0.', __METHOD__), E_USER_DEPRECATED);
222250

@@ -229,7 +257,7 @@ public function getInternArrayOffset(): int
229257
* @param bool $internCall indicates that methods is calling itself
230258
* @return AbstractStructArrayBase
231259
*/
232-
public function initInternArray(array $array = [], bool $internCall = false): self
260+
private function initInternArray(array $array = [], bool $internCall = false): self
233261
{
234262
@trigger_error(sprintf('%s() will be private in WsdlToPhp/PackageBase 5.0.', __METHOD__), E_USER_DEPRECATED);
235263

@@ -238,7 +266,7 @@ public function initInternArray(array $array = [], bool $internCall = false): se
238266
->setInternArray($array)
239267
->setInternArrayOffset(0)
240268
->setInternArrayIsArray(true);
241-
} elseif (!$internCall && property_exists($this, $this->getAttributeName())) {
269+
} elseif (!$this->internArrayIsArray && !$internCall && property_exists($this, $this->getAttributeName())) {
242270
$this->initInternArray($this->getPropertyValue($this->getAttributeName()), true);
243271
}
244272

@@ -250,7 +278,7 @@ public function initInternArray(array $array = [], bool $internCall = false): se
250278
* @param int $internArrayOffset
251279
* @return AbstractStructArrayBase
252280
*/
253-
public function setInternArrayOffset(int $internArrayOffset): self
281+
private function setInternArrayOffset(int $internArrayOffset): self
254282
{
255283
@trigger_error(sprintf('%s() will be private in WsdlToPhp/PackageBase 5.0.', __METHOD__), E_USER_DEPRECATED);
256284

@@ -263,7 +291,7 @@ public function setInternArrayOffset(int $internArrayOffset): self
263291
* Method returning true if intern array is an actual array
264292
* @return bool
265293
*/
266-
public function getInternArrayIsArray(): bool
294+
private function getInternArrayIsArray(): bool
267295
{
268296
@trigger_error(sprintf('%s() will be private in WsdlToPhp/PackageBase 5.0.', __METHOD__), E_USER_DEPRECATED);
269297

@@ -275,7 +303,7 @@ public function getInternArrayIsArray(): bool
275303
* @param bool $internArrayIsArray
276304
* @return AbstractStructArrayBase
277305
*/
278-
public function setInternArrayIsArray(bool $internArrayIsArray = false): self
306+
private function setInternArrayIsArray(bool $internArrayIsArray = false): self
279307
{
280308
@trigger_error(sprintf('%s() will be private in WsdlToPhp/PackageBase 5.0.', __METHOD__), E_USER_DEPRECATED);
281309

0 commit comments

Comments
 (0)