Skip to content

Commit 1a7f60b

Browse files
committed
[SoapClient] Added proxy authentication option in SoapClientBuilder
Fixed BeSimple#47
1 parent 70db0c4 commit 1a7f60b

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

src/BeSimple/SoapClient/Curl.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ public function __construct(array $options = array(), $followLocationMaxRedirect
9292

9393
if (false !== $proxyHost && isset($options['proxy_login'])) {
9494
curl_setopt($this->ch, CURLOPT_PROXYUSERPWD, $options['proxy_login'].':'.$options['proxy_password']);
95+
96+
if (isset($options['proxy_auth'])) {
97+
curl_setopt($this->ch, CURLOPT_PROXYAUTH, $options['proxy_auth']);
98+
}
9599
}
96100
}
97101

src/BeSimple/SoapClient/SoapClientBuilder.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,17 +177,26 @@ public function withDigestAuthentication($certificate, $passphrase = null)
177177
* @param int $port Port
178178
* @param string $login Login
179179
* @param string $password Password
180+
* @param int $auth Authentication method
180181
*
181182
* @return \BeSimple\SoapClient\SoapClientBuilder
182183
*/
183-
public function withProxy($host, $port, $login = null, $password = null)
184+
public function withProxy($host, $port, $login = null, $password = null, $auth = null)
184185
{
185186
$this->soapOptions['proxy_host'] = $host;
186187
$this->soapOptions['proxy_port'] = $port;
187188

188189
if ($login) {
189190
$this->soapOptions['proxy_login'] = $login;
190191
$this->soapOptions['proxy_password'] = $password;
192+
193+
if ($auth) {
194+
if (!in_array($auth, array(\CURLAUTH_BASIC, \CURLAUTH_NTLM), true)) {
195+
throw new \InvalidArgumentException('Invalid authentication method: CURLAUTH_BASIC or CURLAUTH_NTLM constants are availables.');
196+
}
197+
198+
$this->soapOptions['proxy_auth'] = $auth;
199+
}
191200
}
192201

193202
return $this;

src/BeSimple/SoapClient/Tests/SoapClientBuilderTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,20 @@ public function testWithProxy()
9696

9797
$builder->withProxy('127.0.0.1', 8585, 'foo', 'bar');
9898
$this->assertEquals($this->mergeOptions(array('proxy_host' => '127.0.0.1', 'proxy_port' => 8585, 'proxy_login' => 'foo', 'proxy_password' => 'bar')), $builder->getSoapOptions());
99+
100+
$builder->withProxy('127.0.0.1', 8585, 'foo', 'bar', \CURLAUTH_BASIC);
101+
$this->assertEquals($this->mergeOptions(array('proxy_host' => '127.0.0.1', 'proxy_port' => 8585, 'proxy_login' => 'foo', 'proxy_password' => 'bar', 'proxy_auth' => \CURLAUTH_BASIC)), $builder->getSoapOptions());
102+
103+
$builder->withProxy('127.0.0.1', 8585, 'foo', 'bar', \CURLAUTH_NTLM);
104+
$this->assertEquals($this->mergeOptions(array('proxy_host' => '127.0.0.1', 'proxy_port' => 8585, 'proxy_login' => 'foo', 'proxy_password' => 'bar', 'proxy_auth' => \CURLAUTH_NTLM)), $builder->getSoapOptions());
105+
106+
try {
107+
$builder->withProxy('127.0.0.1', 8585, 'foo', 'bar', -100);
108+
109+
$this->fail('An expected exception has not been raised.');
110+
} catch (\Exception $e) {
111+
$this->assertInstanceOf('InvalidArgumentException', $e);
112+
}
99113
}
100114

101115
public function testCreateWithDefaults()

0 commit comments

Comments
 (0)