Skip to content

Commit 36a5e92

Browse files
committed
Merge branch 'release/2.1.0'
2 parents cc57d91 + 598f108 commit 36a5e92

15 files changed

+210
-17
lines changed

.docker/Dockerfile

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
FROM php:7.2-apache
2-
3-
RUN apt-get update \
4-
&& apt-get install -y libxml2-dev git zip zlib1g \
5-
&& docker-php-ext-install soap
1+
FROM splitbrain/phpfarm:jessie
62

73
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
8-
COPY . /var/www/html
4+
COPY . /var/www/
95

10-
WORKDIR /var/www/html
6+
WORKDIR /var/www/

.travis.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,16 @@ sudo: false
55
matrix:
66
include:
77
- php: 5.4
8+
dist: trusty
89
- php: 5.5
10+
dist: trusty
911
- php: 5.6
12+
dist: trusty
1013
- php: 7.0
1114
- php: 7.1
1215
- php: 7.2
16+
- php: 7.3
17+
- php: 7.4
1318

1419
install:
1520
- composer install

CHANGELOG.md

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

3+
## 2.0.4 - 2020-05-14
4+
- Pull request #29 - Transform HTTP headers from stream context options to array
5+
- Update Travis CI PHP Matrix
6+
- Use better Docker configuration
7+
- Introduce StructEnumInterface and AbstractStructEnumBase from which generated Enum classes should inherit
8+
- Add __toString method to AbstractStructBase and AbstractSoapClientBase classes
9+
310
## 2.0.3 - 2019-01-10
411
- Issue #25 - Enhancement: Improve output from running php-cs-fixer
512
- Issue #26 - Enhancement: Keep packages sorted in composer.json

README.md

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,29 @@ For example, it allows to easily loop through the array elements of a SOAP resul
1616

1717
## Main features
1818
- [Interfaces](#the-interfaces)
19+
- [StructEnumInterface](#structenuminterface)
1920
- [StructInterface](#structinterface)
2021
- [StructArrayInterface](#structarrayinterface)
2122
- [SoapClientInterface](#soapclientinterface)
2223
- [Abstract classes](#the-abstract-classes)
24+
- [AbstractStructEnumBase](#abstractstructenumbase)
2325
- [AbstractStructBase](#abstractstructbase)
2426
- [AbstractStructArrayBase](#abstractstructarraybase)
2527
- [AbstractSoapClientBase](#abstractsoapclientbase)
2628

2729
## The interfaces
2830
The defined interfaces must be used in order to be able to match the requirements for the [PackageGenerator](https://github.com/WsdlToPhp/PackageGenerator) generated classes.
2931

32+
### StructEnumInterface
33+
#### Description
34+
This interface must be used to define a new EnumType class.
35+
36+
#### What has to be implemented?
37+
There is at least/most one method that must be implemented so it's pretty fast to implement it even if you don't see the goal of it:
38+
- **valueIsValid($value)**: this method must ensure that the passed `$value` is valid. This can be done using the array of string returned by the `getValidValues` method always present in the generated Enum classes.
39+
40+
**If you do not want to implement this method, you can too create your own class that inherits from our [AbstractStructEnumBase](#abstractstructenumbase) class.**
41+
3042
### StructInterface
3143
#### Description
3244
This interface must be used to define a new StructType class.
@@ -97,14 +109,24 @@ Here are the methods that must be implemented and why:
97109
**If you do not want to implement all these methods, you can too create your own class that inherits from our [AbstractSoapClientBase](#abstractsoapclientbase) class.**
98110

99111
## The abstract classes
112+
113+
### AbstractStructEnumBase
114+
#### Description
115+
This class is the base class for any ```EnumType``` class generated by [PackageGenerator](https://github.com/WsdlToPhp/PackageGenerator). It implements our [StructEnumInterface](#structenuminterface) interface.
116+
It defines two methods:
117+
- **valueIsValid($value)**: It defines the default behaviour in order to validate a value that must be based on the current EnumType class constants returned by the `getValidValues` method.
118+
- **__toString()**: see [__toString](http://php.net/manual/en/language.oop5.magic.php#object.tostring) definition
119+
120+
100121
### AbstractStructBase
101122
#### Description
102123
This class is the base class for any ```StructType``` class generated by [PackageGenerator](https://github.com/WsdlToPhp/PackageGenerator). It implements our [StructInterface](#structinterface) interface.
103-
It defines four methods:
124+
It defines five methods:
104125
- **__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.
105126
- **_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.
106127
- **_get($name)**: As magic method ```__get```. Used by our [AbstractStructArrayBase](#abstractstructarraybase) class.
107128
- **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.
129+
- **__toString()**: see [__toString](http://php.net/manual/en/language.oop5.magic.php#object.tostring) definition
108130

109131
#### Usage
110132
```php
@@ -283,10 +305,33 @@ public function setSoapHeaderCSPCHD(\Api\StructType\ApiCSPCHD $cSPCHD, $nameSpac
283305
## Need improvements for these classes?
284306
Feel free to make some pull requests. We'll study them and let you know when it can be integrated.
285307

286-
## Unit tests
308+
## Testing
287309
You can run the unit tests with the following command:
288310
```
289-
$ cd /path/to/src/WsdlToPhp/PackageBase/
290-
$ composer install
291-
$ composer test
311+
$ cd /path/to/src/WsdlToPhp/PackageBase/
312+
$ composer install
313+
$ composer test
314+
```
315+
316+
## Testing using [Docker](https://www.docker.com/)
317+
Thanks to the [Docker image](https://hub.docker.com/r/splitbrain/phpfarm) of [phpfarm](https://github.com/fpoirotte/phpfarm), tests can be run locally under *any* PHP version using the cli:
318+
- php-5.4
319+
- php-5.5
320+
- php-5.6
321+
- php-7.0
322+
- php-7.1
323+
- php-7.2
324+
- php-7.3
325+
326+
First of all, you need to create your container which you can do using [docker-compose](https://docs.docker.com/compose/) by running the below command line from the root directory of the project:
327+
```bash
328+
$ docker-compose up -d --build
329+
```
330+
331+
You then have a container named `package_base` in which you can run `composer` commands and `php cli` commands such as:
332+
```bash
333+
# install deps in container (using update ensure it does use the composer.lock file if there is any)
334+
$ docker exec -it package_base php-7.2 /usr/bin/composer update
335+
# run tests in container
336+
$ docker exec -it package_base php-7.2 -dmemory_limit=-1 vendor/bin/phpunit
292337
```

composer.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@
3434
{
3535
"name": "hordijk",
3636
"role": "Contributor"
37+
},
38+
{
39+
"name": "Jacob Dreesen",
40+
"email": "[email protected]",
41+
"role": "Contributor"
3742
}
3843
],
3944
"support" : {

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ services:
66
context: .
77
dockerfile: .docker/Dockerfile
88
volumes:
9-
- .:/var/www/html:rw
9+
- .:/var/www:rw
1010
container_name: package_base

src/AbstractSoapClientBase.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,9 @@ public function getStreamContextOptions()
416416
$context = $this->getStreamContext();
417417
if ($context !== null) {
418418
$options = stream_context_get_options($context);
419+
if (isset($options['http']['header']) && is_string($options['http']['header'])) {
420+
$options['http']['header'] = array_filter(array_map('trim', explode(PHP_EOL, $options['http']['header'])));
421+
}
419422
}
420423
return $options;
421424
}
@@ -475,4 +478,12 @@ public function setResult($result)
475478
$this->result = $result;
476479
return $this;
477480
}
481+
/**
482+
* Default string representation of current object. Don't want to expose any sensible data
483+
* @return string
484+
*/
485+
public function __toString()
486+
{
487+
return get_called_class();
488+
}
478489
}

src/AbstractStructBase.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public function jsonSerialize()
1717
* It allows to return an object instantiated with the values
1818
* @uses AbstractStructBase::_set()
1919
* @param array $array the exported values
20-
* @return Struct
20+
* @return self
2121
*/
2222
public static function __set_state(array $array)
2323
{
@@ -33,7 +33,7 @@ public static function __set_state(array $array)
3333
* @throws \InvalidArgumentException
3434
* @param string $name property name to set
3535
* @param mixed $value property value to use
36-
* @return Struct
36+
* @return self
3737
*/
3838
public function _set($name, $value)
3939
{
@@ -59,4 +59,12 @@ public function _get($name)
5959
}
6060
throw new \InvalidArgumentException(sprintf('Getter does not exist for "%s" property', $name));
6161
}
62+
/**
63+
* Default string representation of current object. Don't want to expose any sensible data
64+
* @return string
65+
*/
66+
public function __toString()
67+
{
68+
return get_called_class();
69+
}
6270
}

src/AbstractStructEnumBase.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace WsdlToPhp\PackageBase;
4+
5+
abstract class AbstractStructEnumBase implements StructEnumInterface
6+
{
7+
/**
8+
* Return true if value is allowed
9+
* @uses self::getValidValues()
10+
* @param mixed $value value
11+
* @return bool true|false
12+
*/
13+
public static function valueIsValid($value)
14+
{
15+
return ($value === null) || in_array($value, static::getValidValues(), true);
16+
}
17+
/**
18+
* Default string representation of current object. Don't want to expose any sensible data
19+
* @return string
20+
*/
21+
public function __toString()
22+
{
23+
return get_called_class();
24+
}
25+
}

src/StructEnumInterface.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace WsdlToPhp\PackageBase;
4+
5+
interface StructEnumInterface
6+
{
7+
/**
8+
* Return true if value is allowed
9+
* @uses self::getValidValues()
10+
* @param mixed $value value
11+
* @return bool true|false
12+
*/
13+
public static function valueIsValid($value);
14+
/**
15+
* Return allowed values
16+
* @return string[]
17+
*/
18+
public static function getValidValues();
19+
}

0 commit comments

Comments
 (0)