Skip to content

Commit f2a8a7e

Browse files
committed
Merge branch '0.2'
2 parents bbd4c26 + 7a9119c commit f2a8a7e

17 files changed

+128
-26
lines changed

src/BeSimple/SoapBundle/DependencyInjection/BeSimpleSoapExtension.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,23 @@ private function registerClientConfiguration(array $config, ContainerBuilder $co
9898
}
9999
}
100100

101+
$proxy = $options['proxy'];
102+
if (false !== $proxy['host']) {
103+
if (null !== $proxy['auth']) {
104+
if ('basic' === $proxy['auth']) {
105+
$proxy['auth'] = \CURLAUTH_BASIC;
106+
} elseif ('ntlm' === $proxy['auth']) {
107+
$proxy['auth'] = \CURLAUTH_NTLM;
108+
}
109+
}
110+
111+
$definition->addMethodCall('withProxy', array(
112+
$proxy['host'], $proxy['port'],
113+
$proxy['login'], $proxy['password'],
114+
$proxy['auth']
115+
));
116+
}
117+
101118
if (isset($defOptions['cache_type'])) {
102119
$defOptions['cache_type'] = $this->getCacheType($defOptions['cache_type']);
103120
}

src/BeSimple/SoapBundle/DependencyInjection/Configuration.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
class Configuration
2525
{
2626
private $cacheTypes = array('none', 'disk', 'memory', 'disk_memory');
27+
private $proxyAuth = array('basic', 'ntlm');
2728

2829
/**
2930
* Generates the configuration tree.
@@ -85,12 +86,33 @@ private function addClientSection(ArrayNodeDefinition $rootNode)
8586
->scalarNode('cache_type')
8687
->validate()
8788
->ifNotInArray($this->cacheTypes)
88-
->thenInvalid(sprintf('The cache type has to be either %s', implode(', ', $this->cacheTypes)))
89+
->thenInvalid(sprintf('The cache type has to be either: %s', implode(', ', $this->cacheTypes)))
8990
->end()
9091
->end()
9192
->arrayNode('classmap')
9293
->useAttributeAsKey('name')->prototype('scalar')->end()
9394
->end()
95+
->arrayNode('proxy')
96+
->info('proxy configuration')
97+
->addDefaultsIfNotSet()
98+
->beforeNormalization()
99+
->ifTrue(function ($v) { return !is_array($v); })
100+
->then(function ($v) { return array('host' => null === $v ? false : $v); })
101+
->end()
102+
->children()
103+
->scalarNode('host')->defaultFalse()->end()
104+
->scalarNode('port')->defaultValue(3128)->end()
105+
->scalarNode('login')->defaultNull()->end()
106+
->scalarNode('password')->defaultNull()->end()
107+
->scalarNode('auth')
108+
->defaultNull()
109+
->validate()
110+
->ifNotInArray($this->proxyAuth)
111+
->thenInvalid(sprintf('The proxy auth has to be either: %s', implode(', ', $this->proxyAuth)))
112+
->end()
113+
->end()
114+
->end()
115+
->end()
94116
->end()
95117
->end()
96118
->end()

src/BeSimple/SoapBundle/Resources/doc/soapclient/configuration.rst

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Configuration
22
=============
33

4-
Minimal client configuration
5-
----------------------------
4+
Client configuration
5+
--------------------
66

77
Configure your first client in your config file:
88

@@ -12,8 +12,20 @@ Configure your first client in your config file:
1212
be_simple_soap:
1313
clients:
1414
DemoApi:
15-
wsdl: http://localhost:8086/app_dev.php/ws/DemoApi?wsdl
15+
# required
16+
wsdl: http://localhost/app_dev.php/ws/DemoApi?wsdl
1617
18+
# classmap (optional)
19+
classmap:
20+
type_name: "Full\Class\Name"
21+
22+
# proxy (optional)
23+
proxy:
24+
host: proxy.domain.name # required to enable proxy configuration
25+
port: 3128
26+
login: ~
27+
password: ~
28+
auth: ~ # can be 'basic' or 'ntlm'
1729
1830
Using client
1931
------------

src/BeSimple/SoapClient/Curl.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ public function __construct(array $options = array(), $followLocationMaxRedirect
8080
if (isset($options['connection_timeout'])) {
8181
curl_setopt($this->ch, CURLOPT_CONNECTTIMEOUT, $options['connection_timeout']);
8282
}
83+
8384
if (isset($options['proxy_host'])) {
8485
if (false !== $options['proxy_host']) {
8586
$proxyHost = $options['proxy_host'].(isset($options['proxy_port']) ? $options['proxy_port'] : 8080);
@@ -88,10 +89,16 @@ public function __construct(array $options = array(), $followLocationMaxRedirect
8889
}
8990

9091
curl_setopt($this->ch, CURLOPT_PROXY, $proxyHost);
92+
93+
if (false !== $proxyHost && isset($options['proxy_login'])) {
94+
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+
}
99+
}
91100
}
92-
if (isset($options['proxy_user'])) {
93-
curl_setopt($this->ch, CURLOPT_PROXYUSERPWD, $options['proxy_user'] . ':' . $options['proxy_password']);
94-
}
101+
95102
if (isset($options['login'])) {
96103
curl_setopt($this->ch, CURLOPT_HTTPAUTH, isset($options['extra_options']['http_auth']) ? $options['extra_options']['http_auth'] : CURLAUTH_ANY);
97104
curl_setopt($this->ch, CURLOPT_USERPWD, $options['login'].':'.$options['password']);

src/BeSimple/SoapClient/SoapClientBuilder.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,19 +175,28 @@ public function withDigestAuthentication($certificate, $passphrase = null)
175175
*
176176
* @param string $host Host
177177
* @param int $port Port
178-
* @param string $username Username
178+
* @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, $username = 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

188-
if ($username) {
189-
$this->soapOptions['proxy_login'] = $username;
189+
if ($login) {
190+
$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;
@@ -236,4 +245,4 @@ protected function validateOptions()
236245
{
237246
$this->validateWsdl();
238247
}
239-
}
248+
}

src/BeSimple/SoapClient/Tests/AxisInterop/MtomAxisInteropTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class MtomAxisInteropTest extends TestCase
2828
'base64Binary' => 'BeSimple\SoapClient\Tests\AxisInterop\Fixtures\base64Binary',
2929
'AttachmentRequest' => 'BeSimple\SoapClient\Tests\AxisInterop\Fixtures\AttachmentRequest',
3030
),
31+
'proxy_host' => false,
3132
);
3233

3334
public function testAttachment()
@@ -48,4 +49,4 @@ public function testAttachment()
4849
// $this->assertEquals($b64->_, file_get_contents($fileCreatedByServer));
4950
// unlink($fileCreatedByServer);
5051
}
51-
}
52+
}

src/BeSimple/SoapClient/Tests/AxisInterop/SwaAxisInteropTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class SwaAxisInteropTest extends TestCase
3737
'uploadFile' => 'BeSimple\SoapClient\Tests\AxisInterop\Fixtures\uploadFile',
3838
'uploadFileResponse' => 'BeSimple\SoapClient\Tests\AxisInterop\Fixtures\uploadFileResponse',
3939
),
40+
'proxy_host' => false,
4041
);
4142

4243
public function testUploadDownloadText()
@@ -74,4 +75,4 @@ public function testUploadDownloadImage()
7475

7576
$this->assertEquals($upload->data, $result->data);
7677
}
77-
}
78+
}

src/BeSimple/SoapClient/Tests/AxisInterop/WsAddressingAxisInteropTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class WsAddressingAxisInteropTest extends TestCase
3232
private $options = array(
3333
'soap_version' => SOAP_1_2,
3434
'features' => SOAP_SINGLE_ELEMENT_ARRAYS, // make sure that result is array for size=1
35+
'proxy_host' => false,
3536
);
3637

3738
public function testSession()
@@ -56,4 +57,4 @@ public function testSession()
5657

5758
$this->assertEquals($soapSessionId1, $soapSessionId2);
5859
}
59-
}
60+
}

src/BeSimple/SoapClient/Tests/AxisInterop/WsSecuritySigEncAxisInteropTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class WsSecuritySigEncAxisInteropTest extends TestCase
6464
'addBookResponse' => 'BeSimple\SoapClient\Tests\AxisInterop\Fixtures\addBookResponse',
6565
'BookInformation' => 'BeSimple\SoapClient\Tests\AxisInterop\Fixtures\BookInformation',
6666
),
67+
'proxy_host' => false,
6768
);
6869

6970
public function testSigEnc()
@@ -103,4 +104,4 @@ public function testSigEnc()
103104

104105
// getBooksByType("scifi");
105106
}
106-
}
107+
}

src/BeSimple/SoapClient/Tests/AxisInterop/WsSecurityUserPassAxisInteropTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class WsSecurityUserPassAxisInteropTest extends TestCase
4040
'addBookResponse' => 'BeSimple\SoapClient\Tests\AxisInterop\Fixtures\addBookResponse',
4141
'BookInformation' => 'BeSimple\SoapClient\Tests\AxisInterop\Fixtures\BookInformation',
4242
),
43+
'proxy_host' => false,
4344
);
4445

4546
public function testUserPassText()
@@ -93,4 +94,4 @@ public function testUserPassDigest()
9394

9495
// getBooksByType("scifi");
9596
}
96-
}
97+
}

0 commit comments

Comments
 (0)