Completed
Pull Request — master (#189)
by Dieter
10:43
created

SessionHandlerParams::loadOverrideSoapClient()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 8
cts 8
cp 1
rs 9.2
c 0
b 0
f 0
cc 4
eloc 5
nc 4
nop 1
crap 4
1
<?php
2
/**
3
 * amadeus-ws-client
4
 *
5
 * Copyright 2015 Amadeus Benelux NV
6
 *
7
 * Licensed under the Apache License, Version 2.0 (the "License");
8
 * you may not use this file except in compliance with the License.
9
 * You may obtain a copy of the License at
10
 *
11
 * http://www.apache.org/licenses/LICENSE-2.0
12
 *
13
 * Unless required by applicable law or agreed to in writing, software
14
 * distributed under the License is distributed on an "AS IS" BASIS,
15
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
 * See the License for the specific language governing permissions and
17
 * limitations under the License.
18
 *
19
 * @package Amadeus
20
 * @license https://opensource.org/licenses/Apache-2.0 Apache 2.0
21
 */
22
23
namespace Amadeus\Client\Params;
24
25
use Amadeus\Client;
26
use Psr\Log\LoggerInterface;
27
28
/**
29
 * SessionHandlerParams contains all parameters for setting up the session handler
30
 *
31
 * @package Amadeus\Client\Params
32
 * @author Dieter Devlieghere <[email protected]>
33
 */
34
class SessionHandlerParams
35
{
36
37
    /**
38
     * Full file & path to the WSDL file to be used
39
     *
40
     * @var string[]
41
     */
42
    public $wsdl = [];
43
44
    /**
45
     * Which Soap Header version to be used
46
     *
47
     * @var string
48
     */
49
    public $soapHeaderVersion = Client::HEADER_V4;
50
51
    /**
52
     * @var AuthParams
53
     */
54
    public $authParams;
55
56
    /**
57
     * The default setting for sending messages (if not specified)
58
     *
59
     * Set to FALSE to enable stateless messages - only applies to SOAP header v4 and higher!
60
     *
61
     * @var bool
62
     */
63
    public $stateful = true;
64
65
66
    /**
67
     * @var LoggerInterface
68
     */
69
    public $logger;
70
71
    /**
72
     * Override the default \SoapClient options
73
     *
74
     * used when constructing \SoapClient
75
     *
76
     * See Amadeus\Client\Session\Handler\Base::$soapClientOptions for defaults
77
     *
78
     * @var array
79
     */
80
    public $soapClientOptions = [];
81
82
    /**
83
     * Overridden soap client
84
     *
85
     * @var \SoapClient
86
     */
87
    public $overrideSoapClient;
88
89
    /**
90
     * Override SoapClient WSDL name
91
     *
92
     * @var string
93
     */
94
    public $overrideSoapClientWsdlName;
95
96
    /**
97
     * Enable the TransactionFlowLink SOAP Header?
98
     *
99
     * @var bool
100
     */
101
    public $enableTransactionFlowLink = false;
102
103
    /**
104
     * Consumer ID for Transaction Flow Link
105
     *
106
     * @var string|null
107
     */
108
    public $consumerId = null;
109
110
    /**
111
     * @param array $params
112
     */
113 288
    public function __construct($params = [])
114
    {
115 288
        $this->loadFromArray($params);
116 288
    }
117
118
    /**
119
     * Load parameters from an associative array
120
     *
121
     * @param array $params
122
     * @return void
123
     */
124 288
    protected function loadFromArray(array $params)
125
    {
126 288
        if (count($params) > 0) {
127 280
            if (isset($params['soapHeaderVersion'])) {
128 188
                $this->soapHeaderVersion = $params['soapHeaderVersion'];
129 94
            }
130
131 280
            $this->loadWsdl($params);
132 280
            $this->loadStateful($params);
133 280
            $this->loadLogger($params);
134
135 280
            $this->loadAuthParams($params);
136
137 280
            $this->loadOverrideSoapClient($params);
138 280
            $this->loadSoapClientOptions($params);
139
140 280
            $this->loadTransactionFlowLink($params);
141 140
        }
142 288
    }
143
144
    /**
145
     * Load WSDL from config
146
     *
147
     * Either a single WSDL location as string or a list of WSDL locations as array.
148
     *
149
     * @param array $params
150
     * @return void
151
     */
152 280 View Code Duplication
    protected function loadWsdl($params)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
153
    {
154 280
        if (isset($params['wsdl'])) {
155 276
            if (is_string($params['wsdl'])) {
156 256
                $this->wsdl = [
157 256
                    $params['wsdl']
158 128
                ];
159 148
            } elseif (is_array($params['wsdl'])) {
160 4
                $this->wsdl = $params['wsdl'];
161 2
            }
162 138
        }
163 280
    }
164
165
    /**
166
     * Load Stateful param from config
167
     *
168
     * @param array $params
169
     * @return void
170
     */
171 280
    protected function loadStateful($params)
172
    {
173 280
        $this->stateful = (isset($params['stateful'])) ? $params['stateful'] : true;
174 280
    }
175
176
177
    /**
178
     * Load Logger from config
179
     *
180
     * @param array $params
181
     * @return void
182
     */
183 280
    protected function loadLogger($params)
184
    {
185 280
        if ((isset($params['logger']) && $params['logger'] instanceof LoggerInterface)) {
186 264
            $this->logger = $params['logger'];
187 132
        }
188 280
    }
189
190
    /**
191
     * Load Authentication parameters from config
192
     *
193
     * @param array $params
194
     * @return void
195
     */
196 280 View Code Duplication
    protected function loadAuthParams($params)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
197
    {
198 280
        if (isset($params['authParams'])) {
199 260
            if ($params['authParams'] instanceof AuthParams) {
200 16
                $this->authParams = $params['authParams'];
201 252
            } elseif (is_array($params['authParams'])) {
202 244
                $this->authParams = new AuthParams($params['authParams']);
203 122
            }
204 130
        }
205 280
    }
206
207
    /**
208
     * Load Override SoapClient parameter from config
209
     *
210
     * @param array $params
211
     * @return void
212
     */
213 280
    protected function loadOverrideSoapClient($params)
214
    {
215 280
        if (isset($params['overrideSoapClient']) && $params['overrideSoapClient'] instanceof \SoapClient) {
216 8
            $this->overrideSoapClient = $params['overrideSoapClient'];
217 4
        }
218 280
        if (isset($params['overrideSoapClientWsdlName'])) {
219 44
            $this->overrideSoapClientWsdlName = $params['overrideSoapClientWsdlName'];
220 22
        }
221 280
    }
222
223
    /**
224
     * Load SoapClient Options from config
225
     *
226
     * @param array $params
227
     * @return void
228
     */
229 280
    protected function loadSoapClientOptions($params)
230
    {
231 280
        if (isset($params['soapClientOptions']) && is_array($params['soapClientOptions'])) {
232 4
            $this->soapClientOptions = $params['soapClientOptions'];
233 2
        }
234 280
    }
235
236
    /**
237
     * Load TransactionFlowLink options from config
238
     *
239
     * @param array $params
240
     * @return void
241
     */
242 280
    protected function loadTransactionFlowLink($params)
243
    {
244 280
        if (isset($params['enableTransactionFlowLink']) && $params['enableTransactionFlowLink'] === true) {
245 4
            $this->enableTransactionFlowLink = true;
246 4
            $this->consumerId = (isset($params['consumerId'])) ? $params['consumerId'] : null;
247 2
        }
248 280
    }
249
}
250