Skip to content

Commit d983f71

Browse files
committed
Merge branch 'release/4.0.0'
2 parents 9e93bd3 + 7e48f3d commit d983f71

File tree

6 files changed

+56
-25
lines changed

6 files changed

+56
-25
lines changed

CHANGELOG.md

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
# CHANGELOG
22

3-
## 3.0.1 - 2021-01-28
3+
## 4.0.0 - 2021/02/03
4+
- BC:
5+
- `WsdlToPhp\PackageBase\AbstractStructBase::_set` has been renamed to `WsdlToPhp\PackageBase\AbstractStructBase::setPropertyValue`
6+
- `WsdlToPhp\PackageBase\AbstractStructBase::_set` has been renamed to `WsdlToPhp\PackageBase\AbstractStructBase::getPropertyValue`
7+
- Improve `WsdlToPhp\PackageBase\AbstractStructBase::__set_state` method using `ReflectionClass`
8+
- Review .php_cs settings, apply PHP CS Fixer
9+
10+
## 3.0.1 - 2021/01/28
411
- Update Travis CI badge and settings
512

6-
## 3.0.0 - 2021-01-28
7-
- Issue #32 - Migrate to PHp >= 7.4
13+
## 3.0.0 - 2021/01/28
14+
- Issue #32 - Migrate to PHP >= 7.4
815
- use `splitbrain/phpfarm:jessie` as Docker image and fix docker image settings
916
- Code requires PHP >= 7.4
1017
- Code cleaning
@@ -17,30 +24,30 @@
1724
- Update LICENSE file
1825
- Version 1.0 is no more maintained
1926

20-
## 2.2.0 - 2020-09-11
27+
## 2.2.0 - 2020/09/11
2128
- Issue #31 - Add output headers to SoapClient in order to be able to store them
2229

23-
## 2.1.0 - 2020-05-14
30+
## 2.1.0 - 2020/05/14
2431
- Pull request #29 - Transform HTTP headers from stream context options to array
2532
- Update Travis CI PHP Matrix
2633
- Use better Docker configuration
2734
- Introduce StructEnumInterface and AbstractStructEnumBase from which generated Enum classes should inherit
2835
- Add __toString method to AbstractStructBase and AbstractSoapClientBase classes
2936

30-
## 2.0.3 - 2019-01-10
37+
## 2.0.3 - 2019/01/10
3138
- Issue #25 - Enhancement: Improve output from running php-cs-fixer
3239
- Issue #26 - Enhancement: Keep packages sorted in composer.json
3340
- Issue #28 - Add the URI as an option in the soapClient parameters
3441

3542

36-
## 2.0.2 - 2018-07-23
43+
## 2.0.2 - 2018/07/23
3744
- Issue #22 / Pull request #23 - Add support to invoke getLastRequest without throwing an InvalidArgumentException if the request is not executed
3845

39-
## 2.0.1 - 2018-05-08
46+
## 2.0.1 - 2018/05/08
4047
- Issue #19 - WSDL_CACHE_WSDL does not work!
4148
- Code reviewed as it was not complete, default options were not taken into account properly too, it's working right from now on!
4249

43-
## 2.0.0 - 2018-04-17
50+
## 2.0.0 - 2018/04/17
4451
- Issue #15 - AbstractSoapClientBase should not define static SoapClient instance
4552

4653
## 1.0.11

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ It defines two methods:
124124
This class is the base class for any ```StructType``` class generated by [PackageGenerator](https://github.com/WsdlToPhp/PackageGenerator). It implements our [StructInterface](#structinterface) interface.
125125
It defines five methods:
126126
- **__set_state($array)**: Useful when you load the string representation of an object that you stored using ```var_export```. It also allows you to ease the instanciation of an object that contains many properties which would be hard to instanciate using the ```__construct``` method. You can see ```__set_state``` as an hydratation method.
127-
- **_set($name, $value)**: As magic method ```__set``` but used by the ```__set_state``` method. Plus, defining ```__set``` method on used class by the classmap option for the [SoapClient](http://php.net/manual/en/class.soapclient.php) breaks the correct hydratation of your received objects.
128-
- **_get($name)**: As magic method ```__get```. Used by our [AbstractStructArrayBase](#abstractstructarraybase) class.
127+
- **setPropertyValue(string $name, $value)**: As magic method ```__set``` but used by the ```__set_state``` method. Plus, defining ```__set``` method on used class by the classmap option for the [SoapClient](http://php.net/manual/en/class.soapclient.php) breaks the correct hydratation of your received objects.
128+
- **getPropertyValue(string $name)**: As magic method ```__get```. Used by our [AbstractStructArrayBase](#abstractstructarraybase) class.
129129
- **jsonSerialize()**: by implementing the [\JsonSerializable](http://php.net/manual/en/class.jsonserializable.php) interface, it implements this method that allows to pass the object to the [json_encode](http://php.net/manual/en/function.json-encode.php) method so it will return the properties of the current object in an array.
130130
- **__toString()**: see [__toString](http://php.net/manual/en/language.oop5.magic.php#object.tostring) definition
131131

UPGRADE-4.0.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# UPGRADE FROM 3.0 to 4.0
2+
3+
The previsouly `_set` and `_get` methods are to be used internally and are not intended to be used externally, at your own risks ;)
4+
5+
**Previously**:
6+
```php
7+
/** @var WsdlToPhp\PackageBase\AbstractStructBase|WsdlToPhp\PackageBase\AbstractStructArrayBase $o */
8+
$o = new Struct();
9+
$o->_set('name', 'the name');
10+
$theName = $o->_get('name');
11+
```
12+
13+
Same remark as previously, methods are renamed and marked as internal from now on ;)
14+
15+
**Now**:
16+
```php
17+
/** @var WsdlToPhp\PackageBase\AbstractStructBase|WsdlToPhp\PackageBase\AbstractStructArrayBase $o */
18+
$o = new Struct();
19+
$o->setPropertyValue('name', 'the name');
20+
$theName = $o->getPropertyValue('name');
21+
```

src/AbstractStructArrayBase.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,15 @@ public function item($index)
105105
public function add($item): self
106106
{
107107
// init array
108-
if (!is_array($this->_get($this->getAttributeName()))) {
109-
$this->_set($this->getAttributeName(), []);
108+
if (!is_array($this->getPropertyValue($this->getAttributeName()))) {
109+
$this->setPropertyValue($this->getAttributeName(), []);
110110
}
111111

112112
// current array
113-
$currentArray = $this->_get($this->getAttributeName());
113+
$currentArray = $this->getPropertyValue($this->getAttributeName());
114114
$currentArray[] = $item;
115115
$this
116-
->_set($this->getAttributeName(), $currentArray)
116+
->setPropertyValue($this->getAttributeName(), $currentArray)
117117
->setInternArray($currentArray)
118118
->setInternArrayIsArray(true)
119119
->setInternArrayOffset(0);
@@ -169,7 +169,7 @@ public function offsetSet($offset, $value): self
169169
{
170170
$this->internArray[$offset] = $value;
171171

172-
return $this->_set($this->getAttributeName(), $this->internArray);
172+
return $this->setPropertyValue($this->getAttributeName(), $this->internArray);
173173
}
174174

175175
/**
@@ -181,7 +181,7 @@ public function offsetUnset($offset): self
181181
{
182182
if ($this->offsetExists($offset)) {
183183
unset($this->internArray[$offset]);
184-
$this->_set($this->getAttributeName(), $this->internArray);
184+
$this->setPropertyValue($this->getAttributeName(), $this->internArray);
185185
}
186186

187187
return $this;
@@ -231,7 +231,7 @@ public function initInternArray(array $array = [], bool $internCall = false): se
231231
->setInternArrayOffset(0)
232232
->setInternArrayIsArray(true);
233233
} elseif (!$internCall && property_exists($this, $this->getAttributeName())) {
234-
$this->initInternArray($this->_get($this->getAttributeName()), true);
234+
$this->initInternArray($this->getPropertyValue($this->getAttributeName()), true);
235235
}
236236

237237
return $this;

src/AbstractStructBase.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use InvalidArgumentException;
88
use JsonSerializable;
9+
use ReflectionClass;
910

1011
abstract class AbstractStructBase implements StructInterface, JsonSerializable
1112
{
@@ -26,10 +27,10 @@ public function jsonSerialize(): array
2627
*/
2728
public static function __set_state(array $array): StructInterface
2829
{
29-
$className = get_called_class();
30-
$object = new $className();
30+
$reflection = new ReflectionClass(get_called_class());
31+
$object = $reflection->newInstance();
3132
foreach ($array as $name => $value) {
32-
$object->_set($name, $value);
33+
$object->setPropertyValue($name, $value);
3334
}
3435

3536
return $object;
@@ -41,8 +42,9 @@ public static function __set_state(array $array): StructInterface
4142
* @param string $name property name to set
4243
* @param mixed $value property value to use
4344
* @return self
45+
* @internal
4446
*/
45-
public function _set(string $name, $value): self
47+
public function setPropertyValue(string $name, $value): self
4648
{
4749
$setMethod = 'set' . ucfirst($name);
4850
if (method_exists($this, $setMethod)) {
@@ -59,8 +61,9 @@ public function _set(string $name, $value): self
5961
* @throws InvalidArgumentException
6062
* @param string $name property name to get
6163
* @return mixed
64+
* @internal
6265
*/
63-
public function _get(string $name)
66+
public function getPropertyValue(string $name)
6467
{
6568
$getMethod = 'get' . ucfirst($name);
6669
if (method_exists($this, $getMethod)) {

tests/StructBaseTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function testSetGet()
3838
$object
3939
->setBar('foo')
4040
->setFoo('bar');
41-
$this->assertSame('foo', $object->_get('bar'));
41+
$this->assertSame('foo', $object->getPropertyValue('bar'));
4242
}
4343

4444
public function testSetGetWithException()
@@ -49,7 +49,7 @@ public function testSetGetWithException()
4949
$object
5050
->setBar('foo')
5151
->setFoo('bar');
52-
$object->_get('sample');
52+
$object->getPropertyValue('sample');
5353
}
5454

5555
public function testJsonSerialize()

0 commit comments

Comments
 (0)