Merge branch '0.2'

This commit is contained in:
Francis Besset 2014-08-18 14:20:19 +02:00
commit f2a8a7ebb3
17 changed files with 128 additions and 26 deletions

View File

@ -98,6 +98,23 @@ class BeSimpleSoapExtension extends Extension
} }
} }
$proxy = $options['proxy'];
if (false !== $proxy['host']) {
if (null !== $proxy['auth']) {
if ('basic' === $proxy['auth']) {
$proxy['auth'] = \CURLAUTH_BASIC;
} elseif ('ntlm' === $proxy['auth']) {
$proxy['auth'] = \CURLAUTH_NTLM;
}
}
$definition->addMethodCall('withProxy', array(
$proxy['host'], $proxy['port'],
$proxy['login'], $proxy['password'],
$proxy['auth']
));
}
if (isset($defOptions['cache_type'])) { if (isset($defOptions['cache_type'])) {
$defOptions['cache_type'] = $this->getCacheType($defOptions['cache_type']); $defOptions['cache_type'] = $this->getCacheType($defOptions['cache_type']);
} }

View File

@ -24,6 +24,7 @@ use Symfony\Component\Config\Definition\Builder\TreeBuilder;
class Configuration class Configuration
{ {
private $cacheTypes = array('none', 'disk', 'memory', 'disk_memory'); private $cacheTypes = array('none', 'disk', 'memory', 'disk_memory');
private $proxyAuth = array('basic', 'ntlm');
/** /**
* Generates the configuration tree. * Generates the configuration tree.
@ -85,12 +86,33 @@ class Configuration
->scalarNode('cache_type') ->scalarNode('cache_type')
->validate() ->validate()
->ifNotInArray($this->cacheTypes) ->ifNotInArray($this->cacheTypes)
->thenInvalid(sprintf('The cache type has to be either %s', implode(', ', $this->cacheTypes))) ->thenInvalid(sprintf('The cache type has to be either: %s', implode(', ', $this->cacheTypes)))
->end() ->end()
->end() ->end()
->arrayNode('classmap') ->arrayNode('classmap')
->useAttributeAsKey('name')->prototype('scalar')->end() ->useAttributeAsKey('name')->prototype('scalar')->end()
->end() ->end()
->arrayNode('proxy')
->info('proxy configuration')
->addDefaultsIfNotSet()
->beforeNormalization()
->ifTrue(function ($v) { return !is_array($v); })
->then(function ($v) { return array('host' => null === $v ? false : $v); })
->end()
->children()
->scalarNode('host')->defaultFalse()->end()
->scalarNode('port')->defaultValue(3128)->end()
->scalarNode('login')->defaultNull()->end()
->scalarNode('password')->defaultNull()->end()
->scalarNode('auth')
->defaultNull()
->validate()
->ifNotInArray($this->proxyAuth)
->thenInvalid(sprintf('The proxy auth has to be either: %s', implode(', ', $this->proxyAuth)))
->end()
->end()
->end()
->end()
->end() ->end()
->end() ->end()
->end() ->end()

View File

@ -1,8 +1,8 @@
Configuration Configuration
============= =============
Minimal client configuration Client configuration
---------------------------- --------------------
Configure your first client in your config file: Configure your first client in your config file:
@ -12,8 +12,20 @@ Configure your first client in your config file:
be_simple_soap: be_simple_soap:
clients: clients:
DemoApi: DemoApi:
wsdl: http://localhost:8086/app_dev.php/ws/DemoApi?wsdl # required
wsdl: http://localhost/app_dev.php/ws/DemoApi?wsdl
# classmap (optional)
classmap:
type_name: "Full\Class\Name"
# proxy (optional)
proxy:
host: proxy.domain.name # required to enable proxy configuration
port: 3128
login: ~
password: ~
auth: ~ # can be 'basic' or 'ntlm'
Using client Using client
------------ ------------

View File

@ -80,6 +80,7 @@ class Curl
if (isset($options['connection_timeout'])) { if (isset($options['connection_timeout'])) {
curl_setopt($this->ch, CURLOPT_CONNECTTIMEOUT, $options['connection_timeout']); curl_setopt($this->ch, CURLOPT_CONNECTTIMEOUT, $options['connection_timeout']);
} }
if (isset($options['proxy_host'])) { if (isset($options['proxy_host'])) {
if (false !== $options['proxy_host']) { if (false !== $options['proxy_host']) {
$proxyHost = $options['proxy_host'].(isset($options['proxy_port']) ? $options['proxy_port'] : 8080); $proxyHost = $options['proxy_host'].(isset($options['proxy_port']) ? $options['proxy_port'] : 8080);
@ -88,10 +89,16 @@ class Curl
} }
curl_setopt($this->ch, CURLOPT_PROXY, $proxyHost); curl_setopt($this->ch, CURLOPT_PROXY, $proxyHost);
if (false !== $proxyHost && isset($options['proxy_login'])) {
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']);
}
}
} }
if (isset($options['proxy_user'])) {
curl_setopt($this->ch, CURLOPT_PROXYUSERPWD, $options['proxy_user'] . ':' . $options['proxy_password']);
}
if (isset($options['login'])) { if (isset($options['login'])) {
curl_setopt($this->ch, CURLOPT_HTTPAUTH, isset($options['extra_options']['http_auth']) ? $options['extra_options']['http_auth'] : CURLAUTH_ANY); curl_setopt($this->ch, CURLOPT_HTTPAUTH, isset($options['extra_options']['http_auth']) ? $options['extra_options']['http_auth'] : CURLAUTH_ANY);
curl_setopt($this->ch, CURLOPT_USERPWD, $options['login'].':'.$options['password']); curl_setopt($this->ch, CURLOPT_USERPWD, $options['login'].':'.$options['password']);

View File

@ -175,19 +175,28 @@ class SoapClientBuilder extends AbstractSoapBuilder
* *
* @param string $host Host * @param string $host Host
* @param int $port Port * @param int $port Port
* @param string $username Username * @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, $username = 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;
if ($username) { if ($login) {
$this->soapOptions['proxy_login'] = $username; $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;
@ -236,4 +245,4 @@ class SoapClientBuilder extends AbstractSoapBuilder
{ {
$this->validateWsdl(); $this->validateWsdl();
} }
} }

View File

@ -28,6 +28,7 @@ class MtomAxisInteropTest extends TestCase
'base64Binary' => 'BeSimple\SoapClient\Tests\AxisInterop\Fixtures\base64Binary', 'base64Binary' => 'BeSimple\SoapClient\Tests\AxisInterop\Fixtures\base64Binary',
'AttachmentRequest' => 'BeSimple\SoapClient\Tests\AxisInterop\Fixtures\AttachmentRequest', 'AttachmentRequest' => 'BeSimple\SoapClient\Tests\AxisInterop\Fixtures\AttachmentRequest',
), ),
'proxy_host' => false,
); );
public function testAttachment() public function testAttachment()
@ -48,4 +49,4 @@ class MtomAxisInteropTest extends TestCase
// $this->assertEquals($b64->_, file_get_contents($fileCreatedByServer)); // $this->assertEquals($b64->_, file_get_contents($fileCreatedByServer));
// unlink($fileCreatedByServer); // unlink($fileCreatedByServer);
} }
} }

View File

@ -37,6 +37,7 @@ class SwaAxisInteropTest extends TestCase
'uploadFile' => 'BeSimple\SoapClient\Tests\AxisInterop\Fixtures\uploadFile', 'uploadFile' => 'BeSimple\SoapClient\Tests\AxisInterop\Fixtures\uploadFile',
'uploadFileResponse' => 'BeSimple\SoapClient\Tests\AxisInterop\Fixtures\uploadFileResponse', 'uploadFileResponse' => 'BeSimple\SoapClient\Tests\AxisInterop\Fixtures\uploadFileResponse',
), ),
'proxy_host' => false,
); );
public function testUploadDownloadText() public function testUploadDownloadText()
@ -74,4 +75,4 @@ class SwaAxisInteropTest extends TestCase
$this->assertEquals($upload->data, $result->data); $this->assertEquals($upload->data, $result->data);
} }
} }

View File

@ -32,6 +32,7 @@ class WsAddressingAxisInteropTest extends TestCase
private $options = array( private $options = array(
'soap_version' => SOAP_1_2, 'soap_version' => SOAP_1_2,
'features' => SOAP_SINGLE_ELEMENT_ARRAYS, // make sure that result is array for size=1 'features' => SOAP_SINGLE_ELEMENT_ARRAYS, // make sure that result is array for size=1
'proxy_host' => false,
); );
public function testSession() public function testSession()
@ -56,4 +57,4 @@ class WsAddressingAxisInteropTest extends TestCase
$this->assertEquals($soapSessionId1, $soapSessionId2); $this->assertEquals($soapSessionId1, $soapSessionId2);
} }
} }

View File

@ -64,6 +64,7 @@ class WsSecuritySigEncAxisInteropTest extends TestCase
'addBookResponse' => 'BeSimple\SoapClient\Tests\AxisInterop\Fixtures\addBookResponse', 'addBookResponse' => 'BeSimple\SoapClient\Tests\AxisInterop\Fixtures\addBookResponse',
'BookInformation' => 'BeSimple\SoapClient\Tests\AxisInterop\Fixtures\BookInformation', 'BookInformation' => 'BeSimple\SoapClient\Tests\AxisInterop\Fixtures\BookInformation',
), ),
'proxy_host' => false,
); );
public function testSigEnc() public function testSigEnc()
@ -103,4 +104,4 @@ class WsSecuritySigEncAxisInteropTest extends TestCase
// getBooksByType("scifi"); // getBooksByType("scifi");
} }
} }

View File

@ -40,6 +40,7 @@ class WsSecurityUserPassAxisInteropTest extends TestCase
'addBookResponse' => 'BeSimple\SoapClient\Tests\AxisInterop\Fixtures\addBookResponse', 'addBookResponse' => 'BeSimple\SoapClient\Tests\AxisInterop\Fixtures\addBookResponse',
'BookInformation' => 'BeSimple\SoapClient\Tests\AxisInterop\Fixtures\BookInformation', 'BookInformation' => 'BeSimple\SoapClient\Tests\AxisInterop\Fixtures\BookInformation',
), ),
'proxy_host' => false,
); );
public function testUserPassText() public function testUserPassText()
@ -93,4 +94,4 @@ class WsSecurityUserPassAxisInteropTest extends TestCase
// getBooksByType("scifi"); // getBooksByType("scifi");
} }
} }

View File

@ -74,7 +74,9 @@ class CurlTest extends AbstractWebserverTest
public function testGetResponseBody() public function testGetResponseBody()
{ {
$curl = new Curl(); $curl = new Curl(array(
'proxy_host' => false,
));
$curl->exec(sprintf('http://localhost:%d/curl.txt', WEBSERVER_PORT)); $curl->exec(sprintf('http://localhost:%d/curl.txt', WEBSERVER_PORT));
$this->assertEquals('This is a testfile for cURL.', $curl->getResponseBody()); $this->assertEquals('This is a testfile for cURL.', $curl->getResponseBody());
@ -82,7 +84,9 @@ class CurlTest extends AbstractWebserverTest
public function testGetResponseContentType() public function testGetResponseContentType()
{ {
$curl = new Curl(); $curl = new Curl(array(
'proxy_host' => false,
));
$curl->exec(sprintf('http://localhost:%d/curl.txt', WEBSERVER_PORT)); $curl->exec(sprintf('http://localhost:%d/curl.txt', WEBSERVER_PORT));
$this->assertEquals('text/plain; charset=UTF-8', $curl->getResponseContentType()); $this->assertEquals('text/plain; charset=UTF-8', $curl->getResponseContentType());
@ -93,7 +97,9 @@ class CurlTest extends AbstractWebserverTest
public function testGetResponseHeaders() public function testGetResponseHeaders()
{ {
$curl = new Curl(); $curl = new Curl(array(
'proxy_host' => false,
));
$curl->exec(sprintf('http://localhost:%d/curl.txt', WEBSERVER_PORT)); $curl->exec(sprintf('http://localhost:%d/curl.txt', WEBSERVER_PORT));
$this->assertEquals(117 + self::$websererPortLength, strlen($curl->getResponseHeaders())); $this->assertEquals(117 + self::$websererPortLength, strlen($curl->getResponseHeaders()));
@ -104,7 +110,9 @@ class CurlTest extends AbstractWebserverTest
public function testGetResponseStatusCode() public function testGetResponseStatusCode()
{ {
$curl = new Curl(); $curl = new Curl(array(
'proxy_host' => false,
));
$curl->exec(sprintf('http://localhost:%d/curl.txt', WEBSERVER_PORT)); $curl->exec(sprintf('http://localhost:%d/curl.txt', WEBSERVER_PORT));
$this->assertEquals(200, $curl->getResponseStatusCode()); $this->assertEquals(200, $curl->getResponseStatusCode());

View File

@ -20,6 +20,7 @@ class MtomServerInteropTest extends TestCase
'base64Binary' => 'BeSimple\SoapClient\Tests\ServerInterop\Fixtures\base64Binary', 'base64Binary' => 'BeSimple\SoapClient\Tests\ServerInterop\Fixtures\base64Binary',
'AttachmentRequest' => 'BeSimple\SoapClient\Tests\ServerInterop\Fixtures\AttachmentRequest', 'AttachmentRequest' => 'BeSimple\SoapClient\Tests\ServerInterop\Fixtures\AttachmentRequest',
), ),
'proxy_host' => false,
); );
public function testAttachment() public function testAttachment()
@ -40,4 +41,4 @@ class MtomServerInteropTest extends TestCase
$this->assertEquals($b64->_, file_get_contents($fileCreatedByServer)); $this->assertEquals($b64->_, file_get_contents($fileCreatedByServer));
unlink($fileCreatedByServer); unlink($fileCreatedByServer);
} }
} }

View File

@ -23,6 +23,7 @@ class SwaServerInteropTest extends TestCase
'uploadFile' => 'BeSimple\SoapClient\Tests\ServerInterop\Fixtures\uploadFile', 'uploadFile' => 'BeSimple\SoapClient\Tests\ServerInterop\Fixtures\uploadFile',
'uploadFileResponse' => 'BeSimple\SoapClient\Tests\ServerInterop\Fixtures\uploadFileResponse', 'uploadFileResponse' => 'BeSimple\SoapClient\Tests\ServerInterop\Fixtures\uploadFileResponse',
), ),
'proxy_host' => false,
); );
public function testUploadDownloadText() public function testUploadDownloadText()

View File

@ -30,6 +30,7 @@ class WsSecuritySigEncServerInteropTest extends TestCase
'addBookResponse' => 'BeSimple\SoapClient\Tests\ServerInterop\Fixtures\addBookResponse', 'addBookResponse' => 'BeSimple\SoapClient\Tests\ServerInterop\Fixtures\addBookResponse',
'BookInformation' => 'BeSimple\SoapClient\Tests\ServerInterop\Fixtures\BookInformation', 'BookInformation' => 'BeSimple\SoapClient\Tests\ServerInterop\Fixtures\BookInformation',
), ),
'proxy_host' => false,
); );
public function testSigEnc() public function testSigEnc()
@ -69,4 +70,4 @@ class WsSecuritySigEncServerInteropTest extends TestCase
// getBooksByType("scifi"); // getBooksByType("scifi");
} }
} }

View File

@ -29,6 +29,7 @@ class WsSecurityUserPassServerInteropTest extends TestCase
'addBookResponse' => 'BeSimple\SoapClient\Tests\ServerInterop\Fixtures\addBookResponse', 'addBookResponse' => 'BeSimple\SoapClient\Tests\ServerInterop\Fixtures\addBookResponse',
'BookInformation' => 'BeSimple\SoapClient\Tests\ServerInterop\Fixtures\BookInformation', 'BookInformation' => 'BeSimple\SoapClient\Tests\ServerInterop\Fixtures\BookInformation',
), ),
'proxy_host' => false,
); );
public function testUserPassText() public function testUserPassText()
@ -82,4 +83,4 @@ class WsSecurityUserPassServerInteropTest extends TestCase
// getBooksByType("scifi"); // getBooksByType("scifi");
} }
} }

View File

@ -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()

View File

@ -115,7 +115,9 @@ class WsdlDownloaderTest extends AbstractWebserverTest
Cache::setDirectory($wsdlCacheUrl); Cache::setDirectory($wsdlCacheUrl);
$cacheDirForRegExp = preg_quote($wsdlCacheUrl, '#'); $cacheDirForRegExp = preg_quote($wsdlCacheUrl, '#');
$wsdlDownloader = new WsdlDownloader(new Curl()); $wsdlDownloader = new WsdlDownloader(new Curl(array(
'proxy_host' => false,
)));
$r = new \ReflectionClass($wsdlDownloader); $r = new \ReflectionClass($wsdlDownloader);
$m = $r->getMethod('resolveRemoteIncludes'); $m = $r->getMethod('resolveRemoteIncludes');
$m->setAccessible(true); $m->setAccessible(true);
@ -178,7 +180,9 @@ class WsdlDownloaderTest extends AbstractWebserverTest
Cache::setDirectory($wsdlCacheUrl); Cache::setDirectory($wsdlCacheUrl);
$cacheDirForRegExp = preg_quote($wsdlCacheUrl, '#'); $cacheDirForRegExp = preg_quote($wsdlCacheUrl, '#');
$wsdlDownloader = new WsdlDownloader(new Curl()); $wsdlDownloader = new WsdlDownloader(new Curl(array(
'proxy_host' => false,
)));
$r = new \ReflectionClass($wsdlDownloader); $r = new \ReflectionClass($wsdlDownloader);
$m = $r->getMethod('resolveRemoteIncludes'); $m = $r->getMethod('resolveRemoteIncludes');
$m->setAccessible(true); $m->setAccessible(true);