[SoapClient] Added proxy authentication option in SoapClientBuilder
Fixed #47
This commit is contained in:
parent
70db0c42fd
commit
1a7f60b679
|
@ -92,6 +92,10 @@ class Curl
|
||||||
|
|
||||||
if (false !== $proxyHost && isset($options['proxy_login'])) {
|
if (false !== $proxyHost && isset($options['proxy_login'])) {
|
||||||
curl_setopt($this->ch, CURLOPT_PROXYUSERPWD, $options['proxy_login'].':'.$options['proxy_password']);
|
curl_setopt($this->ch, CURLOPT_PROXYUSERPWD, $options['proxy_login'].':'.$options['proxy_password']);
|
||||||
|
|
||||||
|
if (isset($options['proxy_auth'])) {
|
||||||
|
curl_setopt($this->ch, CURLOPT_PROXYAUTH, $options['proxy_auth']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -177,10 +177,11 @@ class SoapClientBuilder extends AbstractSoapBuilder
|
||||||
* @param int $port Port
|
* @param int $port Port
|
||||||
* @param string $login Login
|
* @param string $login Login
|
||||||
* @param string $password Password
|
* @param string $password Password
|
||||||
|
* @param int $auth Authentication method
|
||||||
*
|
*
|
||||||
* @return \BeSimple\SoapClient\SoapClientBuilder
|
* @return \BeSimple\SoapClient\SoapClientBuilder
|
||||||
*/
|
*/
|
||||||
public function withProxy($host, $port, $login = null, $password = null)
|
public function withProxy($host, $port, $login = null, $password = null, $auth = null)
|
||||||
{
|
{
|
||||||
$this->soapOptions['proxy_host'] = $host;
|
$this->soapOptions['proxy_host'] = $host;
|
||||||
$this->soapOptions['proxy_port'] = $port;
|
$this->soapOptions['proxy_port'] = $port;
|
||||||
|
@ -188,6 +189,14 @@ class SoapClientBuilder extends AbstractSoapBuilder
|
||||||
if ($login) {
|
if ($login) {
|
||||||
$this->soapOptions['proxy_login'] = $login;
|
$this->soapOptions['proxy_login'] = $login;
|
||||||
$this->soapOptions['proxy_password'] = $password;
|
$this->soapOptions['proxy_password'] = $password;
|
||||||
|
|
||||||
|
if ($auth) {
|
||||||
|
if (!in_array($auth, array(\CURLAUTH_BASIC, \CURLAUTH_NTLM), true)) {
|
||||||
|
throw new \InvalidArgumentException('Invalid authentication method: CURLAUTH_BASIC or CURLAUTH_NTLM constants are availables.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->soapOptions['proxy_auth'] = $auth;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
|
|
@ -96,6 +96,20 @@ class SoapClientBuilderTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
$builder->withProxy('127.0.0.1', 8585, 'foo', 'bar');
|
$builder->withProxy('127.0.0.1', 8585, 'foo', 'bar');
|
||||||
$this->assertEquals($this->mergeOptions(array('proxy_host' => '127.0.0.1', 'proxy_port' => 8585, 'proxy_login' => 'foo', 'proxy_password' => 'bar')), $builder->getSoapOptions());
|
$this->assertEquals($this->mergeOptions(array('proxy_host' => '127.0.0.1', 'proxy_port' => 8585, 'proxy_login' => 'foo', 'proxy_password' => 'bar')), $builder->getSoapOptions());
|
||||||
|
|
||||||
|
$builder->withProxy('127.0.0.1', 8585, 'foo', 'bar', \CURLAUTH_BASIC);
|
||||||
|
$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());
|
||||||
|
|
||||||
|
$builder->withProxy('127.0.0.1', 8585, 'foo', 'bar', \CURLAUTH_NTLM);
|
||||||
|
$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());
|
||||||
|
|
||||||
|
try {
|
||||||
|
$builder->withProxy('127.0.0.1', 8585, 'foo', 'bar', -100);
|
||||||
|
|
||||||
|
$this->fail('An expected exception has not been raised.');
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$this->assertInstanceOf('InvalidArgumentException', $e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCreateWithDefaults()
|
public function testCreateWithDefaults()
|
||||||
|
|
Loading…
Reference in New Issue