Skip to content

Commit 2c36a0c

Browse files
committed
issue #13 - use short array notation, implement jsonSerialize method
1 parent 9dcd9be commit 2c36a0c

File tree

5 files changed

+35
-16
lines changed

5 files changed

+35
-16
lines changed

src/AbstractSoapClientBase.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ abstract class AbstractSoapClientBase implements SoapClientInterface
2626
* @param array $wsdlOptions
2727
* @param bool $resetSoapClient allows to disable the SoapClient redefinition
2828
*/
29-
public function __construct(array $wsdlOptions = array(), $resetSoapClient = true)
29+
public function __construct(array $wsdlOptions = [], $resetSoapClient = true)
3030
{
31-
$this->setLastError(array());
31+
$this->setLastError([]);
3232
/**
3333
* Init soap Client
3434
* Set default values
@@ -65,7 +65,7 @@ public static function setSoapClient(\SoapClient $soapClient)
6565
*/
6666
public function initSoapClient(array $options)
6767
{
68-
$wsdlOptions = array();
68+
$wsdlOptions = [];
6969
$defaultWsdlOptions = static::getDefaultWsdlOptions();
7070
foreach ($defaultWsdlOptions as $optionName => $optionValue) {
7171
if (array_key_exists($optionName, $options) && !empty($options[$optionName])) {
@@ -131,7 +131,7 @@ public function getSoapClientClassName($soapClientClassName = null)
131131
*/
132132
public static function getDefaultWsdlOptions()
133133
{
134-
return array(
134+
return [
135135
self::WSDL_CLASSMAP => null,
136136
self::WSDL_CACHE_WSDL => WSDL_CACHE_NONE,
137137
self::WSDL_COMPRESSION => null,
@@ -156,7 +156,7 @@ public static function getDefaultWsdlOptions()
156156
self::WSDL_PASSPHRASE => null,
157157
self::WSDL_AUTHENTICATION => null,
158158
self::WSDL_SSL_METHOD => null,
159-
);
159+
];
160160
}
161161
/**
162162
* Allows to set the SoapClient location to call
@@ -270,7 +270,7 @@ public static function getFormatedXml($string, $asDomDocument = false)
270270
public static function convertStringHeadersToArray($headers)
271271
{
272272
$lines = explode("\r\n", $headers);
273-
$headers = array();
273+
$headers = [];
274274
foreach ($lines as $line) {
275275
if (strpos($line, ':')) {
276276
$headerParts = explode(':', $line);
@@ -294,7 +294,7 @@ public static function convertStringHeadersToArray($headers)
294294
public function setSoapHeader($nameSpace, $name, $data, $mustUnderstand = false, $actor = null)
295295
{
296296
if (static::getSoapClient()) {
297-
$defaultHeaders = (isset(static::getSoapClient()->__default_headers) && is_array(static::getSoapClient()->__default_headers)) ? static::getSoapClient()->__default_headers : array();
297+
$defaultHeaders = (isset(static::getSoapClient()->__default_headers) && is_array(static::getSoapClient()->__default_headers)) ? static::getSoapClient()->__default_headers : [];
298298
foreach ($defaultHeaders as $index => $soapHeader) {
299299
if ($soapHeader->name === $name) {
300300
unset($defaultHeaders[$index]);
@@ -326,13 +326,13 @@ public function setHttpHeader($headerName, $headerValue)
326326
if (static::getSoapClient() && !empty($headerName)) {
327327
$streamContext = $this->getStreamContext();
328328
if ($streamContext === null) {
329-
$options = array();
330-
$options['http'] = array();
329+
$options = [];
330+
$options['http'] = [];
331331
$options['http']['header'] = '';
332332
} else {
333333
$options = stream_context_get_options($streamContext);
334334
if (!array_key_exists('http', $options) || !is_array($options['http'])) {
335-
$options['http'] = array();
335+
$options['http'] = [];
336336
$options['http']['header'] = '';
337337
} elseif (!array_key_exists('header', $options['http'])) {
338338
$options['http']['header'] = '';
@@ -343,7 +343,7 @@ public function setHttpHeader($headerName, $headerValue)
343343
/**
344344
* Ensure there is only one header entry for this header name
345345
*/
346-
$newLines = array();
346+
$newLines = [];
347347
foreach ($lines as $line) {
348348
if (!empty($line) && strpos($line, $headerName) === false) {
349349
array_push($newLines, $line);
@@ -386,7 +386,7 @@ public function getStreamContext()
386386
*/
387387
public function getStreamContextOptions()
388388
{
389-
$options = array();
389+
$options = [];
390390
$context = $this->getStreamContext();
391391
if ($context !== null) {
392392
$options = stream_context_get_options($context);

src/AbstractStructArrayBase.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public function add($item)
115115
* init array
116116
*/
117117
if (!is_array($this->_get($this->getAttributeName()))) {
118-
$this->_set($this->getAttributeName(), array());
118+
$this->_set($this->getAttributeName(), []);
119119
}
120120
/**
121121
* current array
@@ -232,7 +232,7 @@ public function getInternArrayOffset()
232232
* @param bool $internCall indicates that methods is calling itself
233233
* @return AbstractStructArrayBase
234234
*/
235-
public function initInternArray($array = array(), $internCall = false)
235+
public function initInternArray($array = [], $internCall = false)
236236
{
237237
if (stripos(get_called_class(), 'array') !== false) {
238238
if (is_array($array) && count($array) > 0) {

src/AbstractStructBase.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,16 @@
22

33
namespace WsdlToPhp\PackageBase;
44

5-
abstract class AbstractStructBase implements StructInterface
5+
abstract class AbstractStructBase implements StructInterface, \JsonSerializable
66
{
7+
/**
8+
* Returns the properties of this object
9+
* @return mixed[]
10+
*/
11+
public function jsonSerialize()
12+
{
13+
return \get_object_vars($this);
14+
}
715
/**
816
* Generic method called when an object has been exported with var_export() functions
917
* It allows to return an object instantiated with the values

src/SoapClientInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ interface SoapClientInterface
144144
* @param array $wsdlOptions
145145
* @param bool $resetSoapClient allows to disable the SoapClient redefinition
146146
*/
147-
public function __construct(array $wsdlOptions = array(), $resetSoapClient = true);
147+
public function __construct(array $wsdlOptions = [], $resetSoapClient = true);
148148
/**
149149
* Static method getting current SoapClient
150150
* @return \SoapClient

tests/StructBaseTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,15 @@ public function testSetGetWithException()
5151
->setFoo('bar');
5252
$object->_get('sample');
5353
}
54+
public function testJsonSerialize()
55+
{
56+
$object = new StructObject();
57+
$object
58+
->setBar('foo')
59+
->setFoo('bar');
60+
$this->assertSame([
61+
'foo' => 'bar',
62+
'bar' => 'foo',
63+
], $object->jsonSerialize());
64+
}
5465
}

0 commit comments

Comments
 (0)