Skip to content

Commit

Permalink
Fix for #4: Support for custom \SoapClient options in SessionHandlerP…
Browse files Browse the repository at this point in the history
…arams
  • Loading branch information
DerMika committed Apr 26, 2016
1 parent 2d0ed2d commit 55cd02f
Show file tree
Hide file tree
Showing 10 changed files with 138 additions and 9 deletions.
14 changes: 7 additions & 7 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ filter:
checks:
php: true
coding_style:
php:
indentation:
general:
size: 1
php:
indentation:
general:
size: 1
build: true
environment:
php:
version: 5.6
environment:
php:
version: 5.6
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# 2016-04

Added support for providing custom `\SoapClient` options (https://github.com/amabnl/amadeus-ws-client/issues/4)
Implemented Amadeus SoapHeader 2 support (https://github.com/amabnl/amadeus-ws-client/issues/3)
Changed all references 'tatoo' to 'tattoo' for consistency (https://github.com/amabnl/amadeus-ws-client/issues/1)

# UNSTABLE

The library's API will be unstable until we release version 0.1.
33 changes: 32 additions & 1 deletion docs/samples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ You can restore a previous current session after you retrieved it from your sess
$client->setSessionData($previousSessionData);
*********************
Handling the response
*********************
Expand Down Expand Up @@ -124,6 +123,38 @@ We try to ease your pain a little by analyzing the messages we support and look

To override this behaviour, look at the ``Amadeus\Client\ResponseHandler\ResponseHandlerInterface``.

**************************
Custom \SoapClient options
**************************

You can override the default ``\SoapClient`` options by passing them in the Session Handler Params:

.. code-block:: php
$params = new Params([
'sessionHandlerParams' => [
'soapHeaderVersion' => Client::HEADER_V4, //This is the default value, can be omitted.
'wsdl' => '/home/user/mytestproject/data/amadeuswsdl/1ASIWXXXXXX_PDT_20160101_080000.wsdl', //Points to the location of the WSDL file for your WSAP. Make sure the associated XSD's are also available.
'stateful' => false, //Enable stateful messages by default - can be changed at will to switch between stateless & stateful.
'logger' => new Psr\Log\NullLogger(),
'soapClientOptions' => [
'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP
]
'authParams' => [
'officeId' => 'BRUXX1111', //The Amadeus Office Id you want to sign in to - must be open on your WSAP.
'userId' => 'WSBENXXX', //Also known as 'Originator' for Soap Header 1 & 2 WSDL's
'passwordData' => 'dGhlIHBhc3N3b3Jk' // **base 64 encoded** password
]
],
'requestCreatorParams' => [
'receivedFrom' => 'my test project' // The "Received From" string that will be visible in PNR History
]
]);
\SoapClient options provided as such will override the default settings defined in
``Amadeus\Client\Session\Handler\Base::$soapClientOptions`` and must be provided in the correct
format as specified in the PHP manual: http://php.net/manual/en/soapclient.soapclient.php

***
PNR
***
Expand Down
14 changes: 14 additions & 0 deletions src/Amadeus/Client/Params/SessionHandlerParams.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,17 @@ class SessionHandlerParams
*/
public $logger;

/**
* Override the default \SoapClient options
*
* used when constructing \SoapClient
*
* See Amadeus\Client\Session\Handler\Base::$soapClientOptions for defaults
*
* @var array
*/
public $soapClientOptions = [];

/**
* Overridden soap client
*
Expand Down Expand Up @@ -108,6 +119,9 @@ protected function loadFromArray(array $params) {
if (isset($params['overrideSoapClient']) && $params['overrideSoapClient'] instanceof \SoapClient) {
$this->overrideSoapClient = $params['overrideSoapClient'];
}
if (isset($params['soapClientOptions']) && is_array($params['soapClientOptions'])) {
$this->soapClientOptions = $params['soapClientOptions'];
}
}
}
}
5 changes: 4 additions & 1 deletion src/Amadeus/Client/Session/Handler/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,10 @@ abstract class Base implements HandlerInterface, LoggerAwareInterface


/**
* SoapClient options used during initialisation
* Default SoapClient options used during initialisation
*
* Can be overridden by providing custom options in
* Amadeus\Client\Params\SessionHandlerParams::$soapClientOptions
*
* @var array
*/
Expand Down
4 changes: 4 additions & 0 deletions src/Amadeus/Client/Session/Handler/SoapHeader2.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ protected function makeSoapClientOptions()
$options = $this->soapClientOptions;
$options['classmap'] = array_merge(Classmap::$soapheader2map, Classmap::$map);

if (!empty($this->params->soapClientOptions)) {
$options = array_merge($options, $this->params->soapClientOptions);
}

return $options;
}
}
4 changes: 4 additions & 0 deletions src/Amadeus/Client/Session/Handler/SoapHeader4.php
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,10 @@ protected function makeSoapClientOptions()
$options = $this->soapClientOptions;
$options['classmap'] = array_merge(Classmap::$soapheader4map, Classmap::$map);

if (!empty($this->params->soapClientOptions)) {
$options = array_merge($options, $this->params->soapClientOptions);
}

return $options;
}
}
23 changes: 23 additions & 0 deletions tests/Amadeus/Client/Params/SessionHandlerParamsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,27 @@ public function testCanMakeSessionHandlerParamsWithoutLogger()
$this->assertEquals(Client::HEADER_V4,$par->soapHeaderVersion);
$this->assertNull($par->overrideSoapClient);
}

public function testCanMakeSessionHandlerParamsWithSoapClientOptions()
{
$par = new Params\SessionHandlerParams([
'wsdl' => realpath(dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . "testfiles" . DIRECTORY_SEPARATOR . "dummywsdl.wsdl"),
'stateful' => true,
'authParams' => new Params\AuthParams([
'officeId' => 'BRUXXXXXX',
'userId' => 'WSXXXXXX',
'passwordData' => base64_encode('TEST')
]),
'soapClientOptions' => [
'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP
]
]);

$this->assertInternalType('array', $par->soapClientOptions);
$this->assertNotEmpty($par->soapClientOptions);
$this->assertEquals(
SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP,
$par->soapClientOptions['compression']
);
}
}
21 changes: 21 additions & 0 deletions tests/Amadeus/Client/Session/Handler/SoapHeader2Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,27 @@ public function testGetLastRequestEmptyWithNoMessages()
$this->assertNull($result);
}

public function testCanMakeSoapClientOptionsWithOverrides()
{
$sessionHandlerParams = $this->makeSessionHandlerParams();
$sessionHandlerParams->soapClientOptions['compression'] = SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP;

$sessionHandler = new SoapHeader2($sessionHandlerParams);

$expected = [
'trace' => 1,
'exceptions' => 1,
'soap_version' => SOAP_1_1,
'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP,
'classmap' => Client\Session\Handler\Classmap::$soapheader2map
];

$meth = self::getMethod($sessionHandler, 'makeSoapClientOptions');
$result = $meth->invoke($sessionHandler);

$this->assertEquals($expected, $result);
}

/**
* @param \SoapClient|null $overrideSoapClient
* @return SessionHandlerParams
Expand Down
20 changes: 20 additions & 0 deletions tests/Amadeus/Client/Session/Handler/SoapHeader4Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,27 @@ public function testCanExtractMessagesAndVersions()
$actual = $sessionHandler->getMessagesAndVersions();

$this->assertEquals($expected, $actual);
}

public function testCanMakeSoapClientOptionsWithOverrides()
{
$sessionHandlerParams = $this->makeSessionHandlerParams();
$sessionHandlerParams->soapClientOptions['compression'] = SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP;

$sessionHandler = new SoapHeader4($sessionHandlerParams);

$expected = [
'trace' => 1,
'exceptions' => 1,
'soap_version' => SOAP_1_1,
'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP,
'classmap' => Client\Session\Handler\Classmap::$soapheader4map
];

$meth = self::getMethod($sessionHandler, 'makeSoapClientOptions');
$result = $meth->invoke($sessionHandler);

$this->assertEquals($expected, $result);
}

/**
Expand Down

0 comments on commit 55cd02f

Please sign in to comment.