Completed
Push — develop ( 0e431d...1ee5f2 )
by Dieter
05:22
created

SessionHandlerParams::loadOverrideSoapClient()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 3
eloc 3
nc 2
nop 1
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
     * @var string
47
     */
48
    public $soapHeaderVersion = Client::HEADER_V4;
49
50
    /**
51
     * @var AuthParams
52
     */
53
    public $authParams;
54
55
    /**
56
     * The default setting for sending messages (if not specified)
57
     *
58
     * Set to FALSE to enable stateless messages - only applies to SOAP header v4 and higher!
59
     *
60
     * @var bool
61
     */
62
    public $stateful = true;
63
64
65
    /**
66
     * @var LoggerInterface
67
     */
68
    public $logger;
69
70
    /**
71
     * Override the default \SoapClient options
72
     *
73
     * used when constructing \SoapClient
74
     *
75
     * See Amadeus\Client\Session\Handler\Base::$soapClientOptions for defaults
76
     *
77
     * @var array
78
     */
79
    public $soapClientOptions = [];
80
81
    /**
82
     * Overridden soap client
83
     *
84
     * @var \SoapClient
85
     */
86
    public $overrideSoapClient;
87
88
    /**
89
     * @param array $params
90
     */
91
    public function __construct($params = [])
92
    {
93
        $this->loadFromArray($params);
94
    }
95
96
    /**
97
     * Load parameters from an associative array
98
     *
99
     * @param array $params
100
     * @return void
101
     */
102
    protected function loadFromArray(array $params) {
103
        if (count($params) > 0) {
104
            if (isset($params['soapHeaderVersion'])) {
105
                $this->soapHeaderVersion = $params['soapHeaderVersion'];
106
            }
107
108
            $this->loadWsdl($params);
109
            $this->loadStateful($params);
110
            $this->loadLogger($params);
111
112
            $this->loadAuthParams($params);
113
114
            $this->loadOverrideSoapClient($params);
115
            $this->loadSoapClientOptions($params);
116
        }
117
    }
118
119
    /**
120
     * Load WSDL from config
121
     *
122
     * @param array $params
123
     * @return void
124
     */
125
    protected function loadWsdl($params)
126
    {
127
        $this->wsdl = (isset($params['wsdl'])) ? $params['wsdl'] : null;
128
    }
129
130
    /**
131
     * Load Stateful param from config
132
     *
133
     * @param array $params
134
     * @return void
135
     */
136
    protected function loadStateful($params)
137
    {
138
        $this->stateful = (isset($params['stateful'])) ? $params['stateful'] : true;
139
    }
140
141
142
    /**
143
     * Load Logger from config
144
     *
145
     * @param array $params
146
     * @return void
147
     */
148
    protected function loadLogger($params)
149
    {
150
        if ((isset($params['logger']) && $params['logger'] instanceof LoggerInterface)) {
151
            $this->logger = $params['logger'];
152
        }
153
    }
154
155
    /**
156
     * Load Authentication parameters from config
157
     *
158
     * @param array $params
159
     * @return void
160
     */
161
    protected function loadAuthParams($params)
162
    {
163 View Code Duplication
        if (isset($params['authParams'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
164
            if ($params['authParams'] instanceof AuthParams) {
165
                $this->authParams = $params['authParams'];
166
            } elseif (is_array($params['authParams'])) {
167
                $this->authParams = new AuthParams($params['authParams']);
168
            }
169
        }
170
    }
171
172
    /**
173
     * Load Override SoapClient parameter from config
174
     *
175
     * @param array $params
176
     * @return void
177
     */
178
    protected function loadOverrideSoapClient($params)
179
    {
180
        if (isset($params['overrideSoapClient']) && $params['overrideSoapClient'] instanceof \SoapClient) {
181
            $this->overrideSoapClient = $params['overrideSoapClient'];
182
        }
183
    }
184
185
    /**
186
     * Load SoapClient Options from config
187
     *
188
     * @param array $params
189
     * @return void
190
     */
191
    protected function loadSoapClientOptions($params)
192
    {
193
        if (isset($params['soapClientOptions']) && is_array($params['soapClientOptions'])) {
194
            $this->soapClientOptions = $params['soapClientOptions'];
195
        }
196
    }
197
}
198