Skip to content

Commit

Permalink
Merge branch 'release/5.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
mikaelcom committed Feb 5, 2021
2 parents 5eb27d0 + 72de482 commit 195c3bf
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 166 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## 5.0.0 - 2021/02/05
- Issue #13 - Auto initialize AbstractStructArrayBase::internArray
- BC: read [UPGRADE-5.0.md](/UPGRADE-5.0.md)

## 4.0.1 - 2021/02/05
- Add deprecation messages for next major release 5

Expand Down
73 changes: 23 additions & 50 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,12 @@ It defines five methods:

#### Usage
```php
$item = \Api\StructType\Item::__set_state(array(
$item = \Api\StructType\Item::__set_state([
'id' => 1,
'name' => 'Entity #1',
'label' => 'Entity #1',
'_href' => 'http://www.entity.com',
));
]);
// $item is now an \Api\StructType\Item object
```

Expand All @@ -147,87 +147,60 @@ This class is the base class for any ```ArrayType``` class generated by [Package
#### Usage
As soon as you have an element that is an array of items such as:
```php
$items = \Api\ArrayType\Items::__set_state(array(
'items' => array(
\Api\StructType\Item::__set_state(array(
$items = \Api\ArrayType\Items::__set_state([
'items' => [
\Api\StructType\Item::__set_state([
'id' => 1,
'name' => 'Entity #1',
'label' => 'Entity #1',
'_href' => 'http://www.entity-1.com',
),
\Api\StructType\Item::__set_state(array(
]),
\Api\StructType\Item::__set_state([
'id' => 2,
'name' => 'Entity #2',
'label' => 'Entity #2',
'_href' => 'http://www.entity-2.com',
),
\Api\StructType\Item::__set_state(array(
]),
\Api\StructType\Item::__set_state([
'id' => 3,
'name' => 'Entity #3',
'label' => 'Entity #3',
'_href' => 'http://www.entity-3.com',
),
)
));
]),
],
]);
// 'items' is the unique property of the object
// Its name is returned by the getAttributeName method
// defined in the generated \Api\ArrayType\Items class
```
- **You MUST call first** ```initInternArray``` method on your ArrayType object otherwise you'll get nothing working for the implemented methods:
```php
$items->initInternArray();
```
- then you can call ```count```, ```length``` methods: gives you the number of items contained by your object
- you can iterate through the items:
- **You can call ```count```, ```length``` methods: gives you the number of items contained by your object
- You can iterate through the items:
```php
foreach ($items as $item) {
// $items->current() and $item is an \Api\StructType\Item object
// $items->key() is the current index
}
```
- you can get the first item:
- You can get the first item:
```php
$items->first();
```
- you can get the last item:
- You can get the last item:
```php
$items->last();
```
- you can get any item:
- You can get any item:
```php
$items->item($index);
```
- you can add a new item:
- You can add a new item:
```php
$items->add(\Api\StructType\Item::__set_state(array(
$items->add(\Api\StructType\Item::__set_state([
'id' => 4,
'name' => 'Entity #4',
'label' => 'Entity #4',
'_href' => 'http://www.entity-4.com',
)));
```
- you can even reset the items:
```php
$items->initInternArray(array(
\Api\StructType\Item::__set_state(array(
'id' => 0,
'name' => 'Entity #0',
'label' => 'Entity #0',
'_href' => 'http://www.entity-0.com',
),
\Api\StructType\Item::__set_state(array(
'id' => 1,
'name' => 'Entity #1',
'label' => 'Entity #1',
'_href' => 'http://www.entity-1.com',
),
\Api\StructType\Item::__set_state(array(
'id' => 2,
'name' => 'Entity #2',
'label' => 'Entity #2',
'_href' => 'http://www.entity-2.com',
),
));
]));
```

### AbstractSoapClientBase
Expand All @@ -246,7 +219,7 @@ class ApiUpdate extends AbstractSoapClientBase
public function UpdateBulkOrder(\Api\StructType\ApiUpdateBulkOrder $parameters)
{
try {
$this->setResult(self::getSoapClient()->UpdateBulkOrder($parameters));
$this->setResult($this->getSoapClient()->UpdateBulkOrder($parameters));
return $this->getResult();
} catch (\SoapFault $soapFault) {
$this->saveLastError(__METHOD__, $soapFault);
Expand All @@ -258,10 +231,10 @@ class ApiUpdate extends AbstractSoapClientBase
You can do:
```php
use \WsdlToPhp\PackageBase\AbstractSoapClientBase;
$options = array(
$options = [
AbstractSoapClientBase::WSDL_URL => '__WSDL_URL__',
AbstractSoapClientBase::WSDL_CLASSMAP => \Api\ApiClassMap::classMap(),
);
];
// sets the first instance of SoapClient within AbstractSoapClientBase
$update = new \Api\ServiceType\ApiUpdate($options);
// resets the SoapClient instance
Expand Down
2 changes: 1 addition & 1 deletion UPGRADE-4.0.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# UPGRADE FROM 3.0 to 4.0

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

**Previously**:
```php
Expand Down
17 changes: 17 additions & 0 deletions UPGRADE-5.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# UPGRADE FROM 4.0 to 5.0

Internal properties and methods of [AbstractStructArrayBase](/src/AbstractStructArrayBase.php) are now private:
- Properties:
- $internArray
- $internArrayIsArray
- $internArrayOffset
- Methods:
- getInternArray
- setInternArray
- getInternArrayOffset
- initInternArray
- setInternArrayOffset
- getInternArrayIsArray
- setInternArrayIsArray

You don't have to manually call `initInternArray` before looping on the current object, it's done automatically.
50 changes: 39 additions & 11 deletions src/AbstractStructArrayBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,28 @@ abstract class AbstractStructArrayBase extends AbstractStructBase implements Str
* Array that contains values when only one parameter is set when calling __construct method
* @var array
*/
protected array $internArray = [];
private array $internArray = [];

/**
* Bool that tells if array is set or not
* @var bool
*/
protected bool $internArrayIsArray = false;
private bool $internArrayIsArray = false;

/**
* Items index browser
* @var int
*/
protected int $internArrayOffset = 0;
private int $internArrayOffset = 0;

/**
* Method alias to count
* @return int
*/
public function length(): int
{
$this->initInternArray();

return $this->count();
}

Expand All @@ -39,6 +41,8 @@ public function length(): int
*/
public function count(): int
{
$this->initInternArray();

return $this->getInternArrayIsArray() ? count($this->getInternArray()) : -1;
}

Expand All @@ -48,6 +52,8 @@ public function count(): int
*/
public function current()
{
$this->initInternArray();

return $this->offsetGet($this->internArrayOffset);
}

Expand All @@ -57,6 +63,8 @@ public function current()
*/
public function next(): self
{
$this->initInternArray();

return $this->setInternArrayOffset($this->getInternArrayOffset() + 1);
}

Expand All @@ -66,6 +74,8 @@ public function next(): self
*/
public function rewind(): self
{
$this->initInternArray();

return $this->setInternArrayOffset(0);
}

Expand All @@ -75,6 +85,8 @@ public function rewind(): self
*/
public function valid(): bool
{
$this->initInternArray();

return $this->offsetExists($this->getInternArrayOffset());
}

Expand All @@ -84,6 +96,8 @@ public function valid(): bool
*/
public function key(): int
{
$this->initInternArray();

return $this->getInternArrayOffset();
}

Expand All @@ -94,6 +108,8 @@ public function key(): int
*/
public function item($index)
{
$this->initInternArray();

return $this->offsetGet($index);
}

Expand Down Expand Up @@ -127,6 +143,8 @@ public function add($item): self
*/
public function first()
{
$this->initInternArray();

return $this->item(0);
}

Expand All @@ -136,6 +154,8 @@ public function first()
*/
public function last()
{
$this->initInternArray();

return $this->item($this->length() - 1);
}

Expand All @@ -146,6 +166,8 @@ public function last()
*/
public function offsetExists($offset): bool
{
$this->initInternArray();

return ($this->getInternArrayIsArray() && array_key_exists($offset, $this->getInternArray()));
}

Expand All @@ -156,6 +178,8 @@ public function offsetExists($offset): bool
*/
public function offsetGet($offset)
{
$this->initInternArray();

return $this->offsetExists($offset) ? $this->internArray[$offset] : null;
}

Expand All @@ -167,6 +191,8 @@ public function offsetGet($offset)
*/
public function offsetSet($offset, $value): self
{
$this->initInternArray();

$this->internArray[$offset] = $value;

return $this->setPropertyValue($this->getAttributeName(), $this->internArray);
Expand All @@ -179,6 +205,8 @@ public function offsetSet($offset, $value): self
*/
public function offsetUnset($offset): self
{
$this->initInternArray();

if ($this->offsetExists($offset)) {
unset($this->internArray[$offset]);
$this->setPropertyValue($this->getAttributeName(), $this->internArray);
Expand All @@ -191,7 +219,7 @@ public function offsetUnset($offset): self
* Method returning intern array to iterate trough
* @return array
*/
public function getInternArray(): array
private function getInternArray(): array
{
@trigger_error(sprintf('%s() will be private in WsdlToPhp/PackageBase 5.0.', __METHOD__), E_USER_DEPRECATED);

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

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

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

Expand All @@ -238,7 +266,7 @@ public function initInternArray(array $array = [], bool $internCall = false): se
->setInternArray($array)
->setInternArrayOffset(0)
->setInternArrayIsArray(true);
} elseif (!$internCall && property_exists($this, $this->getAttributeName())) {
} elseif (!$this->internArrayIsArray && !$internCall && property_exists($this, $this->getAttributeName())) {
$this->initInternArray($this->getPropertyValue($this->getAttributeName()), true);
}

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

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

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

Expand Down
Loading

0 comments on commit 195c3bf

Please sign in to comment.