Compare commits
280 Commits
Author | SHA1 | Date | |
---|---|---|---|
1fa5c8a15e | |||
813dd52d70 | |||
8a40d23a94 | |||
5d335f2ca9 | |||
9d6468d0a6 | |||
9786f291b0 | |||
750db6692b | |||
|
9f7b7f40b8 | ||
|
87947a1e7b | ||
e024833d48 | |||
fc44014790 | |||
7ba9c4048c | |||
f0733bd671 | |||
f5e1be09de | |||
df3d75047f | |||
87350704d3 | |||
85f86469ab | |||
e1a35d1e1e | |||
30850d7a01 | |||
77403fcfbb | |||
dc63ba20e4 | |||
dad2b76165 | |||
a1695680ae | |||
95706abbd7 | |||
6d5f9ff9e5 | |||
914acccf1d | |||
0c94185907 | |||
aa0b750f47 | |||
|
cc83e1e6db | ||
|
412e7f16c9 | ||
|
729a2bc8df | ||
|
b8bf76aeb9 | ||
|
a3d691261c | ||
|
6cf62100a4 | ||
|
2e9dc9a34d | ||
|
95a91bb8bb | ||
|
ec0004ea36 | ||
|
00101ff7fb | ||
|
ef81da77ea | ||
|
54e9e0ed05 | ||
|
679b44ba13 | ||
|
a7a49b793a | ||
|
d1f5c1f674 | ||
|
fea1093bed | ||
|
9fc58e4388 | ||
|
a7c610b767 | ||
|
2b8f75b4ae | ||
|
6718703ba5 | ||
|
f9f47b913d | ||
|
ca4991a9f6 | ||
|
cdf77dacd8 | ||
|
7802a0d19f | ||
|
c4118855de | ||
|
2771991fc0 | ||
|
ceb69d97c3 | ||
|
19326bccdd | ||
|
22bde386ab | ||
|
2d36e5f060 | ||
|
873dc0ae08 | ||
|
0e24ffe23d | ||
|
d0f53bc806 | ||
|
0cb00e71b5 | ||
|
cc888bf168 | ||
|
bb95a6cb45 | ||
|
3f2a99adf6 | ||
|
ad93b5ca49 | ||
|
cdeab44c2c | ||
|
e046be22eb | ||
|
b10b5431e5 | ||
|
408d88f164 | ||
|
0e4034a093 | ||
|
fd64676312 | ||
|
4d66d072ec | ||
|
735f6a5826 | ||
|
498012697d | ||
|
b96b65cc49 | ||
|
0748b23630 | ||
|
63111261e7 | ||
|
2b91f94b8d | ||
|
1af0828b15 | ||
|
0ca2fe1fd5 | ||
|
fd923e032e | ||
|
e32514abe4 | ||
|
7322bfefd0 | ||
|
e232b1d8b9 | ||
|
1b87b4d212 | ||
|
ae746087e6 | ||
|
9312e4af6a | ||
|
c3da1d545a | ||
|
ad2bd7bc7a | ||
|
e58927469c | ||
|
45cce3a41c | ||
|
e6beef5a80 | ||
|
69a7005c35 | ||
|
073028f160 | ||
|
a9f11beb83 | ||
|
7ab8771989 | ||
|
d68c25daad | ||
|
6e117940a3 | ||
|
0c47f5a8d4 | ||
|
75a0489cce | ||
|
de5d6a2647 | ||
|
6970b7bbef | ||
|
b650254d54 | ||
|
668f2dd258 | ||
|
a8bc834077 | ||
|
f74e4b08ce | ||
|
dcd5ff5234 | ||
|
7bd8481a4e | ||
|
c82288d641 | ||
|
bb20882ade | ||
|
2264e329a1 | ||
|
b9e36b4900 | ||
|
d495f22413 | ||
|
8db9b374e4 | ||
|
f669c18c7f | ||
|
524d1f3fd7 | ||
|
ecffdc18fd | ||
|
b45202f40a | ||
|
ab83642f06 | ||
|
564005da93 | ||
|
311f9e6d08 | ||
|
e67d5aa84b | ||
|
d3023b1a5a | ||
|
21d705bbfa | ||
|
0e2c33faf8 | ||
|
cf6e147c26 | ||
|
f276a30a47 | ||
|
4edc46e67f | ||
|
a76526a5b6 | ||
|
baf32c1350 | ||
|
5c0bf914e3 | ||
|
01d10b89fd | ||
|
e1b50ce914 | ||
|
68b41acc46 | ||
|
30a9707c59 | ||
|
aee034791e | ||
|
00ddf149b0 | ||
|
476813e9bb | ||
|
f57239ad0d | ||
|
10caf27da3 | ||
|
51d1abab48 | ||
|
1224f5f40f | ||
|
f4a4619fe6 | ||
|
052ab20d67 | ||
|
dd7b6904b6 | ||
|
c4d993585f | ||
|
bd1fbf9cfc | ||
|
5fbcfb3e22 | ||
|
84c37b1d24 | ||
|
8d033f9afc | ||
|
bf494a42b5 | ||
|
969709cae5 | ||
|
155aa029ce | ||
|
3c0f731086 | ||
|
374c64538a | ||
|
4d7894b66e | ||
|
0a157748a8 | ||
|
c4a9b58b08 | ||
|
fc15bf36ab | ||
|
8462233a08 | ||
|
03227295f6 | ||
|
f285adfa14 | ||
|
2ecdbe9714 | ||
|
e5c54164c1 | ||
|
27ebf0fbce | ||
|
855e382590 | ||
|
2974a4f838 | ||
|
fb56d51bd8 | ||
|
f2a8a7ebb3 | ||
|
7a9119cef1 | ||
|
1a7f60b679 | ||
|
70db0c42fd | ||
|
960c9f557a | ||
|
33d641de4e | ||
|
bbd4c26134 | ||
|
29170576c2 | ||
|
50ab5a93ad | ||
|
1290573285 | ||
|
f5675f6ece | ||
|
15b208d861 | ||
|
294a9fe90e | ||
|
313840d5a4 | ||
|
8e4d8b0300 | ||
|
621b2080e0 | ||
|
fe67cff5ff | ||
|
e676eb0432 | ||
|
fd402731af | ||
|
f5d6f5e759 | ||
|
726ee89936 | ||
|
36a368e695 | ||
|
e2de214ea5 | ||
|
3cfeea8371 | ||
|
c24e8775bf | ||
|
b3c6353af8 | ||
|
10bba6a3bd | ||
|
a122f2a0f6 | ||
|
8d13d2dd5c | ||
|
1c1cd377f1 | ||
|
1efa348ae5 | ||
|
ccc4d57501 | ||
|
740f146bad | ||
|
5e8e669299 | ||
|
e4cb612aed | ||
|
59ea6b1ce0 | ||
|
7bb849e394 | ||
|
02722eae8f | ||
|
b7581f29b0 | ||
|
dc6e1e0889 | ||
|
f986400dc2 | ||
|
67410805ba | ||
|
2ae7515294 | ||
|
cdfc3cd5bd | ||
|
9ac755d86e | ||
|
321dcf3058 | ||
|
3a2b8e32ee | ||
|
fd5154a469 | ||
|
188f282a87 | ||
|
f9e230400d | ||
|
1b4e262c60 | ||
|
60e3714602 | ||
|
1e82d7fdd7 | ||
|
8788d7595d | ||
|
b45224587a | ||
|
c8baf14c75 | ||
|
53849c68e0 | ||
|
ecdf7e1872 | ||
|
dcfca04db4 | ||
|
73efa627ce | ||
|
d6752a41e9 | ||
|
6a6661012e | ||
|
10705aa9e2 | ||
|
bd2508f854 | ||
|
259c23ee4d | ||
|
98842b24f8 | ||
|
48d305e7db | ||
|
4a97c2537e | ||
|
b8f37d213e | ||
|
6e967fe811 | ||
|
00c8726bb2 | ||
|
dc4c9d2191 | ||
|
9ddac35f18 | ||
|
ed0846da6f | ||
|
9827e58c56 | ||
|
e7d86b3e99 | ||
|
54894b2fd9 | ||
|
95efa3e366 | ||
|
c830097430 | ||
|
391a3f10b8 | ||
|
ebd565cd79 | ||
|
81ce2d7571 | ||
|
461675042a | ||
|
f5a8573a4e | ||
|
1f1d513ea3 | ||
|
8e305da9c0 | ||
|
dc3fcaf81f | ||
|
d8d6ca5795 | ||
|
cbd49c3342 | ||
|
e9388023c1 | ||
|
76360c193e | ||
|
155956ca04 | ||
|
3f41d4b7bc | ||
|
4fa7fd759a | ||
|
2b12264304 | ||
|
f8a80c0361 | ||
|
19def707d3 | ||
|
b21d758e77 | ||
|
9bc9410172 | ||
|
1cde22d8bb | ||
|
8d62141a3d | ||
|
96f8415b92 | ||
|
5229091033 | ||
|
580e6f4da7 | ||
|
6a5109c526 | ||
|
5e6fd5de25 | ||
|
ee321fca42 | ||
|
b5af83f9d2 | ||
|
9f9bab242d | ||
|
f792f53aa2 | ||
|
4d9b112bb5 |
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,3 +1,6 @@
|
|||||||
/vendor/
|
/vendor/
|
||||||
composer.lock
|
composer.lock
|
||||||
|
composer.phar
|
||||||
phpunit.xml
|
phpunit.xml
|
||||||
|
.idea
|
||||||
|
.php_cs.cache
|
||||||
|
22
.travis.yml
22
.travis.yml
@ -1,23 +1,25 @@
|
|||||||
language: php
|
language: php
|
||||||
|
|
||||||
php:
|
php:
|
||||||
- 5.3
|
- 5.6
|
||||||
- 5.4
|
- 7.0
|
||||||
- 5.5
|
- 7.1
|
||||||
|
|
||||||
env:
|
env:
|
||||||
- SYMFONY_VERSION=2.0.*
|
- SYMFONY_VERSION=2.8.*
|
||||||
- SYMFONY_VERSION=2.1.*
|
- SYMFONY_VERSION="dev-master symfony/debug:~2.8@dev symfony/http-kernel:~2.8@dev"
|
||||||
- SYMFONY_VERSION=2.2.*
|
|
||||||
- SYMFONY_VERSION=2.3.*
|
|
||||||
- SYMFONY_VERSION=dev-master
|
|
||||||
|
|
||||||
before_script:
|
before_script:
|
||||||
- composer require symfony/http-foundation:${SYMFONY_VERSION} --no-interaction --prefer-source
|
- phpenv config-add myphp.ini
|
||||||
|
- composer self-update
|
||||||
|
- composer require symfony/framework-bundle:${SYMFONY_VERSION} --no-update
|
||||||
|
- composer update --no-interaction --prefer-source
|
||||||
|
- ./src/BeSimple/SoapClient/Tests/bin/phpwebserver.sh
|
||||||
|
- ./src/BeSimple/SoapClient/Tests/bin/axis.sh
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- phpunit --coverage-text
|
- phpunit --coverage-text
|
||||||
|
|
||||||
matrix:
|
matrix:
|
||||||
allow_failures:
|
allow_failures:
|
||||||
- env: SYMFONY_VERSION=dev-master
|
- env: SYMFONY_VERSION="dev-master symfony/debug:~2.8@dev symfony/http-kernel:~2.8@dev"
|
||||||
|
146
README.md
Normal file
146
README.md
Normal file
@ -0,0 +1,146 @@
|
|||||||
|
# BeSimpleSoap (Symfony 3.4 / 4.x)
|
||||||
|
|
||||||
|
This fork provides the BeSimpleSoap bundle, updated to be compatible with Symfony 3.4 and 4.x (as well as with PHP 7.0-7.4).
|
||||||
|
|
||||||
|
We forked the official [BeSimpleSoap](https://github.com/BeSimple/BeSimpleSoap) repository in order to sucessfully maintain some of our projects.
|
||||||
|
|
||||||
|
We now have integrated changes and fixes from sub-forks (thank you guys!), and we should be up to date now :)
|
||||||
|
|
||||||
|
This fork is maintained by people from [Cadoles](https://www.cadoles.com/).
|
||||||
|
|
||||||
|
# Contributing
|
||||||
|
|
||||||
|
We do welcome pull requests :) please include tests if you can.
|
||||||
|
|
||||||
|
Running tests can be done by running `php vendor/bin/phpunit`.
|
||||||
|
|
||||||
|
# Installation
|
||||||
|
|
||||||
|
If you do not yet have composer, follow instructions on the [Composer website](https://getcomposer.org/download/) to install it.
|
||||||
|
|
||||||
|
Then just running:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ composer require cadoles/soap
|
||||||
|
```
|
||||||
|
|
||||||
|
should be enough to get you up and running.
|
||||||
|
|
||||||
|
# Components
|
||||||
|
|
||||||
|
BeSimpleSoap consists of five components ...
|
||||||
|
|
||||||
|
## BeSimpleSoapClient
|
||||||
|
|
||||||
|
**Refactored** BeSimpleSoapClient is a component that extends the native PHP SoapClient with further features like SwA and WS-Security.
|
||||||
|
|
||||||
|
## BeSimpleSoapServer
|
||||||
|
|
||||||
|
**Refactored** BeSimpleSoapServer is a component that extends the native PHP SoapServer with further features like SwA and WS-Security.
|
||||||
|
|
||||||
|
## BeSimpleSoapCommon
|
||||||
|
|
||||||
|
**Refactored** BeSimpleSoapCommon component contains functionality shared by both the server and client implementations.
|
||||||
|
|
||||||
|
## BeSimpleSoapWsdl
|
||||||
|
|
||||||
|
**Untouched!**
|
||||||
|
The component is not affected by refactoring so it should work properly.
|
||||||
|
For further information see the original [README](https://github.com/BeSimple/BeSimpleSoap/blob/master/src/BeSimple/SoapWsdl/README.md).
|
||||||
|
|
||||||
|
## BeSimpleSoapBundle
|
||||||
|
|
||||||
|
**Unsupported!**
|
||||||
|
The BeSimpleSoapBundle is a Symfony2 bundle to build WSDL and SOAP based web services.
|
||||||
|
For further information see the the original [README](https://github.com/BeSimple/BeSimpleSoap/blob/master/src/BeSimple/SoapBundle/README.md).
|
||||||
|
*Will not work since the Symfony libraries were removed and usages of other components were not refactored. Feel free to fork this repository and fix it!*
|
||||||
|
|
||||||
|
# How to use
|
||||||
|
|
||||||
|
You can investigate the unit tests dir ``tests`` in order to get a clue.
|
||||||
|
Forget about associative arrays, vague configurations, multiple extension and silent errors!
|
||||||
|
This may look a bit more complex at the first sight,
|
||||||
|
but it will guide you to configure and set up your client or server properly.
|
||||||
|
|
||||||
|
## Example of soap client call
|
||||||
|
|
||||||
|
```php
|
||||||
|
$soapClientBuilder = new SoapClientBuilder();
|
||||||
|
$soapClient = $soapClientBuilder->build(
|
||||||
|
SoapClientOptionsBuilder::createWithDefaults(),
|
||||||
|
SoapOptionsBuilder::createWithDefaults('http://path/to/wsdlfile.wsdl')
|
||||||
|
);
|
||||||
|
$myRequest = new MyRequest();
|
||||||
|
$myRequest->attribute = 'string value';
|
||||||
|
$soapResponse = $soapClient->soapCall('myMethod', [$myRequest]);
|
||||||
|
|
||||||
|
var_dump($soapResponse); // Contains Response, Attachments
|
||||||
|
```
|
||||||
|
|
||||||
|
### Something wrong?!
|
||||||
|
|
||||||
|
Turn on the tracking and catch `SoapFaultWithTracingData` exception to get some sweets :)
|
||||||
|
|
||||||
|
```php
|
||||||
|
try {
|
||||||
|
$soapResponse = $soapClient->soapCall('myMethod', [$myRequest]);
|
||||||
|
} catch (SoapFaultWithTracingData $fault) {
|
||||||
|
var_dump($fault->getSoapResponseTracingData()->getLastRequest());
|
||||||
|
}
|
||||||
|
```
|
||||||
|
In this example, a ``MyRequest`` object has been used to describe request.
|
||||||
|
Using a ClassMap, you help SoapClient to turn it into XML request.
|
||||||
|
|
||||||
|
## Example of soap server handling
|
||||||
|
|
||||||
|
Starting a SOAP server is a bit more complex.
|
||||||
|
I recommend you to inspect SoapServer unit tests for inspiration.
|
||||||
|
|
||||||
|
```php
|
||||||
|
$dummyService = new DummyService();
|
||||||
|
$classMap = new ClassMap();
|
||||||
|
foreach ($dummyService->getClassMap() as $type => $className) {
|
||||||
|
$classMap->add($type, $className);
|
||||||
|
}
|
||||||
|
$soapServerBuilder = new SoapServerBuilder();
|
||||||
|
$soapServerOptions = SoapServerOptionsBuilder::createWithDefaults($dummyService);
|
||||||
|
$soapOptions = SoapOptionsBuilder::createWithClassMap($dummyService->getWsdlPath(), $classMap);
|
||||||
|
$soapServer = $soapServerBuilder->build($soapServerOptions, $soapOptions);
|
||||||
|
|
||||||
|
$request = $soapServer->createRequest(
|
||||||
|
$dummyService->getEndpoint(),
|
||||||
|
'DummyService.dummyServiceMethod',
|
||||||
|
'text/xml;charset=UTF-8',
|
||||||
|
'<received><soap><request><here /></request></soap></received>'
|
||||||
|
);
|
||||||
|
$response = $soapServer->handleRequest($request);
|
||||||
|
|
||||||
|
var_dump($response); // Contains Response, Attachments
|
||||||
|
```
|
||||||
|
|
||||||
|
In this example, a ``DummyService`` service has been used to handle request.
|
||||||
|
Using a service can help you create coherent SoapServer endpoints.
|
||||||
|
Service can hold an endpoint URL, WSDL path and a class map as associative array.
|
||||||
|
You can hold a class map as ``ClassMap`` object directly in the ``DummyService`` instead of array.
|
||||||
|
|
||||||
|
In the service you should describe SOAP methods from given WSDL.
|
||||||
|
In the example, the dummyServiceMethod is called.
|
||||||
|
The method will receive request object and return response object that are matched according to the class map.
|
||||||
|
|
||||||
|
See a simplified implementation of ``dummyServiceMethod`` to get a clue:
|
||||||
|
|
||||||
|
```php
|
||||||
|
/**
|
||||||
|
* @param DummyServiceRequest $dummyServiceRequest
|
||||||
|
* @return DummyServiceResponse
|
||||||
|
*/
|
||||||
|
public function dummyServiceMethod(DummyServiceRequest $dummyServiceRequest)
|
||||||
|
{
|
||||||
|
$response = new DummyServiceResponse();
|
||||||
|
$response->status = true;
|
||||||
|
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
For further information and getting inspiration for your implementation, see the unit tests in ``tests`` dir.
|
@ -1,9 +1,9 @@
|
|||||||
{
|
{
|
||||||
"name": "besimple/soap",
|
"name": "cadoles/soap",
|
||||||
"type": "library",
|
"type": "library",
|
||||||
"description": "Build and consume SOAP and WSDL based web services",
|
"description": "Build and consume SOAP and WSDL based web services",
|
||||||
"keywords": ["soap"],
|
"keywords": ["soap"],
|
||||||
"homepage": "http://besim.pl",
|
"homepage": "https://github.com/Cadoles/BeSimpleSoap",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
@ -20,34 +20,34 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=5.3.0",
|
"php": ">=7.0",
|
||||||
"ext-soap": "*",
|
"ext-soap": "*",
|
||||||
"ext-curl": "*",
|
"ext-curl": "*",
|
||||||
"ass/xmlsecurity": "dev-master",
|
"ass/xmlsecurity": "~1.0",
|
||||||
"symfony/framework-bundle": "~2.0",
|
"symfony/framework-bundle": "~3.4|~4.0",
|
||||||
"zendframework/zend-mail": "2.1.*",
|
"symfony/twig-bundle": "~3.4|~4.0",
|
||||||
"zendframework/zend-mime": "2.1.*",
|
"laminas/laminas-mime": "~2.1"
|
||||||
"zendframework/zend-soap": "2.1.*"
|
|
||||||
},
|
},
|
||||||
"replace": {
|
"replace": {
|
||||||
"besimple/soap-bundle": "self.version",
|
"besimple/soap-bundle": "self.version",
|
||||||
"besimple/soap-client": "self.version",
|
"besimple/soap-client": "self.version",
|
||||||
"besimple/soap-common": "self.version",
|
"besimple/soap-common": "self.version",
|
||||||
"besimple/soap-server": "self.version"
|
"besimple/soap-server": "self.version",
|
||||||
|
"besimple/soap-wsdl": "self.version",
|
||||||
|
"cocciagialla/soap": "self.version"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"ext-mcrypt": "*",
|
"mikey179/vfsstream": "~1.6.5",
|
||||||
"mikey179/vfsStream": "dev-master",
|
|
||||||
"symfony/filesystem": "~2.3",
|
"symfony/filesystem": "~2.3",
|
||||||
"symfony/process": "~2.3"
|
"symfony/process": "~2.3",
|
||||||
|
"phpunit/phpunit": "^5.7"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-0": { "BeSimple\\": "src/" }
|
"psr-0": { "BeSimple\\": "src/" }
|
||||||
},
|
},
|
||||||
"minimum-stability": "dev",
|
|
||||||
"extra": {
|
"extra": {
|
||||||
"branch-alias": {
|
"branch-alias": {
|
||||||
"dev-master": "0.1-dev"
|
"dev-master": "5.2.0-dev"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
1
src/BeSimple/SoapBundle/.gitignore
vendored
1
src/BeSimple/SoapBundle/.gitignore
vendored
@ -1,3 +1,4 @@
|
|||||||
vendor/
|
vendor/
|
||||||
composer.lock
|
composer.lock
|
||||||
phpunit.xml
|
phpunit.xml
|
||||||
|
.idea/
|
||||||
|
@ -25,7 +25,6 @@ class Cache
|
|||||||
|
|
||||||
BaseCache::setEnabled($isEnabled);
|
BaseCache::setEnabled($isEnabled);
|
||||||
|
|
||||||
if (BaseCache::ENABLED == BaseCache::isEnabled()) {
|
|
||||||
BaseCache::setType($type);
|
BaseCache::setType($type);
|
||||||
BaseCache::setDirectory($directory);
|
BaseCache::setDirectory($directory);
|
||||||
|
|
||||||
@ -38,4 +37,3 @@ class Cache
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
@ -12,21 +12,29 @@
|
|||||||
|
|
||||||
namespace BeSimple\SoapBundle\Controller;
|
namespace BeSimple\SoapBundle\Controller;
|
||||||
|
|
||||||
|
use BeSimple\SoapBundle\Handler\ExceptionHandler;
|
||||||
use BeSimple\SoapBundle\Soap\SoapRequest;
|
use BeSimple\SoapBundle\Soap\SoapRequest;
|
||||||
use BeSimple\SoapBundle\Soap\SoapResponse;
|
use BeSimple\SoapBundle\Soap\SoapResponse;
|
||||||
use BeSimple\SoapServer\Exception as SoapException;
|
use BeSimple\SoapBundle\WebServiceContext;
|
||||||
|
use BeSimple\SoapServer\SoapServerBuilder;
|
||||||
use Symfony\Component\DependencyInjection\ContainerAware;
|
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
||||||
|
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\Debug\Exception\FlattenException;
|
||||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||||
|
use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
|
||||||
|
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Christian Kerl <christian-kerl@web.de>
|
* @author Christian Kerl <christian-kerl@web.de>
|
||||||
* @author Francis Besset <francis.besset@gmail.com>
|
* @author Francis Besset <francis.besset@gmail.com>
|
||||||
*/
|
*/
|
||||||
class SoapWebServiceController extends ContainerAware
|
class SoapWebServiceController implements ContainerAwareInterface
|
||||||
{
|
{
|
||||||
|
use ContainerAwareTrait;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \SoapServer
|
* @var \SoapServer
|
||||||
*/
|
*/
|
||||||
@ -50,20 +58,22 @@ class SoapWebServiceController extends ContainerAware
|
|||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
private $headers = array();
|
private $headers = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return \BeSimple\SoapBundle\Soap\SoapResponse
|
* @return \BeSimple\SoapBundle\Soap\SoapResponse
|
||||||
*/
|
*/
|
||||||
public function callAction($webservice)
|
public function callAction($webservice)
|
||||||
{
|
{
|
||||||
|
/** @var WebServiceContext $webServiceContext */
|
||||||
$webServiceContext = $this->getWebServiceContext($webservice);
|
$webServiceContext = $this->getWebServiceContext($webservice);
|
||||||
|
|
||||||
$this->serviceBinder = $webServiceContext->getServiceBinder();
|
$this->serviceBinder = $webServiceContext->getServiceBinder();
|
||||||
|
|
||||||
$this->soapRequest = SoapRequest::createFromHttpRequest($this->container->get('request'));
|
$this->soapRequest = SoapRequest::createFromHttpRequest($this->container->get('request_stack')->getCurrentRequest());
|
||||||
$this->soapServer = $webServiceContext
|
$this->soapServer = $webServiceContext
|
||||||
->getServerBuilder()
|
->getServerBuilder()
|
||||||
|
->withSoapVersion11()
|
||||||
->withHandler($this)
|
->withHandler($this)
|
||||||
->build()
|
->build()
|
||||||
;
|
;
|
||||||
@ -79,26 +89,88 @@ class SoapWebServiceController extends ContainerAware
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Symfony\Component\HttpFoundation\Response
|
* @return Response
|
||||||
*/
|
*/
|
||||||
public function definitionAction($webservice)
|
public function definitionAction($webservice)
|
||||||
{
|
{
|
||||||
|
$routeName = $webservice.'_webservice_call';
|
||||||
|
$result = $this->container->get('router')->getRouteCollection()->get($routeName);
|
||||||
|
if (null === $result) {
|
||||||
|
$routeName = '_webservice_call';
|
||||||
|
}
|
||||||
|
|
||||||
$response = new Response($this->getWebServiceContext($webservice)->getWsdlFileContent(
|
$response = new Response($this->getWebServiceContext($webservice)->getWsdlFileContent(
|
||||||
$this->container->get('router')->generate(
|
$this->container->get('router')->generate(
|
||||||
'_webservice_call',
|
$routeName,
|
||||||
array('webservice' => $webservice),
|
['webservice' => $webservice],
|
||||||
true
|
UrlGeneratorInterface::ABSOLUTE_URL
|
||||||
)
|
)
|
||||||
));
|
));
|
||||||
|
|
||||||
$query = $this->container->get('request')->query;
|
/** @var Request $request */
|
||||||
if (!$query->has('wsdl') && !$query->has('WSDL')) {
|
$request = $this->container->get('request_stack')->getCurrentRequest();
|
||||||
$this->container->get('request')->setRequestFormat('xml');
|
$query = $request->query;
|
||||||
|
if ($query->has('wsdl') || $query->has('WSDL')) {
|
||||||
|
$request->setRequestFormat('wsdl');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts an Exception to a SoapFault Response.
|
||||||
|
*
|
||||||
|
* @param Request $request The request
|
||||||
|
* @param FlattenException $exception A FlattenException instance
|
||||||
|
* @param DebugLoggerInterface $logger A DebugLoggerInterface instance
|
||||||
|
*
|
||||||
|
* @return Response
|
||||||
|
*
|
||||||
|
* @throws \LogicException When the request query parameter "_besimple_soap_webservice" does not exist
|
||||||
|
*/
|
||||||
|
public function exceptionAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null)
|
||||||
|
{
|
||||||
|
if (!$webservice = $request->query->get('_besimple_soap_webservice')) {
|
||||||
|
throw new \LogicException(sprintf('The parameter "%s" is required in Request::$query parameter bag to generate the SoapFault.', '_besimple_soap_webservice'), null, $e);
|
||||||
|
}
|
||||||
|
|
||||||
|
$view = '@Twig/Exception/'.($this->container->get('kernel')->isDebug() ? 'exception' : 'error').'.txt.twig';
|
||||||
|
$code = $exception->getStatusCode();
|
||||||
|
$details = $this->container->get('twig')->render($view, [
|
||||||
|
'status_code' => $code,
|
||||||
|
'status_text' => isset(Response::$statusTexts[$code]) ? Response::$statusTexts[$code] : '',
|
||||||
|
'exception' => $exception,
|
||||||
|
'logger' => $logger,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$handler = new ExceptionHandler($exception, $details);
|
||||||
|
if ($soapFault = $request->query->get('_besimple_soap_fault')) {
|
||||||
|
$handler->setSoapFault($soapFault);
|
||||||
|
|
||||||
|
// Remove parameter from query because cannot be Serialized in Logger
|
||||||
|
$request->query->remove('_besimple_soap_fault');
|
||||||
|
}
|
||||||
|
|
||||||
|
$server = SoapServerBuilder::createWithDefaults()
|
||||||
|
->withWsdl(__DIR__.'/../Handler/wsdl/exception.wsdl')
|
||||||
|
->withWsdlCacheNone()
|
||||||
|
->withHandler($handler)
|
||||||
|
->build()
|
||||||
|
;
|
||||||
|
|
||||||
|
ob_start();
|
||||||
|
$server->handle(
|
||||||
|
'<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://besim.pl/soap/exception/1.0/">'.
|
||||||
|
'<soapenv:Header/>'.
|
||||||
|
'<soapenv:Body>'.
|
||||||
|
'<ns:exception />'.
|
||||||
|
'</soapenv:Body>'.
|
||||||
|
'</soapenv:Envelope>'
|
||||||
|
);
|
||||||
|
|
||||||
|
return new Response(ob_get_clean());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method gets called once for every SOAP header the \SoapServer received
|
* This method gets called once for every SOAP header the \SoapServer received
|
||||||
* and afterwards once for the called SOAP operation.
|
* and afterwards once for the called SOAP operation.
|
||||||
@ -124,13 +196,7 @@ class SoapWebServiceController extends ContainerAware
|
|||||||
);
|
);
|
||||||
|
|
||||||
// forward to controller
|
// forward to controller
|
||||||
try {
|
|
||||||
$response = $this->container->get('http_kernel')->handle($this->soapRequest, HttpKernelInterface::SUB_REQUEST, false);
|
$response = $this->container->get('http_kernel')->handle($this->soapRequest, HttpKernelInterface::SUB_REQUEST, false);
|
||||||
} catch (\Exception $e) {
|
|
||||||
$this->soapResponse = new Response(null, 500);
|
|
||||||
|
|
||||||
throw $e instanceof \SoapFault || $this->container->getParameter('kernel.debug') ? $e : new SoapException\ReceiverSoapFault($e->getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->setResponse($response);
|
$this->setResponse($response);
|
||||||
|
|
||||||
@ -167,7 +233,7 @@ class SoapWebServiceController extends ContainerAware
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the SoapResponse
|
* Set the SoapResponse.
|
||||||
*
|
*
|
||||||
* @param Response $response A response to check and set
|
* @param Response $response A response to check and set
|
||||||
*
|
*
|
||||||
@ -184,7 +250,7 @@ class SoapWebServiceController extends ContainerAware
|
|||||||
return $this->soapResponse = $response;
|
return $this->soapResponse = $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getWebServiceContext($webservice)
|
protected function getWebServiceContext($webservice)
|
||||||
{
|
{
|
||||||
$context = sprintf('besimple.soap.context.%s', $webservice);
|
$context = sprintf('besimple.soap.context.%s', $webservice);
|
||||||
|
|
||||||
|
@ -12,8 +12,6 @@ namespace BeSimple\SoapBundle\Converter;
|
|||||||
|
|
||||||
use BeSimple\SoapBundle\ServiceDefinition\ServiceDefinition;
|
use BeSimple\SoapBundle\ServiceDefinition\ServiceDefinition;
|
||||||
use BeSimple\SoapBundle\Util\Assert;
|
use BeSimple\SoapBundle\Util\Assert;
|
||||||
use BeSimple\SoapBundle\Util\QName;
|
|
||||||
use BeSimple\SoapBundle\Util\String;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Christian Kerl <christian-kerl@web.de>
|
* @author Christian Kerl <christian-kerl@web.de>
|
||||||
@ -50,8 +48,6 @@ class TypeRepository
|
|||||||
|
|
||||||
public function fixTypeInformation(ServiceDefinition $definition)
|
public function fixTypeInformation(ServiceDefinition $definition)
|
||||||
{
|
{
|
||||||
$typeMap = $this->defaultTypeMap;
|
|
||||||
|
|
||||||
foreach ($definition->getAllTypes() as $type) {
|
foreach ($definition->getAllTypes() as $type) {
|
||||||
$phpType = $type->getPhpType();
|
$phpType = $type->getPhpType();
|
||||||
$xmlType = $type->getXmlType();
|
$xmlType = $type->getXmlType();
|
||||||
|
@ -12,7 +12,8 @@ namespace BeSimple\SoapBundle\Converter;
|
|||||||
|
|
||||||
use BeSimple\SoapBundle\Soap\SoapRequest;
|
use BeSimple\SoapBundle\Soap\SoapRequest;
|
||||||
use BeSimple\SoapBundle\Soap\SoapResponse;
|
use BeSimple\SoapBundle\Soap\SoapResponse;
|
||||||
use BeSimple\SoapBundle\Util\String;
|
use BeSimple\SoapBundle\Util\BsString;
|
||||||
|
use BeSimple\SoapCommon\Converter\TypeConverterInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Christian Kerl <christian-kerl@web.de>
|
* @author Christian Kerl <christian-kerl@web.de>
|
||||||
@ -39,7 +40,7 @@ class XopIncludeTypeConverter implements TypeConverterInterface
|
|||||||
|
|
||||||
$ref = $include->getAttribute('href');
|
$ref = $include->getAttribute('href');
|
||||||
|
|
||||||
if (String::startsWith($ref, 'cid:')) {
|
if (BsString::startsWith($ref, 'cid:')) {
|
||||||
$cid = urldecode(substr($ref, 4));
|
$cid = urldecode(substr($ref, 4));
|
||||||
|
|
||||||
return $request->getSoapAttachments()->get($cid)->getContent();
|
return $request->getSoapAttachments()->get($cid)->getContent();
|
||||||
|
@ -17,10 +17,11 @@ use BeSimple\SoapCommon\Cache;
|
|||||||
use Symfony\Component\Config\Definition\Processor;
|
use Symfony\Component\Config\Definition\Processor;
|
||||||
use Symfony\Component\Config\FileLocator;
|
use Symfony\Component\Config\FileLocator;
|
||||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
use Symfony\Component\DependencyInjection\DefinitionDecorator;
|
use Symfony\Component\DependencyInjection\ChildDefinition;
|
||||||
use Symfony\Component\DependencyInjection\Reference;
|
use Symfony\Component\DependencyInjection\Reference;
|
||||||
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
||||||
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
|
||||||
|
use Symfony\Component\HttpKernel\Kernel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* BeSimpleSoapExtension.
|
* BeSimpleSoapExtension.
|
||||||
@ -63,6 +64,8 @@ class BeSimpleSoapExtension extends Extension
|
|||||||
$serviceConfig['name'] = $name;
|
$serviceConfig['name'] = $name;
|
||||||
$this->createWebServiceContext($serviceConfig, $container);
|
$this->createWebServiceContext($serviceConfig, $container);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$container->setParameter('besimple.soap.exception_listener.controller', $config['exception_controller']);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function registerCacheConfiguration(array $config, ContainerBuilder $container, XmlFileLoader $loader)
|
private function registerCacheConfiguration(array $config, ContainerBuilder $container, XmlFileLoader $loader)
|
||||||
@ -78,11 +81,15 @@ class BeSimpleSoapExtension extends Extension
|
|||||||
|
|
||||||
private function registerClientConfiguration(array $config, ContainerBuilder $container, XmlFileLoader $loader)
|
private function registerClientConfiguration(array $config, ContainerBuilder $container, XmlFileLoader $loader)
|
||||||
{
|
{
|
||||||
|
if (3 === Kernel::MAJOR_VERSION) {
|
||||||
|
$loader->load('client3.xml');
|
||||||
|
} else {
|
||||||
$loader->load('client.xml');
|
$loader->load('client.xml');
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($config as $client => $options) {
|
foreach ($config as $client => $options) {
|
||||||
$definition = new DefinitionDecorator('besimple.soap.client.builder');
|
$definition = new ChildDefinition('besimple.soap.client.builder');
|
||||||
$context = $container->setDefinition(sprintf('besimple.soap.client.builder.%s', $client), $definition);
|
$container->setDefinition(sprintf('besimple.soap.client.builder.%s', $client), $definition);
|
||||||
|
|
||||||
$definition->replaceArgument(0, $options['wsdl']);
|
$definition->replaceArgument(0, $options['wsdl']);
|
||||||
|
|
||||||
@ -96,18 +103,31 @@ 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']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$definition->replaceArgument(1, $defOptions);
|
$definition->replaceArgument(1, $defOptions);
|
||||||
|
|
||||||
if (!empty($options['classmap'])) {
|
|
||||||
$classmap = $this->createClientClassmap($client, $options['classmap'], $container);
|
$classmap = $this->createClientClassmap($client, $options['classmap'], $container);
|
||||||
$definition->replaceArgument(2, new Reference($classmap));
|
$definition->replaceArgument(2, new Reference($classmap));
|
||||||
} else {
|
|
||||||
$definition->replaceArgument(2, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->createClient($client, $container);
|
$this->createClient($client, $container);
|
||||||
}
|
}
|
||||||
@ -115,23 +135,33 @@ class BeSimpleSoapExtension extends Extension
|
|||||||
|
|
||||||
private function createClientClassmap($client, array $classmap, ContainerBuilder $container)
|
private function createClientClassmap($client, array $classmap, ContainerBuilder $container)
|
||||||
{
|
{
|
||||||
$definition = new DefinitionDecorator('besimple.soap.classmap');
|
$definition = new ChildDefinition('besimple.soap.classmap');
|
||||||
$context = $container->setDefinition(sprintf('besimple.soap.classmap.%s', $client), $definition);
|
$container->setDefinition(sprintf('besimple.soap.classmap.%s', $client), $definition);
|
||||||
|
|
||||||
|
if (!empty($classmap)) {
|
||||||
$definition->setMethodCalls(array(
|
$definition->setMethodCalls(array(
|
||||||
array('set', array($classmap)),
|
array('set', array($classmap)),
|
||||||
));
|
));
|
||||||
|
}
|
||||||
|
|
||||||
return sprintf('besimple.soap.classmap.%s', $client);
|
return sprintf('besimple.soap.classmap.%s', $client);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function createClient($client, ContainerBuilder $container)
|
private function createClient($client, ContainerBuilder $container)
|
||||||
{
|
{
|
||||||
$definition = new DefinitionDecorator('besimple.soap.client');
|
$definition = new ChildDefinition('besimple.soap.client');
|
||||||
$context = $container->setDefinition(sprintf('besimple.soap.client.%s', $client), $definition);
|
$container->setDefinition(sprintf('besimple.soap.client.%s', $client), $definition);
|
||||||
|
|
||||||
|
if (Kernel::MAJOR_VERSION >= 3) {
|
||||||
|
$definition->setFactory(array(
|
||||||
|
new Reference(sprintf('besimple.soap.client.builder.%s', $client)),
|
||||||
|
'build'
|
||||||
|
));
|
||||||
|
$definition->setPublic(true);
|
||||||
|
} else {
|
||||||
$definition->setFactoryService(sprintf('besimple.soap.client.builder.%s', $client));
|
$definition->setFactoryService(sprintf('besimple.soap.client.builder.%s', $client));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private function createWebServiceContext(array $config, ContainerBuilder $container)
|
private function createWebServiceContext(array $config, ContainerBuilder $container)
|
||||||
{
|
{
|
||||||
@ -139,8 +169,8 @@ class BeSimpleSoapExtension extends Extension
|
|||||||
unset($config['binding']);
|
unset($config['binding']);
|
||||||
|
|
||||||
$contextId = 'besimple.soap.context.'.$config['name'];
|
$contextId = 'besimple.soap.context.'.$config['name'];
|
||||||
$definition = new DefinitionDecorator('besimple.soap.context.'.$bindingSuffix);
|
$definition = new ChildDefinition('besimple.soap.context.'.$bindingSuffix);
|
||||||
$context = $container->setDefinition($contextId, $definition);
|
$container->setDefinition($contextId, $definition);
|
||||||
|
|
||||||
if (isset($config['cache_type'])) {
|
if (isset($config['cache_type'])) {
|
||||||
$config['cache_type'] = $this->getCacheType($config['cache_type']);
|
$config['cache_type'] = $this->getCacheType($config['cache_type']);
|
||||||
@ -148,9 +178,10 @@ class BeSimpleSoapExtension extends Extension
|
|||||||
|
|
||||||
$options = $container
|
$options = $container
|
||||||
->getDefinition('besimple.soap.context.'.$bindingSuffix)
|
->getDefinition('besimple.soap.context.'.$bindingSuffix)
|
||||||
->getArgument(5);
|
->setPublic(true)
|
||||||
|
->getArgument(2);
|
||||||
|
|
||||||
$definition->replaceArgument(5, array_merge($options, $config));
|
$definition->replaceArgument(2, array_merge($options, $config));
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getCacheType($type)
|
private function getCacheType($type)
|
||||||
|
@ -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.
|
||||||
@ -40,6 +41,12 @@ class Configuration
|
|||||||
$this->addServicesSection($rootNode);
|
$this->addServicesSection($rootNode);
|
||||||
$this->addWsdlDumperSection($rootNode);
|
$this->addWsdlDumperSection($rootNode);
|
||||||
|
|
||||||
|
$rootNode
|
||||||
|
->children()
|
||||||
|
->scalarNode('exception_controller')->defaultValue('BeSimpleSoapBundle:SoapWebService:exception')->end()
|
||||||
|
->end()
|
||||||
|
;
|
||||||
|
|
||||||
return $treeBuilder->buildTree();
|
return $treeBuilder->buildTree();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,12 +86,37 @@ 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()
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
namespace BeSimple\SoapBundle\EventListener;
|
namespace BeSimple\SoapBundle\EventListener;
|
||||||
|
|
||||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
|
||||||
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
|
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
|
||||||
|
|
||||||
class RequestFormatListener
|
class RequestFormatListener
|
||||||
|
@ -0,0 +1,87 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the BeSimpleSoapBundle.
|
||||||
|
*
|
||||||
|
* (c) Christian Kerl <christian-kerl@web.de>
|
||||||
|
* (c) Francis Besset <francis.besset@gmail.com>
|
||||||
|
*
|
||||||
|
* This source file is subject to the MIT license that is bundled
|
||||||
|
* with this source code in the file LICENSE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace BeSimple\SoapBundle\EventListener;
|
||||||
|
|
||||||
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
|
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
|
||||||
|
use Symfony\Component\HttpKernel\EventListener\ExceptionListener;
|
||||||
|
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||||
|
use Symfony\Component\HttpKernel\KernelEvents;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Francis Besset <francis.besset@gmail.com>
|
||||||
|
*/
|
||||||
|
class SoapExceptionListener extends ExceptionListener
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var ContainerInterface
|
||||||
|
*/
|
||||||
|
protected $container;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To avoid conflict between , the logger param is not typed:
|
||||||
|
* The parent class needs and instance of `Psr\Log\LoggerInterface` from Symfony 2.2,
|
||||||
|
* before logger is an instance of `Symfony\Component\HttpKernel\Log\LoggerInterface`.
|
||||||
|
*
|
||||||
|
* @param ContainerInterface $container A ContainerInterface instance
|
||||||
|
* @param string $controller The controller name to call
|
||||||
|
* @param LoggerInterface $logger A logger instance
|
||||||
|
*/
|
||||||
|
public function __construct(ContainerInterface $container, $controller, $logger)
|
||||||
|
{
|
||||||
|
parent::__construct($controller, $logger);
|
||||||
|
|
||||||
|
$this->container = $container;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onKernelException(GetResponseForExceptionEvent $event)
|
||||||
|
{
|
||||||
|
if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$request = $event->getRequest();
|
||||||
|
if (!in_array($request->getRequestFormat(), array('soap', 'xml'))) {
|
||||||
|
return;
|
||||||
|
} elseif ('xml' === $request->getRequestFormat() && '_webservice_call' !== $request->attributes->get('_route')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$attributes = $request->attributes;
|
||||||
|
if (!$webservice = $attributes->get('webservice')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$this->container->has(sprintf('besimple.soap.context.%s', $webservice))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// hack to retrieve the current WebService name in the controller
|
||||||
|
$request->query->set('_besimple_soap_webservice', $webservice);
|
||||||
|
|
||||||
|
$exception = $event->getException();
|
||||||
|
if ($exception instanceof \SoapFault) {
|
||||||
|
$request->query->set('_besimple_soap_fault', $exception);
|
||||||
|
}
|
||||||
|
|
||||||
|
parent::onKernelException($event);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getSubscribedEvents()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
// Must be called before ExceptionListener of HttpKernel component
|
||||||
|
KernelEvents::EXCEPTION => array('onKernelException', -64),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
53
src/BeSimple/SoapBundle/Handler/ExceptionHandler.php
Normal file
53
src/BeSimple/SoapBundle/Handler/ExceptionHandler.php
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the BeSimpleSoapBundle.
|
||||||
|
*
|
||||||
|
* (c) Christian Kerl <christian-kerl@web.de>
|
||||||
|
* (c) Francis Besset <francis.besset@gmail.com>
|
||||||
|
*
|
||||||
|
* This source file is subject to the MIT license that is bundled
|
||||||
|
* with this source code in the file LICENSE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace BeSimple\SoapBundle\Handler;
|
||||||
|
|
||||||
|
use BeSimple\SoapServer\Exception\ReceiverSoapFault;
|
||||||
|
use Symfony\Component\Debug\Exception\FlattenException;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Francis Besset <francis.besset@gmail.com>
|
||||||
|
*/
|
||||||
|
class ExceptionHandler
|
||||||
|
{
|
||||||
|
protected $exception;
|
||||||
|
protected $details;
|
||||||
|
protected $soapFault;
|
||||||
|
|
||||||
|
public function __construct(FlattenException $exception, $details = null)
|
||||||
|
{
|
||||||
|
$this->exception = $exception;
|
||||||
|
$this->details = $details;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setSoapFault(\SoapFault $soapFault)
|
||||||
|
{
|
||||||
|
$this->soapFault = $soapFault;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __call($method, $arguments)
|
||||||
|
{
|
||||||
|
if (isset($this->soapFault)) {
|
||||||
|
throw $this->soapFault;
|
||||||
|
}
|
||||||
|
|
||||||
|
$code = $this->exception->getStatusCode();
|
||||||
|
|
||||||
|
throw new ReceiverSoapFault(
|
||||||
|
isset(Response::$statusTexts[$code]) ? Response::$statusTexts[$code] : '',
|
||||||
|
null,
|
||||||
|
$this->details
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
31
src/BeSimple/SoapBundle/Handler/wsdl/exception.wsdl
Normal file
31
src/BeSimple/SoapBundle/Handler/wsdl/exception.wsdl
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://besim.pl/soap/exception/1.0/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" name="Exception" targetNamespace="http://besim.pl/soap/exception/1.0/">
|
||||||
|
|
||||||
|
<portType name="ExceptionPortType">
|
||||||
|
<operation name="exception">
|
||||||
|
<input message="tns:empty"/>
|
||||||
|
<output message="tns:empty"/>
|
||||||
|
</operation>
|
||||||
|
</portType>
|
||||||
|
|
||||||
|
<message name="empty" />
|
||||||
|
|
||||||
|
<binding name="ExceptionBinding" type="tns:ExceptionPortType">
|
||||||
|
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="rpc"/>
|
||||||
|
<operation name="exception">
|
||||||
|
<soap:operation soapAction="http://besim.pl/soap/exception/1.0/exception"/>
|
||||||
|
<input>
|
||||||
|
<soap:body use="literal" namespace="http://besim.pl/soap/exception/1.0/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
|
||||||
|
</input>
|
||||||
|
<output>
|
||||||
|
<soap:body use="literal" namespace="http://besim.pl/soap/exception/1.0/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
|
||||||
|
</output>
|
||||||
|
</operation>
|
||||||
|
</binding>
|
||||||
|
|
||||||
|
<service name="ExceptionService">
|
||||||
|
<port name="ExceptionPort" binding="tns:ExceptionBinding">
|
||||||
|
<soap:address location="http://localhost/soap/Exception"/>
|
||||||
|
</port>
|
||||||
|
</service>
|
||||||
|
</definitions>
|
@ -16,9 +16,12 @@
|
|||||||
</argument>
|
</argument>
|
||||||
<argument type="service" id="besimple.soap.classmap" />
|
<argument type="service" id="besimple.soap.classmap" />
|
||||||
<argument type="service" id="besimple.soap.converter.collection" />
|
<argument type="service" id="besimple.soap.converter.collection" />
|
||||||
|
<argument type="service" id="besimple.soap.cache" /> <!-- hack to load besimple cache configuration -->
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
<service id="besimple.soap.client" factory-service="besimple.soap.client.builder" factory-method="build" class="%besimple.soap.client.builder.class%" abstract="true" />
|
<service id="besimple.soap.client" class="%besimple.soap.client.builder.class%" abstract="true">
|
||||||
|
<factory service="besimple.soap.client.builder" method="build" />
|
||||||
|
</service>
|
||||||
|
|
||||||
<service id="besimple.soap.classmap" class="%besimple.soap.classmap.class%" abstract="true" />
|
<service id="besimple.soap.classmap" class="%besimple.soap.classmap.class%" abstract="true" />
|
||||||
</services>
|
</services>
|
||||||
|
29
src/BeSimple/SoapBundle/Resources/config/client3.xml
Normal file
29
src/BeSimple/SoapBundle/Resources/config/client3.xml
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<container xmlns="http://symfony.com/schema/dic/services"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
|
||||||
|
|
||||||
|
<parameters>
|
||||||
|
<parameter key="besimple.soap.client.builder.class">BeSimple\SoapBundle\Soap\SoapClientBuilder</parameter>
|
||||||
|
<parameter key="besimple.soap.classmap.class">BeSimple\SoapCommon\Classmap</parameter>
|
||||||
|
</parameters>
|
||||||
|
|
||||||
|
<services>
|
||||||
|
<service id="besimple.soap.client.builder" class="%besimple.soap.client.builder.class%" abstract="true">
|
||||||
|
<argument /> <!-- wsdl URI -->
|
||||||
|
<argument type="collection">
|
||||||
|
<argument key="debug">%kernel.debug%</argument>
|
||||||
|
</argument>
|
||||||
|
<argument type="service" id="besimple.soap.classmap" />
|
||||||
|
<argument type="service" id="besimple.soap.converter.collection" />
|
||||||
|
<argument type="service" id="besimple.soap.cache" /> <!-- hack to load besimple cache configuration -->
|
||||||
|
</service>
|
||||||
|
|
||||||
|
<service id="besimple.soap.client" class="%besimple.soap.client.builder.class%" abstract="true">
|
||||||
|
<factory service="besimple.soap.client.builder" method="build" />
|
||||||
|
</service>
|
||||||
|
|
||||||
|
<service id="besimple.soap.classmap" class="%besimple.soap.classmap.class%" abstract="true" />
|
||||||
|
</services>
|
||||||
|
|
||||||
|
</container>
|
@ -29,10 +29,13 @@
|
|||||||
<service id="besimple.soap.definition.loader.annot_class" class="%besimple.soap.definition.loader.annot_class.class%" public="false">
|
<service id="besimple.soap.definition.loader.annot_class" class="%besimple.soap.definition.loader.annot_class.class%" public="false">
|
||||||
<tag name="besimple.soap.definition.loader" />
|
<tag name="besimple.soap.definition.loader" />
|
||||||
<argument type="service" id="annotation_reader" />
|
<argument type="service" id="annotation_reader" />
|
||||||
|
<argument type="service" id="besimple.soap.type.repository" />
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
<service id="besimple.soap.definition.loader.annot_complextype" class="%besimple.soap.definition.loader.annot_complextype.class%" public="false">
|
<service id="besimple.soap.definition.loader.annot_complextype" class="%besimple.soap.definition.loader.annot_complextype.class%" public="false">
|
||||||
|
<tag name="besimple.soap.definition.loader" />
|
||||||
<argument type="service" id="annotation_reader" />
|
<argument type="service" id="annotation_reader" />
|
||||||
|
<argument type="service" id="besimple.soap.type.repository" />
|
||||||
</service>
|
</service>
|
||||||
</services>
|
</services>
|
||||||
|
|
||||||
|
@ -4,15 +4,13 @@
|
|||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
|
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
|
||||||
|
|
||||||
<route id="_webservice_call" pattern="/{webservice}">
|
<route id="_webservice_call" path="/{webservice}" methods="POST">
|
||||||
<default key="_controller">BeSimpleSoapBundle:SoapWebService:Call</default>
|
<default key="_controller">BeSimpleSoapBundle:SoapWebService:Call</default>
|
||||||
<default key="_format">soap</default>
|
<default key="_format">xml</default>
|
||||||
<requirement key="_method">POST</requirement>
|
|
||||||
</route>
|
</route>
|
||||||
|
|
||||||
<route id="_webservice_definition" pattern="/{webservice}">
|
<route id="_webservice_definition" path="/{webservice}" methods="GET">
|
||||||
<default key="_controller">BeSimpleSoapBundle:SoapWebService:Definition</default>
|
<default key="_controller">BeSimpleSoapBundle:SoapWebService:Definition</default>
|
||||||
<default key="_format">wsdl</default>
|
<default key="_format">xml</default>
|
||||||
<requirement key="_method">GET</requirement>
|
|
||||||
</route>
|
</route>
|
||||||
</routes>
|
</routes>
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
<service id="besimple.soap.cache" class="%besimple.soap.cache.class%">
|
<service id="besimple.soap.cache" class="%besimple.soap.cache.class%">
|
||||||
<argument>%kernel.debug%</argument>
|
<argument>%kernel.debug%</argument>
|
||||||
<argument>%besimple.soap.cache.type%</argument>
|
<argument>%besimple.soap.cache.type%</argument>
|
||||||
<argument>%besimple.soap.cache.dir%/php</argument>
|
<argument>%besimple.soap.cache.dir%/cache</argument>
|
||||||
<argument>%besimple.soap.cache.lifetime%</argument>
|
<argument>%besimple.soap.cache.lifetime%</argument>
|
||||||
<argument>%besimple.soap.cache.limit%</argument>
|
<argument>%besimple.soap.cache.limit%</argument>
|
||||||
</service>
|
</service>
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
<parameters>
|
<parameters>
|
||||||
<parameter key="besimple.soap.response.class">BeSimple\SoapBundle\Soap\SoapResponse</parameter>
|
<parameter key="besimple.soap.response.class">BeSimple\SoapBundle\Soap\SoapResponse</parameter>
|
||||||
<parameter key="besimple.soap.response.listener.class">BeSimple\SoapBundle\EventListener\SoapResponseListener</parameter>
|
<parameter key="besimple.soap.response.listener.class">BeSimple\SoapBundle\EventListener\SoapResponseListener</parameter>
|
||||||
|
<parameter key="besimple.soap.exception_listener.class">BeSimple\SoapBundle\EventListener\SoapExceptionListener</parameter>
|
||||||
<parameter key="besimple.soap.context.class">BeSimple\SoapBundle\WebServiceContext</parameter>
|
<parameter key="besimple.soap.context.class">BeSimple\SoapBundle\WebServiceContext</parameter>
|
||||||
<parameter key="besimple.soap.binder.request_header.rpcliteral.class">BeSimple\SoapBundle\ServiceBinding\RpcLiteralRequestHeaderMessageBinder</parameter>
|
<parameter key="besimple.soap.binder.request_header.rpcliteral.class">BeSimple\SoapBundle\ServiceBinding\RpcLiteralRequestHeaderMessageBinder</parameter>
|
||||||
<parameter key="besimple.soap.binder.request.rpcliteral.class">BeSimple\SoapBundle\ServiceBinding\RpcLiteralRequestMessageBinder</parameter>
|
<parameter key="besimple.soap.binder.request.rpcliteral.class">BeSimple\SoapBundle\ServiceBinding\RpcLiteralRequestMessageBinder</parameter>
|
||||||
@ -13,24 +14,28 @@
|
|||||||
<parameter key="besimple.soap.binder.request.documentwrapped.class">BeSimple\SoapBundle\ServiceBinding\DocumentLiteralWrappedRequestMessageBinder</parameter>
|
<parameter key="besimple.soap.binder.request.documentwrapped.class">BeSimple\SoapBundle\ServiceBinding\DocumentLiteralWrappedRequestMessageBinder</parameter>
|
||||||
<parameter key="besimple.soap.binder.request_header.documentwrapped.class">BeSimple\SoapBundle\ServiceBinding\DocumentLiteralWrappedRequestHeaderMessageBinder</parameter>
|
<parameter key="besimple.soap.binder.request_header.documentwrapped.class">BeSimple\SoapBundle\ServiceBinding\DocumentLiteralWrappedRequestHeaderMessageBinder</parameter>
|
||||||
<parameter key="besimple.soap.binder.response.documentwrapped.class">BeSimple\SoapBundle\ServiceBinding\DocumentLiteralWrappedResponseMessageBinder</parameter>
|
<parameter key="besimple.soap.binder.response.documentwrapped.class">BeSimple\SoapBundle\ServiceBinding\DocumentLiteralWrappedResponseMessageBinder</parameter>
|
||||||
<parameter key="besimple.soap.definition.dumper.wsdl.rpcliteral.class">BeSimple\SoapBundle\ServiceDefinition\Dumper\WsdlDumper</parameter>
|
<parameter key="besimple.soap.type.repository.class">BeSimple\SoapCommon\Definition\Type\TypeRepository</parameter>
|
||||||
<parameter key="besimple.soap.type.repository.class">BeSimple\SoapBundle\Converter\TypeRepository</parameter>
|
|
||||||
<parameter key="besimple.soap.server.classmap.class">BeSimple\SoapServer\Classmap</parameter>
|
<parameter key="besimple.soap.server.classmap.class">BeSimple\SoapServer\Classmap</parameter>
|
||||||
</parameters>
|
</parameters>
|
||||||
|
|
||||||
<services>
|
<services>
|
||||||
<service id="besimple.soap.response" class="%besimple.soap.response.class%" />
|
<service id="besimple.soap.response" class="%besimple.soap.response.class%" public="true" />
|
||||||
|
|
||||||
<service id="besimple.soap.response.listener" class="%besimple.soap.response.listener.class%">
|
<service id="besimple.soap.response.listener" class="%besimple.soap.response.listener.class%">
|
||||||
<tag name="kernel.event_listener" event="kernel.view" method="onKernelView" />
|
<tag name="kernel.event_listener" event="kernel.view" method="onKernelView" />
|
||||||
<argument type="service" id="besimple.soap.response" />
|
<argument type="service" id="besimple.soap.response" />
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
|
<service id="besimple.soap.exception_listener" class="%besimple.soap.exception_listener.class%">
|
||||||
|
<tag name="kernel.event_subscriber" />
|
||||||
|
<tag name="monolog.logger" channel="request" />
|
||||||
|
<argument type="service" id="service_container" />
|
||||||
|
<argument>%besimple.soap.exception_listener.controller%</argument>
|
||||||
|
<argument type="service" id="logger" on-invalid="null" />
|
||||||
|
</service>
|
||||||
|
|
||||||
<service id="besimple.soap.context.rpcliteral" class="%besimple.soap.context.class%" abstract="true">
|
<service id="besimple.soap.context.rpcliteral" class="%besimple.soap.context.class%" abstract="true">
|
||||||
<argument type="service" id="besimple.soap.definition.loader" />
|
<argument type="service" id="besimple.soap.definition.loader" />
|
||||||
<argument type="service" id="besimple.soap.definition.dumper.wsdl.rpcliteral" />
|
|
||||||
<argument type="service" id="besimple.soap.server.classmap" />
|
|
||||||
<argument type="service" id="besimple.soap.type.repository" />
|
|
||||||
<argument type="service" id="besimple.soap.converter.collection" />
|
<argument type="service" id="besimple.soap.converter.collection" />
|
||||||
<argument type="collection">
|
<argument type="collection">
|
||||||
<argument key="cache_dir">%besimple.soap.cache.dir%</argument>
|
<argument key="cache_dir">%besimple.soap.cache.dir%</argument>
|
||||||
@ -39,15 +44,13 @@
|
|||||||
<argument key="binder_request_header_class">%besimple.soap.binder.request_header.rpcliteral.class%</argument>
|
<argument key="binder_request_header_class">%besimple.soap.binder.request_header.rpcliteral.class%</argument>
|
||||||
<argument key="binder_request_class">%besimple.soap.binder.request.rpcliteral.class%</argument>
|
<argument key="binder_request_class">%besimple.soap.binder.request.rpcliteral.class%</argument>
|
||||||
<argument key="binder_response_class">%besimple.soap.binder.response.rpcliteral.class%</argument>
|
<argument key="binder_response_class">%besimple.soap.binder.response.rpcliteral.class%</argument>
|
||||||
|
<argument key="wsdl_stylesheet">%besimple.soap.definition.dumper.options.stylesheet%</argument>
|
||||||
</argument>
|
</argument>
|
||||||
<argument type="service" id="besimple.soap.cache" />
|
<argument type="service" id="besimple.soap.cache" />
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
<service id="besimple.soap.context.documentwrapped" class="%besimple.soap.context.class%" abstract="true">
|
<service id="besimple.soap.context.documentwrapped" class="%besimple.soap.context.class%" abstract="true">
|
||||||
<argument type="service" id="besimple.soap.definition.loader" />
|
<argument type="service" id="besimple.soap.definition.loader" />
|
||||||
<argument type="service" id="besimple.soap.definition.dumper.wsdl.documentwrapped" />
|
|
||||||
<argument type="service" id="besimple.soap.server.classmap" />
|
|
||||||
<argument type="service" id="besimple.soap.type.repository" />
|
|
||||||
<argument type="service" id="besimple.soap.converter.collection" />
|
<argument type="service" id="besimple.soap.converter.collection" />
|
||||||
<argument type="collection">
|
<argument type="collection">
|
||||||
<argument key="cache_dir">%besimple.soap.cache.dir%</argument>
|
<argument key="cache_dir">%besimple.soap.cache.dir%</argument>
|
||||||
@ -56,49 +59,51 @@
|
|||||||
<argument key="binder_request_header_class">%besimple.soap.binder.request_header.documentwrapped.class%</argument>
|
<argument key="binder_request_header_class">%besimple.soap.binder.request_header.documentwrapped.class%</argument>
|
||||||
<argument key="binder_request_class">%besimple.soap.binder.request.documentwrapped.class%</argument>
|
<argument key="binder_request_class">%besimple.soap.binder.request.documentwrapped.class%</argument>
|
||||||
<argument key="binder_response_class">%besimple.soap.binder.response.documentwrapped.class%</argument>
|
<argument key="binder_response_class">%besimple.soap.binder.response.documentwrapped.class%</argument>
|
||||||
|
<argument key="wsdl_stylesheet">%besimple.soap.definition.dumper.options.stylesheet%</argument>
|
||||||
</argument>
|
</argument>
|
||||||
<argument type="service" id="besimple.soap.cache" />
|
<argument type="service" id="besimple.soap.cache" />
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
<service id="besimple.soap.definition.dumper.wsdl.rpcliteral" class="%besimple.soap.definition.dumper.wsdl.rpcliteral.class%">
|
|
||||||
<argument type="service" id="besimple.soap.definition.loader.annot_complextype" />
|
|
||||||
<argument type="service" id="besimple.soap.type.repository" />
|
|
||||||
<argument type="collection">
|
|
||||||
<argument key="stylesheet">%besimple.soap.definition.dumper.options.stylesheet%</argument>
|
|
||||||
</argument>
|
|
||||||
</service>
|
|
||||||
|
|
||||||
<service id="besimple.soap.server.classmap" class="%besimple.soap.server.classmap.class%" public="false" />
|
<service id="besimple.soap.server.classmap" class="%besimple.soap.server.classmap.class%" public="false" />
|
||||||
|
|
||||||
<service id="besimple.soap.type.repository" class="%besimple.soap.type.repository.class%">
|
<service id="besimple.soap.type.repository" class="%besimple.soap.type.repository.class%">
|
||||||
|
<argument type="service" id="besimple.soap.server.classmap" />
|
||||||
<call method="addXmlNamespace">
|
<call method="addXmlNamespace">
|
||||||
<argument>xsd</argument>
|
<argument>xsd</argument>
|
||||||
<argument>http://www.w3.org/2001/XMLSchema</argument>
|
<argument>http://www.w3.org/2001/XMLSchema</argument>
|
||||||
</call>
|
</call>
|
||||||
<call method="addDefaultTypeMapping">
|
<call method="addType">
|
||||||
<argument>string</argument>
|
<argument>string</argument>
|
||||||
<argument>xsd:string</argument>
|
<argument>xsd:string</argument>
|
||||||
</call>
|
</call>
|
||||||
<call method="addDefaultTypeMapping">
|
<call method="addType">
|
||||||
<argument>boolean</argument>
|
<argument>boolean</argument>
|
||||||
<argument>xsd:boolean</argument>
|
<argument>xsd:boolean</argument>
|
||||||
</call>
|
</call>
|
||||||
<call method="addDefaultTypeMapping">
|
<call method="addType">
|
||||||
<argument>int</argument>
|
<argument>int</argument>
|
||||||
<argument>xsd:int</argument>
|
<argument>xsd:int</argument>
|
||||||
</call>
|
</call>
|
||||||
<call method="addDefaultTypeMapping">
|
<call method="addType">
|
||||||
<argument>float</argument>
|
<argument>float</argument>
|
||||||
<argument>xsd:float</argument>
|
<argument>xsd:float</argument>
|
||||||
</call>
|
</call>
|
||||||
<call method="addDefaultTypeMapping">
|
<call method="addType">
|
||||||
<argument>date</argument>
|
<argument>date</argument>
|
||||||
<argument>xsd:date</argument>
|
<argument>xsd:date</argument>
|
||||||
</call>
|
</call>
|
||||||
<call method="addDefaultTypeMapping">
|
<call method="addType">
|
||||||
<argument>dateTime</argument>
|
<argument>dateTime</argument>
|
||||||
<argument>xsd:dateTime</argument>
|
<argument>xsd:dateTime</argument>
|
||||||
</call>
|
</call>
|
||||||
|
<call method="addType">
|
||||||
|
<argument>base64Binary</argument>
|
||||||
|
<argument>xsd:base64Binary</argument>
|
||||||
|
</call>
|
||||||
|
<call method="addType">
|
||||||
|
<argument>hexBinary</argument>
|
||||||
|
<argument>xsd:hexBinary</argument>
|
||||||
|
</call>
|
||||||
</service>
|
</service>
|
||||||
</services>
|
</services>
|
||||||
|
|
||||||
|
@ -33,4 +33,8 @@ SoapServer
|
|||||||
SoapClient
|
SoapClient
|
||||||
----------
|
----------
|
||||||
|
|
||||||
Coming soon.
|
.. toctree::
|
||||||
|
:maxdepth: 1
|
||||||
|
:numbered:
|
||||||
|
|
||||||
|
soapclient/configuration
|
||||||
|
@ -0,0 +1,158 @@
|
|||||||
|
Configuration
|
||||||
|
=============
|
||||||
|
|
||||||
|
Client configuration
|
||||||
|
--------------------
|
||||||
|
|
||||||
|
Configure your first client in your config file:
|
||||||
|
|
||||||
|
.. code-block:: yaml
|
||||||
|
|
||||||
|
# app/config/config.yml
|
||||||
|
be_simple_soap:
|
||||||
|
clients:
|
||||||
|
DemoApi:
|
||||||
|
# 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
|
||||||
|
------------
|
||||||
|
|
||||||
|
.. code-block:: php
|
||||||
|
|
||||||
|
namespace Acme\DemoBundle\Controller;
|
||||||
|
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||||
|
|
||||||
|
class DemoController extends Controller
|
||||||
|
{
|
||||||
|
public function helloAction($name)
|
||||||
|
{
|
||||||
|
// The client service name is `besimple.soap.client.demoapi`:
|
||||||
|
// `besimple.soap.client.`: is the base name of your client
|
||||||
|
// `demoapi`: is the name specified in your config file converted to lowercase
|
||||||
|
$client = $this->container->get('besimple.soap.client.demoapi');
|
||||||
|
|
||||||
|
// call `hello` method on WebService with the string parameter `$name`
|
||||||
|
$helloResult = $client->hello($name);
|
||||||
|
|
||||||
|
return $this->render('AcmeDemoBundle:Demo:hello.html.twig', array(
|
||||||
|
'hello' => $helloResult,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Classmap
|
||||||
|
--------
|
||||||
|
|
||||||
|
Configuration
|
||||||
|
~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
.. code-block:: yaml
|
||||||
|
|
||||||
|
# app/config/config.yml
|
||||||
|
be_simple_soap:
|
||||||
|
clients:
|
||||||
|
DemoApi:
|
||||||
|
# ...
|
||||||
|
classmap:
|
||||||
|
User: Acme\DemoBundle\Api\UserApi
|
||||||
|
# add other type_name: classname
|
||||||
|
|
||||||
|
UserApi class
|
||||||
|
~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
.. code-block:: php
|
||||||
|
|
||||||
|
namespace Acme\DemoBundle\Api;
|
||||||
|
|
||||||
|
class UserApi
|
||||||
|
{
|
||||||
|
private $username;
|
||||||
|
|
||||||
|
private $firstname;
|
||||||
|
|
||||||
|
private $lastname;
|
||||||
|
|
||||||
|
public function __construct($username)
|
||||||
|
{
|
||||||
|
$this->username = $username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getFirstname()
|
||||||
|
{
|
||||||
|
return $this->firstname;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getLastname()
|
||||||
|
{
|
||||||
|
return $this->lastname;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Usage
|
||||||
|
~~~~~
|
||||||
|
|
||||||
|
.. code-block:: php
|
||||||
|
|
||||||
|
namespace Acme\DemoBundle\Controller;
|
||||||
|
|
||||||
|
use Acme\DemoBundle\Api\UserApi;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||||
|
|
||||||
|
class DemoController extends Controller
|
||||||
|
{
|
||||||
|
public function userAction($username)
|
||||||
|
{
|
||||||
|
// The client service name is `besimple.soap.client.demoapi`:
|
||||||
|
// `besimple.soap.client.`: is the base name of your client
|
||||||
|
// `demoapi`: is the name specified in your config file converted to lowercase
|
||||||
|
$client = $this->container->get('besimple.soap.client.demoapi');
|
||||||
|
|
||||||
|
// call `getUser` method on WebService with an instance of UserApi
|
||||||
|
// if the `getUserByUsername` method return a `User` type then `$userResult` is an instance of UserApi
|
||||||
|
$userResult = $client->getUserByUsername($username);
|
||||||
|
|
||||||
|
return $this->render('AcmeDemoBundle:Demo:user.html.twig', array(
|
||||||
|
'user' => $userResult,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Without classmap configuration the `$userResult` is an instance of `stdClass`:
|
||||||
|
|
||||||
|
.. code-block:: text
|
||||||
|
|
||||||
|
object(stdClass)#5561 (3) {
|
||||||
|
["username"]=>
|
||||||
|
string(6) "FooBar"
|
||||||
|
["firstname"]=>
|
||||||
|
string(3) "Foo"
|
||||||
|
["lastname"]=>
|
||||||
|
string(3) "Bar"
|
||||||
|
}
|
||||||
|
|
||||||
|
With classmap configuration the `$userResult` is an instance of `Acme\DemoBundle\Api\UserApi`:
|
||||||
|
|
||||||
|
.. code-block:: text
|
||||||
|
|
||||||
|
object(Acme\DemoBundle\Api\UserApi)#208 (3) {
|
||||||
|
["username":"Acme\DemoBundle\Api\UserApi":private]=>
|
||||||
|
string(6) "FooBar"
|
||||||
|
["firstname":"Acme\DemoBundle\Api\UserApi":private]=>
|
||||||
|
string(3) "Foo"
|
||||||
|
["lastname":"Acme\DemoBundle\Api\UserApi":private]=>
|
||||||
|
string(3) "Bar"
|
||||||
|
}
|
@ -47,9 +47,9 @@ Controller
|
|||||||
/**
|
/**
|
||||||
* @Soap\Method("sendAssocArray")
|
* @Soap\Method("sendAssocArray")
|
||||||
* @Soap\Param("assocArray", phpType = "BeSimple\SoapCommon\Type\KeyValue\String[]")
|
* @Soap\Param("assocArray", phpType = "BeSimple\SoapCommon\Type\KeyValue\String[]")
|
||||||
* @Soap\Return(phpType = "BeSimple\SoapCommon\Type\KeyValue\String[]")
|
* @Soap\Result(phpType = "BeSimple\SoapCommon\Type\KeyValue\String[]")
|
||||||
*/
|
*/
|
||||||
public function assocArrayOfStringAction(array $assocArray)
|
public function sendAssocArrayOfStringAction(array $assocArray)
|
||||||
{
|
{
|
||||||
// The $assocArray it's a real associative array
|
// The $assocArray it's a real associative array
|
||||||
// var_dump($assocArray);die;
|
// var_dump($assocArray);die;
|
||||||
@ -97,3 +97,4 @@ How to create my Associative Array?
|
|||||||
'user2' => new User('user2', 'user2@user.com'),
|
'user2' => new User('user2', 'user2@user.com'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
@ -86,6 +86,16 @@ You can expose only the properties (public, protected or private) of a complex t
|
|||||||
*/
|
*/
|
||||||
private $newsletter;
|
private $newsletter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Soap\ComplexType("date")
|
||||||
|
*/
|
||||||
|
private $createdAt:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Soap\ComplexType("datetime")
|
||||||
|
*/
|
||||||
|
private $updatedAt;
|
||||||
|
|
||||||
public function getId()
|
public function getId()
|
||||||
{
|
{
|
||||||
return $this->id;
|
return $this->id;
|
||||||
@ -128,7 +138,27 @@ You can expose only the properties (public, protected or private) of a complex t
|
|||||||
|
|
||||||
public function setNewsletter($newsletter)
|
public function setNewsletter($newsletter)
|
||||||
{
|
{
|
||||||
$this->newletter = (Boolean) $newsletter
|
$this->newletter = (Boolean) $newsletter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCreatedAt()
|
||||||
|
{
|
||||||
|
return $this->createdAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCreatedAt(\DateTime $createdAt)
|
||||||
|
{
|
||||||
|
$this->createdAt = $createdAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getUpdatedAt()
|
||||||
|
{
|
||||||
|
return this->updatedAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setUpdatedAt(\DateTime $updatedAt)
|
||||||
|
{
|
||||||
|
$this->updatedAt = $updatedAt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* This file is part of the BeSimpleSoapBundle.
|
||||||
|
*
|
||||||
|
* (c) Christian Kerl <christian-kerl@web.de>
|
||||||
|
*
|
||||||
|
* This source file is subject to the MIT license that is bundled
|
||||||
|
* with this source code in the file LICENSE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace BeSimple\SoapBundle\ServiceBinding;
|
||||||
|
|
||||||
|
use BeSimple\SoapBundle\ServiceDefinition\Method;
|
||||||
|
use BeSimple\SoapCommon\Definition\Type\TypeRepository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Francis Besset <francis.besset@gmail.com>
|
||||||
|
*/
|
||||||
|
class DocumentLiteralWrappedRequestHeaderMessageBinder extends DocumentLiteralWrappedRequestMessageBinder
|
||||||
|
{
|
||||||
|
private $header;
|
||||||
|
|
||||||
|
public function setHeader($header)
|
||||||
|
{
|
||||||
|
$this->header = $header;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function processMessage(Method $messageDefinition, $message, TypeRepository $typeRepository)
|
||||||
|
{
|
||||||
|
$headerDefinition = $messageDefinition->getHeaders()->get($this->header);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
@ -11,13 +11,14 @@
|
|||||||
namespace BeSimple\SoapBundle\ServiceBinding;
|
namespace BeSimple\SoapBundle\ServiceBinding;
|
||||||
|
|
||||||
use BeSimple\SoapBundle\ServiceDefinition\Method;
|
use BeSimple\SoapBundle\ServiceDefinition\Method;
|
||||||
|
use BeSimple\SoapCommon\Definition\Type\TypeRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Christian Kerl <christian-kerl@web.de>
|
* @author Christian Kerl <christian-kerl@web.de>
|
||||||
*/
|
*/
|
||||||
class DocumentLiteralWrappedRequestMessageBinder implements MessageBinderInterface
|
class DocumentLiteralWrappedRequestMessageBinder implements MessageBinderInterface
|
||||||
{
|
{
|
||||||
public function processMessage(Method $messageDefinition, $message)
|
public function processMessage(Method $messageDefinition, $message, TypeRepository $typeRepository)
|
||||||
{
|
{
|
||||||
if (count($message) > 1) {
|
if (count($message) > 1) {
|
||||||
throw new \InvalidArgumentException();
|
throw new \InvalidArgumentException();
|
||||||
@ -26,8 +27,8 @@ class DocumentLiteralWrappedRequestMessageBinder implements MessageBinderInterfa
|
|||||||
$result = array();
|
$result = array();
|
||||||
$message = $message[0];
|
$message = $message[0];
|
||||||
|
|
||||||
foreach($messageDefinition->getArguments() as $argument) {
|
foreach ($messageDefinition->getInput()->all() as $argument) {
|
||||||
$result[$argument->getName()] = $message->{$argument->getName()};
|
$result[$argument->getName()] = $message;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
|
@ -11,17 +11,15 @@
|
|||||||
namespace BeSimple\SoapBundle\ServiceBinding;
|
namespace BeSimple\SoapBundle\ServiceBinding;
|
||||||
|
|
||||||
use BeSimple\SoapBundle\ServiceDefinition\Method;
|
use BeSimple\SoapBundle\ServiceDefinition\Method;
|
||||||
|
use BeSimple\SoapCommon\Definition\Type\TypeRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Christian Kerl <christian-kerl@web.de>
|
* @author Christian Kerl <christian-kerl@web.de>
|
||||||
*/
|
*/
|
||||||
class DocumentLiteralWrappedResponseMessageBinder implements MessageBinderInterface
|
class DocumentLiteralWrappedResponseMessageBinder implements MessageBinderInterface
|
||||||
{
|
{
|
||||||
public function processMessage(Method $messageDefinition, $message)
|
public function processMessage(Method $messageDefinition, $message, TypeRepository $typeRepository)
|
||||||
{
|
{
|
||||||
$result = new \stdClass();
|
return $message;
|
||||||
$result->{$messageDefinition->getName().'Result'} = $message;
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -11,6 +11,7 @@
|
|||||||
namespace BeSimple\SoapBundle\ServiceBinding;
|
namespace BeSimple\SoapBundle\ServiceBinding;
|
||||||
|
|
||||||
use BeSimple\SoapBundle\ServiceDefinition\Method;
|
use BeSimple\SoapBundle\ServiceDefinition\Method;
|
||||||
|
use BeSimple\SoapCommon\Definition\Type\TypeRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Christian Kerl <christian-kerl@web.de>
|
* @author Christian Kerl <christian-kerl@web.de>
|
||||||
@ -23,5 +24,5 @@ interface MessageBinderInterface
|
|||||||
*
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
function processMessage(Method $messageDefinition, $message, array $definitionComplexTypes = array());
|
public function processMessage(Method $messageDefinition, $message, TypeRepository $typeRepository);
|
||||||
}
|
}
|
@ -11,6 +11,7 @@
|
|||||||
namespace BeSimple\SoapBundle\ServiceBinding;
|
namespace BeSimple\SoapBundle\ServiceBinding;
|
||||||
|
|
||||||
use BeSimple\SoapBundle\ServiceDefinition\Method;
|
use BeSimple\SoapBundle\ServiceDefinition\Method;
|
||||||
|
use BeSimple\SoapCommon\Definition\Type\TypeRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Francis Besset <francis.besset@gmail.com>
|
* @author Francis Besset <francis.besset@gmail.com>
|
||||||
@ -24,10 +25,11 @@ class RpcLiteralRequestHeaderMessageBinder extends RpcLiteralRequestMessageBinde
|
|||||||
$this->header = $header;
|
$this->header = $header;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function processMessage(Method $messageDefinition, $message, array $definitionComplexTypes = array())
|
public function processMessage(Method $messageDefinition, $message, TypeRepository $typeRepository)
|
||||||
{
|
{
|
||||||
|
$this->typeRepository = $typeRepository;
|
||||||
$headerDefinition = $messageDefinition->getHeaders()->get($this->header);
|
$headerDefinition = $messageDefinition->getHeaders()->get($this->header);
|
||||||
|
|
||||||
return $this->processType($headerDefinition->getType()->getPhpType(), $message, $definitionComplexTypes);
|
return $this->processType($headerDefinition->getType(), $message);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -13,8 +13,9 @@
|
|||||||
namespace BeSimple\SoapBundle\ServiceBinding;
|
namespace BeSimple\SoapBundle\ServiceBinding;
|
||||||
|
|
||||||
use BeSimple\SoapBundle\ServiceDefinition\Method;
|
use BeSimple\SoapBundle\ServiceDefinition\Method;
|
||||||
use BeSimple\SoapBundle\ServiceDefinition\Strategy\MethodComplexType;
|
use BeSimple\SoapCommon\Definition\Type\ArrayOfType;
|
||||||
use BeSimple\SoapBundle\ServiceDefinition\Strategy\PropertyComplexType;
|
use BeSimple\SoapCommon\Definition\Type\ComplexType;
|
||||||
|
use BeSimple\SoapCommon\Definition\Type\TypeRepository;
|
||||||
use BeSimple\SoapCommon\Util\MessageBinder;
|
use BeSimple\SoapCommon\Util\MessageBinder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -23,19 +24,20 @@ use BeSimple\SoapCommon\Util\MessageBinder;
|
|||||||
*/
|
*/
|
||||||
class RpcLiteralRequestMessageBinder implements MessageBinderInterface
|
class RpcLiteralRequestMessageBinder implements MessageBinderInterface
|
||||||
{
|
{
|
||||||
private $messageRefs = array();
|
protected $typeRepository;
|
||||||
private $definitionComplexTypes;
|
|
||||||
|
|
||||||
public function processMessage(Method $messageDefinition, $message, array $definitionComplexTypes = array())
|
private $messageRefs = array();
|
||||||
|
|
||||||
|
public function processMessage(Method $messageDefinition, $message, TypeRepository $typeRepository)
|
||||||
{
|
{
|
||||||
$this->definitionComplexTypes = $definitionComplexTypes;
|
$this->typeRepository = $typeRepository;
|
||||||
|
|
||||||
$result = array();
|
$result = array();
|
||||||
$i = 0;
|
$i = 0;
|
||||||
|
|
||||||
foreach ($messageDefinition->getArguments() as $argument) {
|
foreach ($messageDefinition->getInput()->all() as $argument) {
|
||||||
if (isset($message[$i])) {
|
if (isset($message[$i])) {
|
||||||
$result[$argument->getName()] = $this->processType($argument->getType()->getPhpType(), $message[$i]);
|
$result[$argument->getName()] = $this->processType($argument->getType(), $message[$i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$i++;
|
$i++;
|
||||||
@ -48,14 +50,18 @@ class RpcLiteralRequestMessageBinder implements MessageBinderInterface
|
|||||||
{
|
{
|
||||||
$isArray = false;
|
$isArray = false;
|
||||||
|
|
||||||
if (preg_match('/^([^\[]+)\[\]$/', $phpType, $match)) {
|
$type = $this->typeRepository->getType($phpType);
|
||||||
|
if ($type instanceof ArrayOfType) {
|
||||||
$isArray = true;
|
$isArray = true;
|
||||||
$array = array();
|
$array = array();
|
||||||
$phpType = $match[1];
|
|
||||||
|
$type = $this->typeRepository->getType($type->get('item')->getType());
|
||||||
}
|
}
|
||||||
|
|
||||||
// @TODO Fix array reference
|
// @TODO Fix array reference
|
||||||
if (isset($this->definitionComplexTypes[$phpType])) {
|
if ($type instanceof ComplexType) {
|
||||||
|
$phpType = $type->getPhpType();
|
||||||
|
|
||||||
if ($isArray) {
|
if ($isArray) {
|
||||||
if (isset($message->item)) {
|
if (isset($message->item)) {
|
||||||
foreach ($message->item as $complexType) {
|
foreach ($message->item as $complexType) {
|
||||||
@ -98,17 +104,16 @@ class RpcLiteralRequestMessageBinder implements MessageBinderInterface
|
|||||||
$this->messageRefs[$hash] = $message;
|
$this->messageRefs[$hash] = $message;
|
||||||
|
|
||||||
$messageBinder = new MessageBinder($message);
|
$messageBinder = new MessageBinder($message);
|
||||||
foreach ($this->definitionComplexTypes[$phpType]['properties'] as $type) {
|
foreach ($this->typeRepository->getType($phpType)->all() as $type) {
|
||||||
$property = $type->getName();
|
$property = $type->getName();
|
||||||
$value = $messageBinder->readProperty($property);
|
$value = $messageBinder->readProperty($property);
|
||||||
|
|
||||||
if (null !== $value) {
|
if (null !== $value) {
|
||||||
$value = $this->processType($type->getValue(), $value);
|
$value = $this->processType($type->getType(), $value);
|
||||||
|
|
||||||
$messageBinder->writeProperty($property, $value);
|
$messageBinder->writeProperty($property, $value);
|
||||||
}
|
} elseif (!$type->isNillable()) {
|
||||||
|
// @TODO use xmlType instead of phpType
|
||||||
if (!$type->isNillable() && null === $value) {
|
|
||||||
throw new \SoapFault('SOAP_ERROR_COMPLEX_TYPE', sprintf('"%s:%s" cannot be null.', ucfirst($phpType), $type->getName()));
|
throw new \SoapFault('SOAP_ERROR_COMPLEX_TYPE', sprintf('"%s:%s" cannot be null.', ucfirst($phpType), $type->getName()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,8 +13,9 @@
|
|||||||
namespace BeSimple\SoapBundle\ServiceBinding;
|
namespace BeSimple\SoapBundle\ServiceBinding;
|
||||||
|
|
||||||
use BeSimple\SoapBundle\ServiceDefinition\Method;
|
use BeSimple\SoapBundle\ServiceDefinition\Method;
|
||||||
use BeSimple\SoapBundle\ServiceDefinition\Strategy\PropertyComplexType;
|
use BeSimple\SoapCommon\Definition\Type\ArrayOfType;
|
||||||
use BeSimple\SoapBundle\ServiceDefinition\Strategy\MethodComplexType;
|
use BeSimple\SoapCommon\Definition\Type\ComplexType;
|
||||||
|
use BeSimple\SoapCommon\Definition\Type\TypeRepository;
|
||||||
use BeSimple\SoapCommon\Util\MessageBinder;
|
use BeSimple\SoapCommon\Util\MessageBinder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -23,26 +24,34 @@ use BeSimple\SoapCommon\Util\MessageBinder;
|
|||||||
*/
|
*/
|
||||||
class RpcLiteralResponseMessageBinder implements MessageBinderInterface
|
class RpcLiteralResponseMessageBinder implements MessageBinderInterface
|
||||||
{
|
{
|
||||||
|
protected $typeRepository;
|
||||||
|
|
||||||
private $messageRefs = array();
|
private $messageRefs = array();
|
||||||
private $definitionComplexTypes;
|
|
||||||
|
|
||||||
public function processMessage(Method $messageDefinition, $message, array $definitionComplexTypes = array())
|
public function processMessage(Method $messageDefinition, $message, TypeRepository $typeRepository)
|
||||||
{
|
{
|
||||||
$this->definitionComplexTypes = $definitionComplexTypes;
|
$this->typeRepository = $typeRepository;
|
||||||
|
|
||||||
return $this->processType($messageDefinition->getReturn()->getPhpType(), $message);
|
$parts = $messageDefinition->getOutput()->all();
|
||||||
|
$part = array_shift($parts);
|
||||||
|
|
||||||
|
return $this->processType($part->getType(), $message);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function processType($phpType, $message)
|
private function processType($phpType, $message)
|
||||||
{
|
{
|
||||||
$isArray = false;
|
$isArray = false;
|
||||||
|
|
||||||
if (preg_match('/^([^\[]+)\[\]$/', $phpType, $match)) {
|
$type = $this->typeRepository->getType($phpType);
|
||||||
|
if ($type instanceof ArrayOfType) {
|
||||||
$isArray = true;
|
$isArray = true;
|
||||||
$phpType = $match[1];
|
|
||||||
|
$type = $this->typeRepository->getType($type->get('item')->getType());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($this->definitionComplexTypes[$phpType])) {
|
if ($type instanceof ComplexType) {
|
||||||
|
$phpType = $type->getPhpType();
|
||||||
|
|
||||||
if ($isArray) {
|
if ($isArray) {
|
||||||
$array = array();
|
$array = array();
|
||||||
|
|
||||||
@ -79,16 +88,16 @@ class RpcLiteralResponseMessageBinder implements MessageBinderInterface
|
|||||||
$this->messageRefs[$hash] = $message;
|
$this->messageRefs[$hash] = $message;
|
||||||
|
|
||||||
if (!$message instanceof $phpType) {
|
if (!$message instanceof $phpType) {
|
||||||
throw new \InvalidArgumentException(sprintf('The instance class must be "%s", "%s" given.', get_class($message), $phpType));
|
throw new \InvalidArgumentException(sprintf('The instance class must be "%s", "%s" given.', $phpType, get_class($message)));
|
||||||
}
|
}
|
||||||
|
|
||||||
$messageBinder = new MessageBinder($message);
|
$messageBinder = new MessageBinder($message);
|
||||||
foreach ($this->definitionComplexTypes[$phpType]['properties'] as $type) {
|
foreach ($this->typeRepository->getType($phpType)->all() as $type) {
|
||||||
$property = $type->getName();
|
$property = $type->getName();
|
||||||
$value = $messageBinder->readProperty($property);
|
$value = $messageBinder->readProperty($property);
|
||||||
|
|
||||||
if (null !== $value) {
|
if (null !== $value) {
|
||||||
$value = $this->processType($type->getValue(), $value);
|
$value = $this->processType($type->getType(), $value);
|
||||||
|
|
||||||
$messageBinder->writeProperty($property, $value);
|
$messageBinder->writeProperty($property, $value);
|
||||||
}
|
}
|
||||||
|
@ -10,8 +10,7 @@
|
|||||||
|
|
||||||
namespace BeSimple\SoapBundle\ServiceBinding;
|
namespace BeSimple\SoapBundle\ServiceBinding;
|
||||||
|
|
||||||
use BeSimple\SoapBundle\ServiceDefinition\Header;
|
use BeSimple\SoapBundle\ServiceDefinition\Definition;
|
||||||
use BeSimple\SoapBundle\ServiceDefinition\ServiceDefinition;
|
|
||||||
use BeSimple\SoapBundle\Soap\SoapHeader;
|
use BeSimple\SoapBundle\Soap\SoapHeader;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -40,12 +39,13 @@ class ServiceBinder
|
|||||||
private $responseMessageBinder;
|
private $responseMessageBinder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ServiceDefinition $definition
|
* @param Definition $definition
|
||||||
* @param MessageBinderInterface $requestHeaderMessageBinder
|
* @param MessageBinderInterface $requestHeaderMessageBinder
|
||||||
* @param MessageBinderInterface $requestMessageBinder
|
* @param MessageBinderInterface $requestMessageBinder
|
||||||
* @param MessageBinderInterface $responseMessageBinder
|
* @param MessageBinderInterface $responseMessageBinder
|
||||||
*/
|
*/
|
||||||
public function __construct(ServiceDefinition $definition, MessageBinderInterface $requestHeaderMessageBinder, MessageBinderInterface $requestMessageBinder, MessageBinderInterface $responseMessageBinder) {
|
public function __construct(Definition $definition, MessageBinderInterface $requestHeaderMessageBinder, MessageBinderInterface $requestMessageBinder, MessageBinderInterface $responseMessageBinder)
|
||||||
|
{
|
||||||
$this->definition = $definition;
|
$this->definition = $definition;
|
||||||
|
|
||||||
$this->requestHeaderMessageBinder = $requestHeaderMessageBinder;
|
$this->requestHeaderMessageBinder = $requestHeaderMessageBinder;
|
||||||
@ -62,7 +62,7 @@ class ServiceBinder
|
|||||||
*/
|
*/
|
||||||
public function isServiceHeader($method, $header)
|
public function isServiceHeader($method, $header)
|
||||||
{
|
{
|
||||||
return $this->definition->getMethods()->get($method)->getHeaders()->has($header);
|
return $this->definition->getMethod($method)->getHeader($header);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -72,7 +72,7 @@ class ServiceBinder
|
|||||||
*/
|
*/
|
||||||
public function isServiceMethod($method)
|
public function isServiceMethod($method)
|
||||||
{
|
{
|
||||||
return $this->definition->getMethods()->has($method);
|
return null !== $this->definition->getMethod($method);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -84,11 +84,11 @@ class ServiceBinder
|
|||||||
*/
|
*/
|
||||||
public function processServiceHeader($method, $header, $data)
|
public function processServiceHeader($method, $header, $data)
|
||||||
{
|
{
|
||||||
$methodDefinition = $this->definition->getMethods()->get($method);
|
$methodDefinition = $this->definition->getMethod($method);
|
||||||
$headerDefinition = $methodDefinition->getHeaders()->get($header);
|
$headerDefinition = $methodDefinition->getHeader($header);
|
||||||
|
|
||||||
$this->requestHeaderMessageBinder->setHeader($header);
|
$this->requestHeaderMessageBinder->setHeader($header);
|
||||||
$data = $this->requestHeaderMessageBinder->processMessage($methodDefinition, $data, $this->definition->getDefinitionComplexTypes());
|
$data = $this->requestHeaderMessageBinder->processMessage($methodDefinition, $data, $this->definition->getTypeRepository());
|
||||||
|
|
||||||
return new SoapHeader($this->definition->getNamespace(), $headerDefinition->getName(), $data);
|
return new SoapHeader($this->definition->getNamespace(), $headerDefinition->getName(), $data);
|
||||||
}
|
}
|
||||||
@ -101,11 +101,11 @@ class ServiceBinder
|
|||||||
*/
|
*/
|
||||||
public function processServiceMethodArguments($method, $arguments)
|
public function processServiceMethodArguments($method, $arguments)
|
||||||
{
|
{
|
||||||
$methodDefinition = $this->definition->getMethods()->get($method);
|
$methodDefinition = $this->definition->getMethod($method);
|
||||||
|
|
||||||
return array_merge(
|
return array_merge(
|
||||||
array('_controller' => $methodDefinition->getController()),
|
array('_controller' => $methodDefinition->getController()),
|
||||||
$this->requestMessageBinder->processMessage($methodDefinition, $arguments, $this->definition->getDefinitionComplexTypes())
|
$this->requestMessageBinder->processMessage($methodDefinition, $arguments, $this->definition->getTypeRepository())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,8 +117,8 @@ class ServiceBinder
|
|||||||
*/
|
*/
|
||||||
public function processServiceMethodReturnValue($name, $return)
|
public function processServiceMethodReturnValue($name, $return)
|
||||||
{
|
{
|
||||||
$methodDefinition = $this->definition->getMethods()->get($name);
|
$methodDefinition = $this->definition->getMethod($name);
|
||||||
|
|
||||||
return $this->responseMessageBinder->processMessage($methodDefinition, $return, $this->definition->getDefinitionComplexTypes());
|
return $this->responseMessageBinder->processMessage($methodDefinition, $return, $this->definition->getTypeRepository());
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -18,6 +18,7 @@ class ComplexType extends Configuration
|
|||||||
private $name;
|
private $name;
|
||||||
private $value;
|
private $value;
|
||||||
private $isNillable = false;
|
private $isNillable = false;
|
||||||
|
private $minOccurs = 1;
|
||||||
|
|
||||||
public function getName()
|
public function getName()
|
||||||
{
|
{
|
||||||
@ -34,6 +35,11 @@ class ComplexType extends Configuration
|
|||||||
return $this->isNillable;
|
return $this->isNillable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getIsNillable()
|
||||||
|
{
|
||||||
|
return $this->isNillable;
|
||||||
|
}
|
||||||
|
|
||||||
public function setName($name)
|
public function setName($name)
|
||||||
{
|
{
|
||||||
$this->name = $name;
|
$this->name = $name;
|
||||||
@ -49,6 +55,21 @@ class ComplexType extends Configuration
|
|||||||
$this->isNillable = (bool) $isNillable;
|
$this->isNillable = (bool) $isNillable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setIsNillable($isNillable)
|
||||||
|
{
|
||||||
|
$this->isNillable = (bool) $isNillable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setMinOccurs($minOccurs)
|
||||||
|
{
|
||||||
|
$this->minOccurs = $minOccurs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getMinOccurs()
|
||||||
|
{
|
||||||
|
return $this->minOccurs;
|
||||||
|
}
|
||||||
|
|
||||||
public function getAliasName()
|
public function getAliasName()
|
||||||
{
|
{
|
||||||
return 'complextype';
|
return 'complextype';
|
||||||
|
@ -22,5 +22,5 @@ interface ConfigurationInterface
|
|||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function getAliasName();
|
public function getAliasName();
|
||||||
}
|
}
|
@ -12,8 +12,8 @@ namespace BeSimple\SoapBundle\ServiceDefinition\Annotation;
|
|||||||
|
|
||||||
interface TypedElementInterface
|
interface TypedElementInterface
|
||||||
{
|
{
|
||||||
function getPhpType();
|
public function getPhpType();
|
||||||
function getXmlType();
|
public function getXmlType();
|
||||||
function setPhpType($phpType);
|
public function setPhpType($phpType);
|
||||||
function setXmlType($xmlType);
|
public function setXmlType($xmlType);
|
||||||
}
|
}
|
@ -1,43 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* This file is part of the BeSimpleSoapBundle.
|
|
||||||
*
|
|
||||||
* (c) Christian Kerl <christian-kerl@web.de>
|
|
||||||
*
|
|
||||||
* This source file is subject to the MIT license that is bundled
|
|
||||||
* with this source code in the file LICENSE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace BeSimple\SoapBundle\ServiceDefinition;
|
|
||||||
|
|
||||||
class Argument
|
|
||||||
{
|
|
||||||
private $name;
|
|
||||||
private $type;
|
|
||||||
|
|
||||||
public function __construct($name = null, Type $type = null)
|
|
||||||
{
|
|
||||||
$this->setName($name);
|
|
||||||
$this->setType($type);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getName()
|
|
||||||
{
|
|
||||||
return $this->name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setName($name)
|
|
||||||
{
|
|
||||||
$this->name = $name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getType()
|
|
||||||
{
|
|
||||||
return $this->type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setType(Type $type)
|
|
||||||
{
|
|
||||||
$this->type = $type;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,8 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the BeSimpleSoapBundle.
|
* This file is part of the BeSimpleSoap.
|
||||||
*
|
*
|
||||||
* (c) Christian Kerl <christian-kerl@web.de>
|
* (c) Christian Kerl <christian-kerl@web.de>
|
||||||
|
* (c) Francis Besset <francis.besset@gmail.com>
|
||||||
*
|
*
|
||||||
* This source file is subject to the MIT license that is bundled
|
* This source file is subject to the MIT license that is bundled
|
||||||
* with this source code in the file LICENSE.
|
* with this source code in the file LICENSE.
|
||||||
@ -18,6 +20,7 @@ class ComplexType
|
|||||||
private $name;
|
private $name;
|
||||||
private $value;
|
private $value;
|
||||||
private $isNillable = false;
|
private $isNillable = false;
|
||||||
|
private $minOccurs = 1;
|
||||||
|
|
||||||
public function getName()
|
public function getName()
|
||||||
{
|
{
|
||||||
@ -48,4 +51,14 @@ class ComplexType
|
|||||||
{
|
{
|
||||||
$this->isNillable = (bool) $isNillable;
|
$this->isNillable = (bool) $isNillable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setMinOccurs($minOccurs)
|
||||||
|
{
|
||||||
|
$this->minOccurs = $minOccurs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getMinOccurs()
|
||||||
|
{
|
||||||
|
return $this->minOccurs;
|
||||||
|
}
|
||||||
}
|
}
|
44
src/BeSimple/SoapBundle/ServiceDefinition/Definition.php
Normal file
44
src/BeSimple/SoapBundle/ServiceDefinition/Definition.php
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the BeSimpleSoap.
|
||||||
|
*
|
||||||
|
* (c) Christian Kerl <christian-kerl@web.de>
|
||||||
|
* (c) Francis Besset <francis.besset@gmail.com>
|
||||||
|
*
|
||||||
|
* This source file is subject to the MIT license that is bundled
|
||||||
|
* with this source code in the file LICENSE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace BeSimple\SoapBundle\ServiceDefinition;
|
||||||
|
|
||||||
|
use BeSimple\SoapCommon\Definition\Definition as BaseDefinition;
|
||||||
|
use BeSimple\SoapCommon\Definition\Type\TypeRepository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Christian Kerl <christian-kerl@web.de>
|
||||||
|
* @author Francis Besset <francis.besset@gmail.com>
|
||||||
|
*/
|
||||||
|
class Definition extends BaseDefinition
|
||||||
|
{
|
||||||
|
public function __construct(TypeRepository $typeRepository)
|
||||||
|
{
|
||||||
|
$this->typeRepository = $typeRepository;
|
||||||
|
|
||||||
|
$this->setOptions(array());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setName($name)
|
||||||
|
{
|
||||||
|
$this->name = $name;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setNamespace($namespace)
|
||||||
|
{
|
||||||
|
$this->namespace = $namespace;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
}
|
@ -1,18 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* This file is part of the BeSimpleSoapBundle.
|
|
||||||
*
|
|
||||||
* (c) Christian Kerl <christian-kerl@web.de>
|
|
||||||
*
|
|
||||||
* This source file is subject to the MIT license that is bundled
|
|
||||||
* with this source code in the file LICENSE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace BeSimple\SoapBundle\ServiceDefinition\Dumper;
|
|
||||||
|
|
||||||
use BeSimple\SoapBundle\ServiceDefinition\ServiceDefinition;
|
|
||||||
|
|
||||||
interface DumperInterface
|
|
||||||
{
|
|
||||||
function dumpServiceDefinition(ServiceDefinition $definition, $endpoint);
|
|
||||||
}
|
|
@ -1,80 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* This file is part of the BeSimpleSoapBundle.
|
|
||||||
*
|
|
||||||
* (c) Christian Kerl <christian-kerl@web.de>
|
|
||||||
*
|
|
||||||
* This source file is subject to the MIT license that is bundled
|
|
||||||
* with this source code in the file LICENSE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace BeSimple\SoapBundle\ServiceDefinition\Dumper;
|
|
||||||
|
|
||||||
use BeSimple\SoapBundle\Converter\TypeRepository;
|
|
||||||
use BeSimple\SoapBundle\ServiceDefinition\Type;
|
|
||||||
use Zend\Soap\Wsdl as BaseWsdl;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Francis Besset <francis.besset@gmail.com>
|
|
||||||
*/
|
|
||||||
class Wsdl extends BaseWsdl
|
|
||||||
{
|
|
||||||
private $typeRepository;
|
|
||||||
|
|
||||||
public function __construct(TypeRepository $typeRepository, $name, $uri, $strategy = true)
|
|
||||||
{
|
|
||||||
$this->typeRepository = $typeRepository;
|
|
||||||
|
|
||||||
parent::__construct($name, $uri, $strategy);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getType($type)
|
|
||||||
{
|
|
||||||
if ($type instanceof Type) {
|
|
||||||
return $type->getXmlType();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ('\\' === $type[0]) {
|
|
||||||
$type = substr($type, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$xmlType = $this->typeRepository->getXmlTypeMapping($type)) {
|
|
||||||
$xmlType = $this->addComplexType($type);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $xmlType;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Translate PHP type into WSDL QName
|
|
||||||
*
|
|
||||||
* @param string $type
|
|
||||||
* @return string QName
|
|
||||||
*/
|
|
||||||
public function translateType($type)
|
|
||||||
{
|
|
||||||
if (isset($this->classMap[$type])) {
|
|
||||||
return $this->classMap[$type];
|
|
||||||
}
|
|
||||||
|
|
||||||
return str_replace('\\', '.', $type);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function addBindingOperationHeader(\DOMElement $bindingOperation, array $headers, array $baseBinding)
|
|
||||||
{
|
|
||||||
foreach ($headers as $header) {
|
|
||||||
$inputNode = $bindingOperation->getElementsByTagName('input')->item(0);
|
|
||||||
|
|
||||||
$headerNode = $this->toDomDocument()->createElement('soap:header');
|
|
||||||
$headerNode->setAttribute('part', $header);
|
|
||||||
|
|
||||||
foreach ($baseBinding as $name => $value) {
|
|
||||||
$headerNode->setAttribute($name, $value);
|
|
||||||
}
|
|
||||||
|
|
||||||
$inputNode->appendChild($headerNode);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $bindingOperation;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,177 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* This file is part of the BeSimpleSoapBundle.
|
|
||||||
*
|
|
||||||
* (c) Christian Kerl <christian-kerl@web.de>
|
|
||||||
*
|
|
||||||
* This source file is subject to the MIT license that is bundled
|
|
||||||
* with this source code in the file LICENSE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace BeSimple\SoapBundle\ServiceDefinition\Dumper;
|
|
||||||
|
|
||||||
use BeSimple\SoapBundle\Converter\TypeRepository;
|
|
||||||
use BeSimple\SoapBundle\ServiceDefinition\Method;
|
|
||||||
use BeSimple\SoapBundle\ServiceDefinition\Type;
|
|
||||||
use BeSimple\SoapBundle\ServiceDefinition\ServiceDefinition;
|
|
||||||
use BeSimple\SoapBundle\ServiceDefinition\Loader\AnnotationComplexTypeLoader;
|
|
||||||
use BeSimple\SoapBundle\Util\Assert;
|
|
||||||
use BeSimple\SoapBundle\Util\QName;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Christian Kerl <christian-kerl@web.de>
|
|
||||||
*/
|
|
||||||
class WsdlDumper implements DumperInterface
|
|
||||||
{
|
|
||||||
private $loader;
|
|
||||||
private $typeRepository;
|
|
||||||
private $options;
|
|
||||||
|
|
||||||
private $wsdl;
|
|
||||||
private $definition;
|
|
||||||
|
|
||||||
public function __construct(AnnotationComplexTypeLoader $loader, TypeRepository $typeRepository, array $options)
|
|
||||||
{
|
|
||||||
$this->loader = $loader;
|
|
||||||
$this->typeRepository = $typeRepository;
|
|
||||||
$this->options = $options;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function dumpServiceDefinition(ServiceDefinition $definition, $endpoint)
|
|
||||||
{
|
|
||||||
Assert::thatArgumentNotNull('definition', $definition);
|
|
||||||
|
|
||||||
$this->definition = $definition;
|
|
||||||
$this->wsdl = new Wsdl($this->typeRepository, $definition->getName(), $definition->getNamespace(), new WsdlTypeStrategy($this->loader, $definition));
|
|
||||||
$port = $this->wsdl->addPortType($this->getPortTypeName());
|
|
||||||
$binding = $this->wsdl->addBinding($this->getBindingName(), $this->qualify($this->getPortTypeName()));
|
|
||||||
|
|
||||||
$this->wsdl->addSoapBinding($binding, 'rpc');
|
|
||||||
$this->wsdl->addService($this->getServiceName(), $this->getPortName(), $this->qualify($this->getBindingName()), $endpoint);
|
|
||||||
|
|
||||||
foreach ($definition->getMethods() as $method) {
|
|
||||||
$requestHeaderParts =
|
|
||||||
$requestParts =
|
|
||||||
$responseParts = array();
|
|
||||||
|
|
||||||
foreach ($method->getHeaders() as $header) {
|
|
||||||
$requestHeaderParts[$header->getName()] = $this->wsdl->getType($header->getType()->getPhpType());
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($method->getArguments() as $argument) {
|
|
||||||
$requestParts[$argument->getName()] = $this->wsdl->getType($argument->getType()->getPhpType());
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($method->getReturn() !== null) {
|
|
||||||
$responseParts['return'] = $this->wsdl->getType($method->getReturn()->getPhpType());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!empty($requestHeaderParts)) {
|
|
||||||
$this->wsdl->addMessage($this->getRequestHeaderMessageName($method), $requestHeaderParts);
|
|
||||||
}
|
|
||||||
$this->wsdl->addMessage($this->getRequestMessageName($method), $requestParts);
|
|
||||||
$this->wsdl->addMessage($this->getResponseMessageName($method), $responseParts);
|
|
||||||
|
|
||||||
$portOperation = $this->wsdl->addPortOperation(
|
|
||||||
$port,
|
|
||||||
$method->getName(),
|
|
||||||
$this->qualify($this->getRequestMessageName($method)),
|
|
||||||
$this->qualify($this->getResponseMessageName($method))
|
|
||||||
);
|
|
||||||
|
|
||||||
$baseBinding =
|
|
||||||
$inputBinding =
|
|
||||||
$outputBinding = array(
|
|
||||||
'use' => 'literal',
|
|
||||||
'namespace' => $definition->getNamespace(),
|
|
||||||
'encodingStyle' => 'http://schemas.xmlsoap.org/soap/encoding/',
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!empty($requestParts)) {
|
|
||||||
$portOperation->setAttribute('parameterOrder', implode(' ', array_keys($requestParts)));
|
|
||||||
|
|
||||||
$inputBinding['parts'] = implode(' ', array_keys($requestParts));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!empty($responseParts)) {
|
|
||||||
$outputBinding['parts'] = implode(' ', array_keys($responseParts));
|
|
||||||
}
|
|
||||||
|
|
||||||
$bindingOperation = $this->wsdl->addBindingOperation(
|
|
||||||
$binding,
|
|
||||||
$method->getName(),
|
|
||||||
$inputBinding,
|
|
||||||
$outputBinding
|
|
||||||
);
|
|
||||||
$bindingOperation = $this->wsdl->addBindingOperationHeader(
|
|
||||||
$bindingOperation,
|
|
||||||
array_keys($requestHeaderParts),
|
|
||||||
array_merge(array('message' => $this->qualify($this->getRequestHeaderMessageName($method))), $baseBinding)
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->wsdl->addSoapOperation($bindingOperation, $this->getSoapOperationName($method));
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->definition = null;
|
|
||||||
|
|
||||||
$dom = $this->wsdl->toDomDocument();
|
|
||||||
$dom->formatOutput = true;
|
|
||||||
|
|
||||||
if ($this->options['stylesheet']) {
|
|
||||||
$stylesheet = $dom->createProcessingInstruction('xml-stylesheet', sprintf('type="text/xsl" href="%s"', $this->options['stylesheet']));
|
|
||||||
|
|
||||||
$dom->insertBefore($stylesheet, $dom->documentElement);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->wsdl->toXml();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function qualify($name, $namespace = null)
|
|
||||||
{
|
|
||||||
if($namespace === null) {
|
|
||||||
$namespace = $this->definition->getNamespace();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->wsdl->toDomDocument()->lookupPrefix($namespace).':'.$name;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function getPortName()
|
|
||||||
{
|
|
||||||
return $this->definition->getName().'Port';
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function getPortTypeName()
|
|
||||||
{
|
|
||||||
return $this->definition->getName().'PortType';
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function getBindingName()
|
|
||||||
{
|
|
||||||
return $this->definition->getName().'Binding';
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function getServiceName()
|
|
||||||
{
|
|
||||||
return $this->definition->getName().'Service';
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function getRequestHeaderMessageName(Method $method)
|
|
||||||
{
|
|
||||||
return $method->getName().'Header';
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function getRequestMessageName(Method $method)
|
|
||||||
{
|
|
||||||
return $method->getName().'Request';
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function getResponseMessageName(Method $method)
|
|
||||||
{
|
|
||||||
return $method->getName().'Response';
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function getSoapOperationName(Method $method)
|
|
||||||
{
|
|
||||||
return $this->definition->getNamespace().$method->getName();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,95 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* This file is part of the BeSimpleSoapBundle.
|
|
||||||
*
|
|
||||||
* (c) Christian Kerl <christian-kerl@web.de>
|
|
||||||
*
|
|
||||||
* This source file is subject to the MIT license that is bundled
|
|
||||||
* with this source code in the file LICENSE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace BeSimple\SoapBundle\ServiceDefinition\Dumper;
|
|
||||||
|
|
||||||
use BeSimple\SoapBundle\ServiceDefinition\ServiceDefinition;
|
|
||||||
use BeSimple\SoapBundle\ServiceDefinition\Loader\AnnotationComplexTypeLoader;
|
|
||||||
use BeSimple\SoapBundle\ServiceDefinition\Strategy\ComplexType;
|
|
||||||
use BeSimple\SoapBundle\Util\String;
|
|
||||||
|
|
||||||
use Zend\Soap\Exception;
|
|
||||||
use Zend\Soap\Wsdl as BaseWsdl;
|
|
||||||
use Zend\Soap\Wsdl\ComplexTypeStrategy\ComplexTypeStrategyInterface;
|
|
||||||
use Zend\Soap\Wsdl\ComplexTypeStrategy\ArrayOfTypeSequence;
|
|
||||||
|
|
||||||
class WsdlTypeStrategy implements ComplexTypeStrategyInterface
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Context WSDL file
|
|
||||||
*
|
|
||||||
* @var \Zend\Soap\Wsdl|null
|
|
||||||
*/
|
|
||||||
private $context;
|
|
||||||
|
|
||||||
private $loader;
|
|
||||||
private $definition;
|
|
||||||
|
|
||||||
private $typeStrategy;
|
|
||||||
private $arrayStrategy;
|
|
||||||
|
|
||||||
public function __construct(AnnotationComplexTypeLoader $loader, ServiceDefinition $definition)
|
|
||||||
{
|
|
||||||
$this->loader = $loader;
|
|
||||||
$this->definition = $definition;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method accepts the current WSDL context file.
|
|
||||||
*
|
|
||||||
* @param \Zend\Soap\Wsdl $context
|
|
||||||
*/
|
|
||||||
public function setContext(BaseWsdl $context)
|
|
||||||
{
|
|
||||||
$this->context = $context;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a complex type based on a strategy
|
|
||||||
*
|
|
||||||
* @param string $type
|
|
||||||
*
|
|
||||||
* @return string XSD type
|
|
||||||
*
|
|
||||||
* @throws \Zend\Soap\WsdlException
|
|
||||||
*/
|
|
||||||
public function addComplexType($type)
|
|
||||||
{
|
|
||||||
if (!$this->context) {
|
|
||||||
throw new \LogicException(sprintf('Cannot add complex type "%s", no context is set for this composite strategy.', $type));
|
|
||||||
}
|
|
||||||
|
|
||||||
$strategy = String::endsWith($type, '[]') ? $this->getArrayStrategy() : $this->getTypeStrategy();
|
|
||||||
|
|
||||||
return $strategy->addComplexType($type);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function getArrayStrategy()
|
|
||||||
{
|
|
||||||
if (!$this->arrayStrategy) {
|
|
||||||
$this->arrayStrategy = new ArrayOfTypeSequence();
|
|
||||||
$this->arrayStrategy->setContext($this->context);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->arrayStrategy;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function getTypeStrategy()
|
|
||||||
{
|
|
||||||
if (!$this->typeStrategy) {
|
|
||||||
$this->typeStrategy = new ComplexType($this->loader, $this->definition);
|
|
||||||
$this->typeStrategy->setContext($this->context);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->typeStrategy;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,43 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* This file is part of the BeSimpleSoapBundle.
|
|
||||||
*
|
|
||||||
* (c) Christian Kerl <christian-kerl@web.de>
|
|
||||||
*
|
|
||||||
* This source file is subject to the MIT license that is bundled
|
|
||||||
* with this source code in the file LICENSE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace BeSimple\SoapBundle\ServiceDefinition;
|
|
||||||
|
|
||||||
class Header
|
|
||||||
{
|
|
||||||
private $name;
|
|
||||||
private $type;
|
|
||||||
|
|
||||||
public function __construct($name = null, Type $type = null)
|
|
||||||
{
|
|
||||||
$this->setName($name);
|
|
||||||
$this->setType($type);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getName()
|
|
||||||
{
|
|
||||||
return $this->name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setName($name)
|
|
||||||
{
|
|
||||||
$this->name = $name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getType()
|
|
||||||
{
|
|
||||||
return $this->type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setType($type)
|
|
||||||
{
|
|
||||||
$this->type = $type;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the BeSimpleSoapBundle.
|
* This file is part of the BeSimpleSoap.
|
||||||
*
|
*
|
||||||
* (c) Christian Kerl <christian-kerl@web.de>
|
* (c) Christian Kerl <christian-kerl@web.de>
|
||||||
* (c) Francis Besset <francis.besset@gmail.com>
|
* (c) Francis Besset <francis.besset@gmail.com>
|
||||||
@ -14,11 +14,10 @@ namespace BeSimple\SoapBundle\ServiceDefinition\Loader;
|
|||||||
|
|
||||||
use BeSimple\SoapBundle\ServiceDefinition as Definition;
|
use BeSimple\SoapBundle\ServiceDefinition as Definition;
|
||||||
use BeSimple\SoapBundle\ServiceDefinition\Annotation;
|
use BeSimple\SoapBundle\ServiceDefinition\Annotation;
|
||||||
|
use BeSimple\SoapCommon\Definition\Type\ComplexType;
|
||||||
|
use BeSimple\SoapCommon\Definition\Type\TypeRepository;
|
||||||
use Doctrine\Common\Annotations\Reader;
|
use Doctrine\Common\Annotations\Reader;
|
||||||
|
|
||||||
use Symfony\Component\Config\Loader\Loader;
|
use Symfony\Component\Config\Loader\Loader;
|
||||||
use Symfony\Component\Config\Loader\LoaderResolverInterface;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AnnotationClassLoader loads ServiceDefinition from a PHP class and its methods.
|
* AnnotationClassLoader loads ServiceDefinition from a PHP class and its methods.
|
||||||
@ -26,19 +25,23 @@ use Symfony\Component\Config\Loader\LoaderResolverInterface;
|
|||||||
* Based on \Symfony\Component\Routing\Loader\AnnotationClassLoader
|
* Based on \Symfony\Component\Routing\Loader\AnnotationClassLoader
|
||||||
*
|
*
|
||||||
* @author Christian Kerl <christian-kerl@web.de>
|
* @author Christian Kerl <christian-kerl@web.de>
|
||||||
|
* @author Francis Besset <francis.besset@gmail.com>
|
||||||
*/
|
*/
|
||||||
class AnnotationClassLoader extends Loader
|
class AnnotationClassLoader extends Loader
|
||||||
{
|
{
|
||||||
protected $reader;
|
protected $reader;
|
||||||
|
|
||||||
|
protected $typeRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @param \Doctrine\Common\Annotations\Reader $reader
|
* @param \Doctrine\Common\Annotations\Reader $reader
|
||||||
*/
|
*/
|
||||||
public function __construct(Reader $reader)
|
public function __construct(Reader $reader, TypeRepository $typeRepository)
|
||||||
{
|
{
|
||||||
$this->reader = $reader;
|
$this->reader = $reader;
|
||||||
|
$this->typeRepository = $typeRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -58,39 +61,26 @@ class AnnotationClassLoader extends Loader
|
|||||||
}
|
}
|
||||||
|
|
||||||
$class = new \ReflectionClass($class);
|
$class = new \ReflectionClass($class);
|
||||||
$definition = new Definition\ServiceDefinition();
|
$definition = new Definition\Definition($this->typeRepository);
|
||||||
|
|
||||||
$serviceMethodHeaders = array();
|
$sharedHeaders = array();
|
||||||
foreach ($this->reader->getClassAnnotations($class) as $annotation) {
|
foreach ($this->reader->getClassAnnotations($class) as $annotation) {
|
||||||
if ($annotation instanceof Annotation\Header) {
|
if ($annotation instanceof Annotation\Header) {
|
||||||
$serviceMethodHeaders[$annotation->getValue()] = $annotation;
|
$sharedHeaders[$annotation->getValue()] = $this->loadType($annotation->getPhpType());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($class->getMethods() as $method) {
|
foreach ($class->getMethods() as $method) {
|
||||||
$serviceArguments =
|
$serviceHeaders = $sharedHeaders;
|
||||||
$serviceHeaders = array();
|
$serviceArguments = array();
|
||||||
$serviceMethod =
|
$serviceMethod =
|
||||||
$serviceReturn = null;
|
$serviceReturn = null;
|
||||||
|
|
||||||
foreach ($serviceMethodHeaders as $annotation) {
|
|
||||||
$serviceHeaders[$annotation->getValue()] = new Definition\Header(
|
|
||||||
$annotation->getValue(),
|
|
||||||
$this->getArgumentType($method, $annotation)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($this->reader->getMethodAnnotations($method) as $annotation) {
|
foreach ($this->reader->getMethodAnnotations($method) as $annotation) {
|
||||||
if ($annotation instanceof Annotation\Header) {
|
if ($annotation instanceof Annotation\Header) {
|
||||||
$serviceHeaders[$annotation->getValue()] = new Definition\Header(
|
$serviceHeaders[$annotation->getValue()] = $this->loadType($annotation->getPhpType());
|
||||||
$annotation->getValue(),
|
|
||||||
$this->getArgumentType($method, $annotation)
|
|
||||||
);
|
|
||||||
} elseif ($annotation instanceof Annotation\Param) {
|
} elseif ($annotation instanceof Annotation\Param) {
|
||||||
$serviceArguments[] = new Definition\Argument(
|
$serviceArguments[$annotation->getValue()] = $this->loadType($annotation->getPhpType());
|
||||||
$annotation->getValue(),
|
|
||||||
$this->getArgumentType($method, $annotation)
|
|
||||||
);
|
|
||||||
} elseif ($annotation instanceof Annotation\Method) {
|
} elseif ($annotation instanceof Annotation\Method) {
|
||||||
if ($serviceMethod) {
|
if ($serviceMethod) {
|
||||||
throw new \LogicException(sprintf('@Soap\Method defined twice for "%s".', $method->getName()));
|
throw new \LogicException(sprintf('@Soap\Method defined twice for "%s".', $method->getName()));
|
||||||
@ -105,7 +95,8 @@ class AnnotationClassLoader extends Loader
|
|||||||
throw new \LogicException(sprintf('@Soap\Result defined twice for "%s".', $method->getName()));
|
throw new \LogicException(sprintf('@Soap\Result defined twice for "%s".', $method->getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
$serviceReturn = new Definition\Type($annotation->getPhpType(), $annotation->getXmlType());
|
$serviceReturn = $annotation->getPhpType();
|
||||||
|
$serviceXmlReturn = $annotation->getXmlType();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,16 +105,25 @@ class AnnotationClassLoader extends Loader
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($serviceMethod) {
|
if ($serviceMethod) {
|
||||||
$serviceMethod->setArguments($serviceArguments);
|
foreach ($serviceHeaders as $name => $type) {
|
||||||
$serviceMethod->setHeaders($serviceHeaders);
|
$serviceMethod->addHeader($name, $type);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($serviceArguments as $name => $type) {
|
||||||
|
$serviceMethod->addInput($name, $type);
|
||||||
|
}
|
||||||
|
|
||||||
if (!$serviceReturn) {
|
if (!$serviceReturn) {
|
||||||
throw new \LogicException(sprintf('@Soap\Result non-existent for "%s".', $method->getName()));
|
throw new \LogicException(sprintf('@Soap\Result non-existent for "%s".', $method->getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
$serviceMethod->setReturn($serviceReturn);
|
if (!isset($serviceXmlReturn) || !$serviceXmlReturn) {
|
||||||
|
$serviceXmlReturn = 'return';
|
||||||
|
}
|
||||||
|
|
||||||
$definition->getMethods()->add($serviceMethod);
|
$serviceMethod->setOutput($this->loadType($serviceReturn), $serviceXmlReturn);
|
||||||
|
|
||||||
|
$definition->addMethod($serviceMethod);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,28 +145,28 @@ class AnnotationClassLoader extends Loader
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private function loadType($phpType)
|
||||||
* @param \ReflectionMethod $method
|
|
||||||
* @param \BeSimple\SoapBundle\ServiceDefinition\Annotation\Param $annotation
|
|
||||||
*
|
|
||||||
* @return \BeSimple\SoapBundle\ServiceDefinition\Type
|
|
||||||
*/
|
|
||||||
private function getArgumentType(\ReflectionMethod $method, Annotation\Param $annotation)
|
|
||||||
{
|
{
|
||||||
$phpType = $annotation->getPhpType();
|
if (false !== $arrayOf = $this->typeRepository->getArrayOf($phpType)) {
|
||||||
$xmlType = $annotation->getXmlType();
|
$this->loadType($arrayOf);
|
||||||
|
|
||||||
if (null === $phpType) {
|
|
||||||
foreach ($method->getParameters() as $param) {
|
|
||||||
if ($param->name === $annotation->getName()) {
|
|
||||||
$phpType = $param->getClass()->name;
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Definition\Type($phpType, $xmlType);
|
if (!$this->typeRepository->hasType($phpType)) {
|
||||||
|
$complexTypeResolver = $this->resolve($phpType, 'annotation_complextype');
|
||||||
|
if (!$complexTypeResolver) {
|
||||||
|
throw new \Exception();
|
||||||
|
}
|
||||||
|
|
||||||
|
$loaded = $complexTypeResolver->load($phpType);
|
||||||
|
$complexType = new ComplexType($phpType, isset($loaded['alias']) ? $loaded['alias'] : $phpType);
|
||||||
|
foreach ($loaded['properties'] as $name => $property) {
|
||||||
|
$complexType->add($name, $this->loadType($property->getValue()), $property->isNillable(), $property->getMinOccurs());
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->typeRepository->addComplexType($complexType);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $phpType;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the BeSimpleSoapBundle.
|
* This file is part of the BeSimpleSoap.
|
||||||
*
|
*
|
||||||
* (c) Christian Kerl <christian-kerl@web.de>
|
* (c) Christian Kerl <christian-kerl@web.de>
|
||||||
* (c) Francis Besset <francis.besset@gmail.com>
|
* (c) Francis Besset <francis.besset@gmail.com>
|
||||||
@ -43,7 +43,7 @@ class AnnotationComplexTypeLoader extends AnnotationClassLoader
|
|||||||
throw new \InvalidArgumentException(sprintf('Class "%s" does not exist.', $class));
|
throw new \InvalidArgumentException(sprintf('Class "%s" does not exist.', $class));
|
||||||
}
|
}
|
||||||
|
|
||||||
$annotations = array();
|
$annotations = [];
|
||||||
|
|
||||||
$class = new \ReflectionClass($class);
|
$class = new \ReflectionClass($class);
|
||||||
if ($alias = $this->reader->getClassAnnotation($class, $this->aliasClass)) {
|
if ($alias = $this->reader->getClassAnnotation($class, $this->aliasClass)) {
|
||||||
@ -59,10 +59,24 @@ class AnnotationComplexTypeLoader extends AnnotationClassLoader
|
|||||||
$propertyComplexType->setValue($complexType->getValue());
|
$propertyComplexType->setValue($complexType->getValue());
|
||||||
$propertyComplexType->setNillable($complexType->isNillable());
|
$propertyComplexType->setNillable($complexType->isNillable());
|
||||||
$propertyComplexType->setName($property->getName());
|
$propertyComplexType->setName($property->getName());
|
||||||
|
$propertyComplexType->setMinOccurs($complexType->getMinOccurs());
|
||||||
$annotations['properties']->add($propertyComplexType);
|
$annotations['properties']->add($propertyComplexType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $annotations;
|
return $annotations;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if this class supports the given resource.
|
||||||
|
*
|
||||||
|
* @param mixed $resource A resource
|
||||||
|
* @param string $type The resource type
|
||||||
|
*
|
||||||
|
* @return bool True if this class supports the given resource, false otherwise
|
||||||
|
*/
|
||||||
|
public function supports($resource, $type = null)
|
||||||
|
{
|
||||||
|
return is_string($resource) && class_exists($resource) && 'annotation_complextype' === $type;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the BeSimpleSoapBundle.
|
* This file is part of the BeSimpleSoap.
|
||||||
*
|
*
|
||||||
* (c) Christian Kerl <christian-kerl@web.de>
|
* (c) Christian Kerl <christian-kerl@web.de>
|
||||||
* (c) Francis Besset <francis.besset@gmail.com>
|
* (c) Francis Besset <francis.besset@gmail.com>
|
||||||
@ -16,7 +16,6 @@ use BeSimple\SoapBundle\ServiceDefinition\ServiceDefinition;
|
|||||||
|
|
||||||
use Symfony\Component\Config\FileLocator;
|
use Symfony\Component\Config\FileLocator;
|
||||||
use Symfony\Component\Config\Loader\FileLoader;
|
use Symfony\Component\Config\Loader\FileLoader;
|
||||||
use Symfony\Component\Config\Resource\FileResource;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AnnotationFileLoader loads ServiceDefinition from annotations set
|
* AnnotationFileLoader loads ServiceDefinition from annotations set
|
||||||
@ -62,7 +61,7 @@ class AnnotationFileLoader extends FileLoader
|
|||||||
$path = $this->locator->locate($file);
|
$path = $this->locator->locate($file);
|
||||||
|
|
||||||
if ($class = $this->findClass($path)) {
|
if ($class = $this->findClass($path)) {
|
||||||
return $definition = $this->loader->load($class, $type);
|
return $this->loader->load($class, $type);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
@ -1,145 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of the BeSimpleSoapBundle.
|
|
||||||
*
|
|
||||||
* (c) Christian Kerl <christian-kerl@web.de>
|
|
||||||
* (c) Francis Besset <francis.besset@gmail.com>
|
|
||||||
*
|
|
||||||
* This source file is subject to the MIT license that is bundled
|
|
||||||
* with this source code in the file LICENSE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace BeSimple\SoapBundle\ServiceDefinition\Loader;
|
|
||||||
|
|
||||||
use BeSimple\SoapBundle\ServiceDefinition\Argument;
|
|
||||||
use BeSimple\SoapBundle\ServiceDefinition\Header;
|
|
||||||
use BeSimple\SoapBundle\ServiceDefinition\Method;
|
|
||||||
use BeSimple\SoapBundle\ServiceDefinition\Type;
|
|
||||||
use BeSimple\SoapBundle\ServiceDefinition\ServiceDefinition;
|
|
||||||
|
|
||||||
use Symfony\Component\Config\Loader\FileLoader;
|
|
||||||
|
|
||||||
class XmlFileLoader extends FileLoader
|
|
||||||
{
|
|
||||||
public function supports($resource, $type = null)
|
|
||||||
{
|
|
||||||
return is_string($resource) && 'xml' === pathinfo($resource, PATHINFO_EXTENSION);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function load($file, $type = null)
|
|
||||||
{
|
|
||||||
$path = $this->locator->locate($file);
|
|
||||||
$xml = $this->parseFile($path);
|
|
||||||
|
|
||||||
$definition = new ServiceDefinition();
|
|
||||||
$definition->setName((string) $xml['name']);
|
|
||||||
$definition->setNamespace((string) $xml['namespace']);
|
|
||||||
|
|
||||||
foreach($xml->header as $header) {
|
|
||||||
$definition->getHeaders()->add($this->parseHeader($header));
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach($xml->method as $method) {
|
|
||||||
$definition->getMethods()->add($this->parseMethod($method));
|
|
||||||
}
|
|
||||||
|
|
||||||
return $definition;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param \SimpleXMLElement $node
|
|
||||||
*
|
|
||||||
* @return \BeSimple\SoapBundle\ServiceDefinition\Header
|
|
||||||
*/
|
|
||||||
protected function parseHeader(\SimpleXMLElement $node)
|
|
||||||
{
|
|
||||||
return new Header((string)$node['name'], $this->parseType($node->type));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param \SimpleXMLElement $node
|
|
||||||
*
|
|
||||||
* @return \BeSimple\SoapBundle\ServiceDefinition\Method
|
|
||||||
*/
|
|
||||||
protected function parseMethod(\SimpleXMLElement $node)
|
|
||||||
{
|
|
||||||
$method = new Method((string)$node['name'], (string)$node['controller']);
|
|
||||||
|
|
||||||
foreach($node->argument as $argument) {
|
|
||||||
$method->getArguments()->add($this->parseArgument($argument));
|
|
||||||
}
|
|
||||||
|
|
||||||
$method->setReturn($this->parseType($node->return->type));
|
|
||||||
|
|
||||||
return $method;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param \SimpleXMLElement $node
|
|
||||||
*
|
|
||||||
* @return \BeSimple\SoapBundle\ServiceDefinition\Argument
|
|
||||||
*/
|
|
||||||
protected function parseArgument(\SimpleXMLElement $node)
|
|
||||||
{
|
|
||||||
$argument = new Argument((string)$node['name'], $this->parseType($node->type));
|
|
||||||
|
|
||||||
return $argument;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param \SimpleXMLElement $node
|
|
||||||
*
|
|
||||||
* @return \BeSimple\SoapBundle\ServiceDefinition\Type
|
|
||||||
*/
|
|
||||||
protected function parseType(\SimpleXMLElement $node)
|
|
||||||
{
|
|
||||||
$namespaces = $node->getDocNamespaces(true);
|
|
||||||
$qname = explode(':', $node['xml-type'], 2);
|
|
||||||
$xmlType = sprintf('{%s}%s', $namespaces[$qname[0]], $qname[1]);
|
|
||||||
|
|
||||||
return new Type((string)$node['php-type'], $xmlType, (string)$node['converter']);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $file
|
|
||||||
*
|
|
||||||
* @return \SimpleXMLElement
|
|
||||||
*/
|
|
||||||
protected function parseFile($file)
|
|
||||||
{
|
|
||||||
$dom = new \DOMDocument();
|
|
||||||
libxml_use_internal_errors(true);
|
|
||||||
if (!$dom->load($file, LIBXML_COMPACT)) {
|
|
||||||
throw new \InvalidArgumentException(implode("\n", $this->getXmlErrors()));
|
|
||||||
}
|
|
||||||
if (!$dom->schemaValidate(__DIR__.'/schema/servicedefinition-1.0.xsd')) {
|
|
||||||
throw new \InvalidArgumentException(implode("\n", $this->getXmlErrors()));
|
|
||||||
}
|
|
||||||
$dom->validateOnParse = true;
|
|
||||||
$dom->normalizeDocument();
|
|
||||||
libxml_use_internal_errors(false);
|
|
||||||
|
|
||||||
return simplexml_import_dom($dom);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function getXmlErrors()
|
|
||||||
{
|
|
||||||
$errors = array();
|
|
||||||
foreach (libxml_get_errors() as $error) {
|
|
||||||
$errors[] = sprintf('[%s %s] %s (in %s - line %d, column %d)',
|
|
||||||
LIBXML_ERR_WARNING == $error->level ? 'WARNING' : 'ERROR',
|
|
||||||
$error->code,
|
|
||||||
trim($error->message),
|
|
||||||
$error->file ? $error->file : 'n/a',
|
|
||||||
$error->line,
|
|
||||||
$error->column
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
libxml_clear_errors();
|
|
||||||
libxml_use_internal_errors(false);
|
|
||||||
|
|
||||||
return $errors;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,8 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the BeSimpleSoapBundle.
|
* This file is part of the BeSimpleSoap.
|
||||||
*
|
*
|
||||||
* (c) Christian Kerl <christian-kerl@web.de>
|
* (c) Christian Kerl <christian-kerl@web.de>
|
||||||
|
* (c) Francis Besset <francis.besset@gmail.com>
|
||||||
*
|
*
|
||||||
* This source file is subject to the MIT license that is bundled
|
* This source file is subject to the MIT license that is bundled
|
||||||
* with this source code in the file LICENSE.
|
* with this source code in the file LICENSE.
|
||||||
@ -10,36 +12,22 @@
|
|||||||
|
|
||||||
namespace BeSimple\SoapBundle\ServiceDefinition;
|
namespace BeSimple\SoapBundle\ServiceDefinition;
|
||||||
|
|
||||||
use BeSimple\SoapBundle\Util\Collection;
|
use BeSimple\SoapCommon\Definition\Method as BaseMethod;
|
||||||
|
use BeSimple\SoapCommon\Definition\Type\TypeRepository;
|
||||||
|
|
||||||
class Method
|
/**
|
||||||
|
* @author Christian Kerl <christian-kerl@web.de>
|
||||||
|
* @author Francis Besset <francis.besset@gmail.com>
|
||||||
|
*/
|
||||||
|
class Method extends BaseMethod
|
||||||
{
|
{
|
||||||
private $name;
|
|
||||||
private $controller;
|
private $controller;
|
||||||
private $arguments;
|
|
||||||
private $headers;
|
|
||||||
private $return;
|
|
||||||
|
|
||||||
public function __construct($name = null, $controller = null, array $headers = array(), array $arguments = array(), Type $return = null)
|
public function __construct($name, $controller)
|
||||||
{
|
{
|
||||||
$this->setName($name);
|
parent::__construct($name);
|
||||||
$this->setController($controller);
|
|
||||||
$this->setHeaders($headers);
|
|
||||||
$this->setArguments($arguments);
|
|
||||||
|
|
||||||
if ($return) {
|
$this->controller = $controller;
|
||||||
$this->setReturn($return);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getName()
|
|
||||||
{
|
|
||||||
return $this->name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setName($name)
|
|
||||||
{
|
|
||||||
$this->name = $name;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getController()
|
public function getController()
|
||||||
@ -47,40 +35,8 @@ class Method
|
|||||||
return $this->controller;
|
return $this->controller;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setController($controller)
|
public function getVersions()
|
||||||
{
|
{
|
||||||
$this->controller = $controller;
|
return array(\SOAP_1_1);
|
||||||
}
|
|
||||||
|
|
||||||
public function getHeaders()
|
|
||||||
{
|
|
||||||
return $this->headers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setHeaders(array $headers)
|
|
||||||
{
|
|
||||||
$this->headers = new Collection('getName', 'BeSimple\SoapBundle\ServiceDefinition\Header');
|
|
||||||
$this->headers->addAll($headers);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getArguments()
|
|
||||||
{
|
|
||||||
return $this->arguments;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setArguments(array $arguments)
|
|
||||||
{
|
|
||||||
$this->arguments = new Collection('getName', 'BeSimple\SoapBundle\ServiceDefinition\Argument');
|
|
||||||
$this->arguments->addAll($arguments);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getReturn()
|
|
||||||
{
|
|
||||||
return $this->return;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setReturn(Type $return)
|
|
||||||
{
|
|
||||||
$this->return = $return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,151 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* This file is part of the BeSimpleSoapBundle.
|
|
||||||
*
|
|
||||||
* (c) Christian Kerl <christian-kerl@web.de>
|
|
||||||
*
|
|
||||||
* This source file is subject to the MIT license that is bundled
|
|
||||||
* with this source code in the file LICENSE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace BeSimple\SoapBundle\ServiceDefinition;
|
|
||||||
|
|
||||||
use BeSimple\SoapBundle\Util\Collection;
|
|
||||||
use BeSimple\SoapCommon\Classmap;
|
|
||||||
|
|
||||||
class ServiceDefinition
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private $name;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private $namespace;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var \BeSimple\SoapBundle\Util\Collection
|
|
||||||
*/
|
|
||||||
private $methods;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var \BeSimple\SoapCommon\Classmap
|
|
||||||
*/
|
|
||||||
private $classmap;
|
|
||||||
|
|
||||||
private $complexTypes = array();
|
|
||||||
|
|
||||||
public function __construct($name = null, $namespace = null, array $methods = array(), Classmap $classmap = null)
|
|
||||||
{
|
|
||||||
$this->setName($name);
|
|
||||||
$this->setNamespace($namespace);
|
|
||||||
|
|
||||||
$this->methods = new Collection('getName', 'BeSimple\SoapBundle\ServiceDefinition\Method');
|
|
||||||
$this->setMethods($methods);
|
|
||||||
|
|
||||||
$this->classmap = $classmap;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getName()
|
|
||||||
{
|
|
||||||
return $this->name;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $name
|
|
||||||
*/
|
|
||||||
public function setName($name)
|
|
||||||
{
|
|
||||||
$this->name = $name;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getNamespace()
|
|
||||||
{
|
|
||||||
return $this->namespace;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $namespace
|
|
||||||
*/
|
|
||||||
public function setNamespace($namespace)
|
|
||||||
{
|
|
||||||
$this->namespace = $namespace;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return \BeSimple\SoapBundle\Util\Collection
|
|
||||||
*/
|
|
||||||
public function getMethods()
|
|
||||||
{
|
|
||||||
return $this->methods;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array $methods
|
|
||||||
*/
|
|
||||||
public function setMethods(array $methods)
|
|
||||||
{
|
|
||||||
$this->methods->addAll($methods);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getAllTypes()
|
|
||||||
{
|
|
||||||
$types = array();
|
|
||||||
|
|
||||||
foreach ($this->methods as $method) {
|
|
||||||
foreach ($method->getArguments() as $argument) {
|
|
||||||
$types[] = $argument->getType();
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($method->getHeaders() as $header) {
|
|
||||||
$types[] = $header->getType();
|
|
||||||
}
|
|
||||||
|
|
||||||
$types[] = $method->getReturn();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $types;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getClassmap()
|
|
||||||
{
|
|
||||||
return $this->classmap ?: array();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setClassmap(Classmap $classmap)
|
|
||||||
{
|
|
||||||
$this->classmap = $classmap;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function hasDefinitionComplexType($type)
|
|
||||||
{
|
|
||||||
return isset($this->complexTypes[$type]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function addDefinitionComplexType($type, array $definition)
|
|
||||||
{
|
|
||||||
if ($this->hasDefinitionComplexType($type)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->complexTypes[$type] = $definition;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getDefinitionComplexTypes()
|
|
||||||
{
|
|
||||||
return $this->complexTypes;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,89 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of the BeSimpleSoapBundle.
|
|
||||||
*
|
|
||||||
* (c) Christian Kerl <christian-kerl@web.de>
|
|
||||||
* (c) Francis Besset <francis.besset@gmail.com>
|
|
||||||
*
|
|
||||||
* This source file is subject to the MIT license that is bundled
|
|
||||||
* with this source code in the file LICENSE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace BeSimple\SoapBundle\ServiceDefinition\Strategy;
|
|
||||||
|
|
||||||
use BeSimple\SoapBundle\ServiceDefinition\Loader\AnnotationComplexTypeLoader;
|
|
||||||
use Zend\Soap\Wsdl;
|
|
||||||
use Zend\Soap\Wsdl\ComplexTypeStrategy\AbstractComplexTypeStrategy;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Francis Besset <francis.besset@gmail.com>
|
|
||||||
*/
|
|
||||||
class ComplexType extends AbstractComplexTypeStrategy
|
|
||||||
{
|
|
||||||
private $loader;
|
|
||||||
private $definition;
|
|
||||||
|
|
||||||
public function __construct(AnnotationComplexTypeLoader $loader, $definition)
|
|
||||||
{
|
|
||||||
$this->loader = $loader;
|
|
||||||
$this->definition = $definition;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a complex type by recursivly using all the class properties fetched via Reflection.
|
|
||||||
*
|
|
||||||
* @param string $type Name of the class to be specified
|
|
||||||
* @return string XSD Type for the given PHP type
|
|
||||||
*/
|
|
||||||
public function addComplexType($classname)
|
|
||||||
{
|
|
||||||
$classmap = $this->definition->getClassmap();
|
|
||||||
if ($classmap->hasByClassname($classname)) {
|
|
||||||
return 'tns:'.$classmap->getByClassname($classname);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$this->loader->supports($classname)) {
|
|
||||||
throw new \InvalidArgumentException(sprintf('Cannot add ComplexType "%s" because it is not an object or the class could not be found.', $classname));
|
|
||||||
}
|
|
||||||
|
|
||||||
$definitionComplexType = $this->loader->load($classname);
|
|
||||||
$classnameAlias = isset($definitionComplexType['alias']) ? $definitionComplexType['alias'] : $classname;
|
|
||||||
|
|
||||||
$type = $this->getContext()->translateType($classnameAlias);
|
|
||||||
$xmlType = 'tns:'.$type;
|
|
||||||
|
|
||||||
// Register type here to avoid recursion
|
|
||||||
$classmap->add($type, $classname);
|
|
||||||
$this->addXmlDefinition($definitionComplexType, $classname, $type);
|
|
||||||
|
|
||||||
return $xmlType;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function addXmlDefinition(array $definitionComplexType, $classname, $type)
|
|
||||||
{
|
|
||||||
$dom = $this->getContext()->toDomDocument();
|
|
||||||
$complexType = $dom->createElement('xsd:complexType');
|
|
||||||
$complexType->setAttribute('name', $type);
|
|
||||||
|
|
||||||
$all = $dom->createElement('xsd:all');
|
|
||||||
|
|
||||||
$elements = array();
|
|
||||||
foreach ($definitionComplexType['properties'] as $property) {
|
|
||||||
$element = $dom->createElement('xsd:element');
|
|
||||||
$element->setAttribute('name', $property->getName());
|
|
||||||
$element->setAttribute('type', $this->getContext()->getType($property->getValue()));
|
|
||||||
|
|
||||||
if ($property->isNillable()) {
|
|
||||||
$element->setAttribute('nillable', 'true');
|
|
||||||
}
|
|
||||||
|
|
||||||
$all->appendChild($element);
|
|
||||||
}
|
|
||||||
|
|
||||||
$complexType->appendChild($all);
|
|
||||||
$this->getContext()->getSchema()->appendChild($complexType);
|
|
||||||
|
|
||||||
$this->definition->addDefinitionComplexType($classname, $definitionComplexType);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,60 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* This file is part of the BeSimpleSoapBundle.
|
|
||||||
*
|
|
||||||
* (c) Christian Kerl <christian-kerl@web.de>
|
|
||||||
*
|
|
||||||
* This source file is subject to the MIT license that is bundled
|
|
||||||
* with this source code in the file LICENSE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace BeSimple\SoapBundle\ServiceDefinition;
|
|
||||||
|
|
||||||
class Type
|
|
||||||
{
|
|
||||||
private $phpType;
|
|
||||||
private $xmlType;
|
|
||||||
private $converter;
|
|
||||||
|
|
||||||
public function __construct($phpType = null, $xmlType = null, $converter = null)
|
|
||||||
{
|
|
||||||
$this->setPhpType($phpType);
|
|
||||||
$this->setXmlType($xmlType);
|
|
||||||
$this->setConverter($converter);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getPhpType()
|
|
||||||
{
|
|
||||||
return $this->phpType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setPhpType($phpType)
|
|
||||||
{
|
|
||||||
$phpType = $phpType;
|
|
||||||
if ($phpType[0] == '\\') {
|
|
||||||
$phpType = substr($phpType, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->phpType = $phpType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getXmlType()
|
|
||||||
{
|
|
||||||
return $this->xmlType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setXmlType($xmlType)
|
|
||||||
{
|
|
||||||
$this->xmlType = $xmlType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getConverter()
|
|
||||||
{
|
|
||||||
return $this->converter;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setConverter($converter)
|
|
||||||
{
|
|
||||||
$this->converter = $converter;
|
|
||||||
}
|
|
||||||
}
|
|
@ -11,11 +11,8 @@
|
|||||||
namespace BeSimple\SoapBundle\Soap;
|
namespace BeSimple\SoapBundle\Soap;
|
||||||
|
|
||||||
use BeSimple\SoapBundle\Util\Collection;
|
use BeSimple\SoapBundle\Util\Collection;
|
||||||
|
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Laminas\Mime\Message;
|
||||||
use Zend\Mime\Mime;
|
|
||||||
use Zend\Mime\Message;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SoapRequest.
|
* SoapRequest.
|
||||||
|
@ -16,66 +16,70 @@ use BeSimple\SoapBundle\ServiceBinding\RpcLiteralRequestMessageBinder;
|
|||||||
use BeSimple\SoapBundle\ServiceDefinition as Definition;
|
use BeSimple\SoapBundle\ServiceDefinition as Definition;
|
||||||
use BeSimple\SoapBundle\Tests\fixtures\ServiceBinding as Fixtures;
|
use BeSimple\SoapBundle\Tests\fixtures\ServiceBinding as Fixtures;
|
||||||
use BeSimple\SoapBundle\Util\Collection;
|
use BeSimple\SoapBundle\Util\Collection;
|
||||||
|
use BeSimple\SoapCommon\Definition\Type\ComplexType;
|
||||||
|
use BeSimple\SoapCommon\Definition\Type\TypeRepository;
|
||||||
|
|
||||||
class RpcLiteralRequestMessageBinderTest extends \PHPUnit_Framework_TestCase
|
class RpcLiteralRequestMessageBinderTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @dataProvider messageProvider
|
* @dataProvider messageProvider
|
||||||
*/
|
*/
|
||||||
public function testProcessMessage(Definition\Method $method, $message, $assert)
|
public function testProcessMessage(Definition\Method $method, array $message, array $assert)
|
||||||
{
|
{
|
||||||
$messageBinder = new RpcLiteralRequestMessageBinder();
|
$messageBinder = new RpcLiteralRequestMessageBinder();
|
||||||
$result = $messageBinder->processMessage($method, $message);
|
$result = $messageBinder->processMessage($method, $message, $this->getTypeRepository());
|
||||||
|
|
||||||
$this->assertSame($assert, $result);
|
$this->assertSame($assert, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testProcessMessageWithComplexType()
|
public function testProcessMessageWithComplexType()
|
||||||
{
|
{
|
||||||
|
$typeRepository = $this->addComplexTypes($this->getTypeRepository());
|
||||||
$messageBinder = new RpcLiteralRequestMessageBinder();
|
$messageBinder = new RpcLiteralRequestMessageBinder();
|
||||||
|
|
||||||
|
$method = new Definition\Method('complextype_argument', null);
|
||||||
|
$method->addInput('foo', 'BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\Foo');
|
||||||
|
|
||||||
$foo = new Fixtures\Foo('foobar', 19395);
|
$foo = new Fixtures\Foo('foobar', 19395);
|
||||||
$result = $messageBinder->processMessage(
|
$result = $messageBinder->processMessage(
|
||||||
new Definition\Method('complextype_argument', null, array(), array(
|
$method,
|
||||||
new Definition\Argument('foo', new Definition\Type('BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\Foo')),
|
|
||||||
)),
|
|
||||||
array($foo),
|
array($foo),
|
||||||
$this->getDefinitionComplexTypes()
|
$typeRepository
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals(array('foo' => $foo), $result);
|
$this->assertEquals(array('foo' => $foo), $result);
|
||||||
|
|
||||||
|
|
||||||
$foo1 = new Fixtures\Foo('foobar', 29291);
|
$foo1 = new Fixtures\Foo('foobar', 29291);
|
||||||
$foo2 = new Fixtures\Foo('barfoo', 39392);
|
$foo2 = new Fixtures\Foo('barfoo', 39392);
|
||||||
$foos = new \stdClass();
|
$foos = new \stdClass();
|
||||||
$foos->item = array($foo1, $foo2);
|
$foos->item = array($foo1, $foo2);
|
||||||
|
|
||||||
|
$method = new Definition\Method('complextype_argument', null);
|
||||||
|
$method->addInput('foos', 'BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\Foo[]');
|
||||||
|
|
||||||
$result = $messageBinder->processMessage(
|
$result = $messageBinder->processMessage(
|
||||||
new Definition\Method('complextype_argument', null, array(), array(
|
$method,
|
||||||
new Definition\Argument('foos', new Definition\Type('BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\Foo[]')),
|
|
||||||
)),
|
|
||||||
array($foos),
|
array($foos),
|
||||||
$this->getDefinitionComplexTypes()
|
$typeRepository
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals(array('foos' => array($foo1, $foo2)), $result);
|
$this->assertEquals(array('foos' => array($foo1, $foo2)), $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException SoapFault
|
|
||||||
*/
|
|
||||||
public function testProcessMessageSoapFault()
|
public function testProcessMessageSoapFault()
|
||||||
{
|
{
|
||||||
$messageBinder = new RpcLiteralRequestMessageBinder();
|
$messageBinder = new RpcLiteralRequestMessageBinder();
|
||||||
|
|
||||||
|
$method = new Definition\Method('complextype_argument', null);
|
||||||
|
$method->addInput('foo', 'BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\Foo');
|
||||||
|
|
||||||
$foo = new Fixtures\Foo('foo', null);
|
$foo = new Fixtures\Foo('foo', null);
|
||||||
$result = $messageBinder->processMessage(
|
|
||||||
new Definition\Method('complextype_argument', null, array(), array(
|
$this->setExpectedException('SoapFault');
|
||||||
new Definition\Argument('foo', new Definition\Type('BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\Foo')),
|
$messageBinder->processMessage(
|
||||||
)),
|
$method,
|
||||||
array($foo),
|
array($foo),
|
||||||
$this->getDefinitionComplexTypes()
|
$this->addComplexTypes($this->getTypeRepository())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,16 +87,17 @@ class RpcLiteralRequestMessageBinderTest extends \PHPUnit_Framework_TestCase
|
|||||||
{
|
{
|
||||||
$messageBinder = new RpcLiteralRequestMessageBinder();
|
$messageBinder = new RpcLiteralRequestMessageBinder();
|
||||||
|
|
||||||
|
$method = new Definition\Method('complextype_argument', null);
|
||||||
|
$method->addInput('foos', 'BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\Foo[]');
|
||||||
|
|
||||||
$foo = new Fixtures\Foo('foo', 2499104);
|
$foo = new Fixtures\Foo('foo', 2499104);
|
||||||
$foos = new \stdClass();
|
$foos = new \stdClass();
|
||||||
$foos->item = array($foo, $foo);
|
$foos->item = array($foo, $foo);
|
||||||
|
|
||||||
$result = $messageBinder->processMessage(
|
$result = $messageBinder->processMessage(
|
||||||
new Definition\Method('complextype_argument', null, array(), array(
|
$method,
|
||||||
new Definition\Argument('foos', new Definition\Type('BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\Foo[]')),
|
|
||||||
)),
|
|
||||||
array($foos),
|
array($foos),
|
||||||
$this->getDefinitionComplexTypes()
|
$this->addComplexTypes($this->getTypeRepository())
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals(array('foos' => array($foo, $foo)), $result);
|
$this->assertEquals(array('foos' => array($foo, $foo)), $result);
|
||||||
@ -102,16 +107,17 @@ class RpcLiteralRequestMessageBinderTest extends \PHPUnit_Framework_TestCase
|
|||||||
{
|
{
|
||||||
$messageBinder = new RpcLiteralRequestMessageBinder();
|
$messageBinder = new RpcLiteralRequestMessageBinder();
|
||||||
|
|
||||||
|
$method = new Definition\Method('complextype_argument', null);
|
||||||
|
$method->addInput('fooBar', 'BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\FooBar');
|
||||||
|
|
||||||
$foo = new Fixtures\Foo('foo', 38845);
|
$foo = new Fixtures\Foo('foo', 38845);
|
||||||
$bar = new Fixtures\Bar('bar', null);
|
$bar = new Fixtures\Bar('bar', null);
|
||||||
$fooBar = new Fixtures\FooBar($foo, $bar);
|
$fooBar = new Fixtures\FooBar($foo, $bar);
|
||||||
|
|
||||||
$result = $messageBinder->processMessage(
|
$result = $messageBinder->processMessage(
|
||||||
new Definition\Method('complextype_argument', null, array(), array(
|
$method,
|
||||||
new Definition\Argument('fooBar', new Definition\Type('BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\FooBar')),
|
|
||||||
)),
|
|
||||||
array($fooBar),
|
array($fooBar),
|
||||||
$this->getDefinitionComplexTypes()
|
$this->addComplexTypes($this->getTypeRepository())
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals(array('fooBar' => $fooBar), $result);
|
$this->assertEquals(array('fooBar' => $fooBar), $result);
|
||||||
@ -121,17 +127,18 @@ class RpcLiteralRequestMessageBinderTest extends \PHPUnit_Framework_TestCase
|
|||||||
{
|
{
|
||||||
$messageBinder = new RpcLiteralRequestMessageBinder();
|
$messageBinder = new RpcLiteralRequestMessageBinder();
|
||||||
|
|
||||||
|
$method = new Definition\Method('complextype_with_array', null);
|
||||||
|
$method->addInput('simple_arrays', 'BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\SimpleArrays');
|
||||||
|
|
||||||
$array = array(1, 2, 3, 4);
|
$array = array(1, 2, 3, 4);
|
||||||
$stdClass = new \stdClass();
|
$stdClass = new \stdClass();
|
||||||
$stdClass->item = $array;
|
$stdClass->item = $array;
|
||||||
$simpleArrays = new Fixtures\SimpleArrays(null, new \stdClass(), $stdClass);
|
$simpleArrays = new Fixtures\SimpleArrays(null, new \stdClass(), $stdClass);
|
||||||
|
|
||||||
$result = $messageBinder->processMessage(
|
$result = $messageBinder->processMessage(
|
||||||
new Definition\Method('complextype_with_array', null, array(), array(
|
$method,
|
||||||
new Definition\Argument('simple_arrays', new Definition\Type('BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\SimpleArrays')),
|
|
||||||
)),
|
|
||||||
array($simpleArrays),
|
array($simpleArrays),
|
||||||
$this->getDefinitionComplexTypes()
|
$this->addComplexTypes($this->getTypeRepository())
|
||||||
);
|
);
|
||||||
|
|
||||||
$result = $result['simple_arrays'];
|
$result = $result['simple_arrays'];
|
||||||
@ -144,12 +151,13 @@ class RpcLiteralRequestMessageBinderTest extends \PHPUnit_Framework_TestCase
|
|||||||
{
|
{
|
||||||
$messageBinder = new RpcLiteralRequestMessageBinder();
|
$messageBinder = new RpcLiteralRequestMessageBinder();
|
||||||
|
|
||||||
|
$method = new Definition\Method('empty_array_complex_type', null);
|
||||||
|
$method->addInput('foo', 'BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\Foo[]');
|
||||||
|
|
||||||
$result = $messageBinder->processMessage(
|
$result = $messageBinder->processMessage(
|
||||||
new Definition\Method('empty_array_complex_type', null, array(), array(
|
$method,
|
||||||
new Definition\Argument('foo', new Definition\Type('BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\Foo[]')),
|
|
||||||
)),
|
|
||||||
array(new \stdClass()),
|
array(new \stdClass()),
|
||||||
$this->getDefinitionComplexTypes()
|
$this->addComplexTypes($this->getTypeRepository())
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals(array('foo' => array()), $result);
|
$this->assertEquals(array('foo' => array()), $result);
|
||||||
@ -159,16 +167,17 @@ class RpcLiteralRequestMessageBinderTest extends \PHPUnit_Framework_TestCase
|
|||||||
{
|
{
|
||||||
$messageBinder = new RpcLiteralRequestMessageBinder();
|
$messageBinder = new RpcLiteralRequestMessageBinder();
|
||||||
|
|
||||||
|
$method = new Definition\Method('prevent_infinite_recursion', null);
|
||||||
|
$method->addInput('foo_recursive', 'BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\FooRecursive');
|
||||||
|
|
||||||
$foo = new Fixtures\FooRecursive('foo', '');
|
$foo = new Fixtures\FooRecursive('foo', '');
|
||||||
$bar = new Fixtures\BarRecursive($foo, 10394);
|
$bar = new Fixtures\BarRecursive($foo, 10394);
|
||||||
$foo->bar = $bar;
|
$foo->bar = $bar;
|
||||||
|
|
||||||
$result = $messageBinder->processMessage(
|
$result = $messageBinder->processMessage(
|
||||||
new Definition\Method('prevent_infinite_recursion', null, array(), array(
|
$method,
|
||||||
new Definition\Argument('foo_recursive', new Definition\Type('BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\FooRecursive')),
|
|
||||||
)),
|
|
||||||
array($foo),
|
array($foo),
|
||||||
$this->getDefinitionComplexTypes()
|
$this->addComplexTypes($this->getTypeRepository())
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals(array('foo_recursive' => $foo), $result);
|
$this->assertEquals(array('foo_recursive' => $foo), $result);
|
||||||
@ -179,43 +188,43 @@ class RpcLiteralRequestMessageBinderTest extends \PHPUnit_Framework_TestCase
|
|||||||
$messages = array();
|
$messages = array();
|
||||||
|
|
||||||
$messages[] = array(
|
$messages[] = array(
|
||||||
new Definition\Method('no_argument'),
|
new Definition\Method('no_argument', null),
|
||||||
array(),
|
array(),
|
||||||
array(),
|
array(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$method = new Definition\Method('string_argument', null);
|
||||||
|
$method->addInput('foo', 'string');
|
||||||
$messages[] = array(
|
$messages[] = array(
|
||||||
new Definition\Method('string_argument', null, array(), array(
|
$method,
|
||||||
new Definition\Argument('foo', new Definition\Type('string')),
|
|
||||||
)),
|
|
||||||
array('bar'),
|
array('bar'),
|
||||||
array('foo' => 'bar'),
|
array('foo' => 'bar'),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$method = new Definition\Method('string_int_arguments', null);
|
||||||
|
$method->addInput('foo', 'string');
|
||||||
|
$method->addInput('bar', 'int');
|
||||||
$messages[] = array(
|
$messages[] = array(
|
||||||
new Definition\Method('string_int_arguments', null, array(), array(
|
$method,
|
||||||
new Definition\Argument('foo', new Definition\Type('string')),
|
|
||||||
new Definition\Argument('bar', new Definition\Type('int')),
|
|
||||||
)),
|
|
||||||
array('test', 20),
|
array('test', 20),
|
||||||
array('foo' => 'test', 'bar' => 20),
|
array('foo' => 'test', 'bar' => 20),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$method = new Definition\Method('array_string_arguments', null);
|
||||||
|
$method->addInput('foo', 'string[]');
|
||||||
|
$method->addInput('bar', 'int');
|
||||||
$strings = new \stdClass();
|
$strings = new \stdClass();
|
||||||
$strings->item = array('foo', 'bar', 'barfoo');
|
$strings->item = array('foo', 'bar', 'barfoo');
|
||||||
$messages[] = array(
|
$messages[] = array(
|
||||||
new Definition\Method('array_string_arguments', null, array(), array(
|
$method,
|
||||||
new Definition\Argument('foo', new Definition\Type('string[]')),
|
|
||||||
new Definition\Argument('bar', new Definition\Type('int')),
|
|
||||||
)),
|
|
||||||
array($strings, 4),
|
array($strings, 4),
|
||||||
array('foo' => array('foo', 'bar', 'barfoo'), 'bar' => 4),
|
array('foo' => array('foo', 'bar', 'barfoo'), 'bar' => 4),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$method = new Definition\Method('empty_array', null);
|
||||||
|
$method->addInput('foo', 'string[]');
|
||||||
$messages[] = array(
|
$messages[] = array(
|
||||||
new Definition\Method('empty_array', null, array(), array(
|
$method,
|
||||||
new Definition\Argument('foo', new Definition\Type('string[]')),
|
|
||||||
)),
|
|
||||||
array(new \stdClass()),
|
array(new \stdClass()),
|
||||||
array('foo' => array()),
|
array('foo' => array()),
|
||||||
);
|
);
|
||||||
@ -223,40 +232,38 @@ class RpcLiteralRequestMessageBinderTest extends \PHPUnit_Framework_TestCase
|
|||||||
return $messages;
|
return $messages;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getDefinitionComplexTypes()
|
private function addComplexTypes(TypeRepository $typeRepository)
|
||||||
{
|
{
|
||||||
$definitionComplexTypes = array();
|
$foo = new ComplexType('BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\Foo', 'Foo');
|
||||||
|
$foo->add('foo', 'string');
|
||||||
|
$foo->add('bar', 'int');
|
||||||
|
$typeRepository->addComplexType($foo);
|
||||||
|
|
||||||
$definitionComplexTypes['BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\Foo'] = $this->createComplexTypeCollection(array(
|
$bar = new ComplexType('BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\Bar', 'Bar');
|
||||||
array('foo', 'string'),
|
$bar->add('foo', 'string');
|
||||||
array('bar', 'int'),
|
$bar->add('bar', 'int', true);
|
||||||
));
|
$typeRepository->addComplexType($bar);
|
||||||
|
|
||||||
$definitionComplexTypes['BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\Bar'] = $this->createComplexTypeCollection(array(
|
$fooBar = new ComplexType('BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\FooBar', 'FooBar');
|
||||||
array('foo', 'string'),
|
$fooBar->add('foo', 'BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\Foo');
|
||||||
array('bar', 'int', true),
|
$fooBar->add('bar', 'BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\Bar');
|
||||||
));
|
$typeRepository->addComplexType($fooBar);
|
||||||
|
|
||||||
$definitionComplexTypes['BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\FooBar'] = $this->createComplexTypeCollection(array(
|
$simpleArrays = new ComplexType('BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\SimpleArrays', 'SimpleArrays');
|
||||||
array('foo', 'BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\Foo'),
|
$simpleArrays->add('array1', 'string[]', true);
|
||||||
array('bar', 'BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\Bar'),
|
$simpleArrays->add('array2', 'string[]');
|
||||||
));
|
$simpleArrays->add('array3', 'string[]');
|
||||||
|
$typeRepository->addComplexType($simpleArrays);
|
||||||
|
|
||||||
$definitionComplexTypes['BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\SimpleArrays'] = $this->createComplexTypeCollection(array(
|
$fooRecursive = new ComplexType('BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\FooRecursive', 'FooRecursive');
|
||||||
array('array1', 'string[]', true),
|
$fooRecursive->add('bar', 'BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\BarRecursive');
|
||||||
array('array2', 'string[]'),
|
$typeRepository->addComplexType($fooRecursive);
|
||||||
array('array3', 'string[]'),
|
|
||||||
));
|
|
||||||
|
|
||||||
$definitionComplexTypes['BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\FooRecursive'] = $this->createComplexTypeCollection(array(
|
$barRecursive = new ComplexType('BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\BarRecursive', 'BarRecursive');
|
||||||
array('bar', 'BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\BarRecursive'),
|
$barRecursive->add('foo', 'BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\FooRecursive');
|
||||||
));
|
$typeRepository->addComplexType($barRecursive);
|
||||||
|
|
||||||
$definitionComplexTypes['BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\BarRecursive'] = $this->createComplexTypeCollection(array(
|
return $typeRepository;
|
||||||
array('foo', 'BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\FooRecursive'),
|
|
||||||
));
|
|
||||||
|
|
||||||
return $definitionComplexTypes;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function createComplexTypeCollection(array $properties)
|
private function createComplexTypeCollection(array $properties)
|
||||||
@ -277,4 +284,18 @@ class RpcLiteralRequestMessageBinderTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
return array('properties' => $collection);
|
return array('properties' => $collection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getTypeRepository()
|
||||||
|
{
|
||||||
|
$typeRepository = new TypeRepository();
|
||||||
|
$typeRepository->addXmlNamespace('xsd', 'http://www.w3.org/2001/XMLSchema');
|
||||||
|
$typeRepository->addType('string', 'xsd:string');
|
||||||
|
$typeRepository->addType('boolean', 'xsd:boolean');
|
||||||
|
$typeRepository->addType('int', 'xsd:int');
|
||||||
|
$typeRepository->addType('float', 'xsd:float');
|
||||||
|
$typeRepository->addType('date', 'xsd:date');
|
||||||
|
$typeRepository->addType('dateTime', 'xsd:dateTime');
|
||||||
|
|
||||||
|
return $typeRepository;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,8 @@ class SoapRequestTest extends \PHPUnit_Framework_TestCase
|
|||||||
{
|
{
|
||||||
public function testMtomMessage()
|
public function testMtomMessage()
|
||||||
{
|
{
|
||||||
|
$this->markTestSkipped('Skip because I\'m not sure that SoapRequest is used in a HTTP Request process.');
|
||||||
|
|
||||||
$content = $this->loadRequestContentFixture('mtom/simple.txt');
|
$content = $this->loadRequestContentFixture('mtom/simple.txt');
|
||||||
|
|
||||||
$request = new SoapRequest(array(), array(), array(), array(), array(), array(), $content);
|
$request = new SoapRequest(array(), array(), array(), array(), array(), array(), $content);
|
||||||
|
@ -15,7 +15,7 @@ namespace BeSimple\SoapBundle\Util;
|
|||||||
*
|
*
|
||||||
* @author Christian Kerl <christian-kerl@web.de>
|
* @author Christian Kerl <christian-kerl@web.de>
|
||||||
*/
|
*/
|
||||||
class String
|
class BsString
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Checks if a string starts with a given string.
|
* Checks if a string starts with a given string.
|
@ -3,6 +3,7 @@
|
|||||||
* This file is part of the BeSimpleSoapBundle.
|
* This file is part of the BeSimpleSoapBundle.
|
||||||
*
|
*
|
||||||
* (c) Christian Kerl <christian-kerl@web.de>
|
* (c) Christian Kerl <christian-kerl@web.de>
|
||||||
|
* (c) Francis Besset <francis.besset@gmail.com>
|
||||||
*
|
*
|
||||||
* This source file is subject to the MIT license that is bundled
|
* This source file is subject to the MIT license that is bundled
|
||||||
* with this source code in the file LICENSE.
|
* with this source code in the file LICENSE.
|
||||||
@ -10,15 +11,10 @@
|
|||||||
|
|
||||||
namespace BeSimple\SoapBundle;
|
namespace BeSimple\SoapBundle;
|
||||||
|
|
||||||
use BeSimple\SoapBundle\Converter\TypeRepository;
|
|
||||||
use BeSimple\SoapBundle\ServiceBinding\MessageBinderInterface;
|
|
||||||
use BeSimple\SoapBundle\ServiceBinding\ServiceBinder;
|
use BeSimple\SoapBundle\ServiceBinding\ServiceBinder;
|
||||||
use BeSimple\SoapBundle\ServiceDefinition\Dumper\DumperInterface;
|
|
||||||
|
|
||||||
use BeSimple\SoapCommon\Classmap;
|
|
||||||
use BeSimple\SoapCommon\Converter\TypeConverterCollection;
|
use BeSimple\SoapCommon\Converter\TypeConverterCollection;
|
||||||
|
use BeSimple\SoapWsdl\Dumper\Dumper;
|
||||||
use BeSimple\SoapServer\SoapServerBuilder;
|
use BeSimple\SoapServer\SoapServerBuilder;
|
||||||
|
|
||||||
use Symfony\Component\Config\ConfigCache;
|
use Symfony\Component\Config\ConfigCache;
|
||||||
use Symfony\Component\Config\Loader\LoaderInterface;
|
use Symfony\Component\Config\Loader\LoaderInterface;
|
||||||
|
|
||||||
@ -26,43 +22,29 @@ use Symfony\Component\Config\Loader\LoaderInterface;
|
|||||||
* WebServiceContext.
|
* WebServiceContext.
|
||||||
*
|
*
|
||||||
* @author Christian Kerl <christian-kerl@web.de>
|
* @author Christian Kerl <christian-kerl@web.de>
|
||||||
|
* @author Francis Besset <francis.besset@gmail.com>
|
||||||
*/
|
*/
|
||||||
class WebServiceContext
|
class WebServiceContext
|
||||||
{
|
{
|
||||||
private $classmap;
|
|
||||||
|
|
||||||
private $typeRepository;
|
|
||||||
private $converterRepository;
|
|
||||||
|
|
||||||
private $wsdlFileDumper;
|
|
||||||
|
|
||||||
private $options;
|
private $options;
|
||||||
|
|
||||||
private $serviceDefinition;
|
private $serviceDefinition;
|
||||||
private $serviceBinder;
|
private $serviceBinder;
|
||||||
private $serverBuilder;
|
private $serverBuilder;
|
||||||
|
|
||||||
public function __construct(LoaderInterface $loader, DumperInterface $dumper, Classmap $classmap, TypeRepository $typeRepository, TypeConverterCollection $converters, array $options)
|
public function __construct(LoaderInterface $loader, TypeConverterCollection $converters, array $options)
|
||||||
{
|
{
|
||||||
$this->loader = $loader;
|
$this->loader = $loader;
|
||||||
$this->wsdlFileDumper = $dumper;
|
|
||||||
|
|
||||||
$this->classmap = $classmap;
|
|
||||||
|
|
||||||
$this->typeRepository = $typeRepository;
|
|
||||||
$this->converters = $converters;
|
$this->converters = $converters;
|
||||||
|
|
||||||
// Issue #6: keep the debug because the cache is invalid
|
|
||||||
$options['debug'] = true;
|
|
||||||
$this->options = $options;
|
$this->options = $options;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getServiceDefinition()
|
public function getServiceDefinition()
|
||||||
{
|
{
|
||||||
if (null === $this->serviceDefinition) {
|
if (null === $this->serviceDefinition) {
|
||||||
$cacheDefinition = new ConfigCache(sprintf('%s/%s.definition.php', $this->options['cache_dir'], $this->options['name']), $this->options['debug']);
|
$cache = new ConfigCache(sprintf('%s/%s.definition.php', $this->options['cache_dir'], $this->options['name']), $this->options['debug']);
|
||||||
if ($cacheDefinition->isFresh()) {
|
if ($cache->isFresh()) {
|
||||||
$this->serviceDefinition = include (string) $cacheDefinition;
|
$this->serviceDefinition = include $cache->getPath();
|
||||||
} else {
|
} else {
|
||||||
if (!$this->loader->supports($this->options['resource'], $this->options['resource_type'])) {
|
if (!$this->loader->supports($this->options['resource'], $this->options['resource_type'])) {
|
||||||
throw new \LogicException(sprintf('Cannot load "%s" (%s)', $this->options['resource'], $this->options['resource_type']));
|
throw new \LogicException(sprintf('Cannot load "%s" (%s)', $this->options['resource'], $this->options['resource_type']));
|
||||||
@ -72,10 +54,7 @@ class WebServiceContext
|
|||||||
$this->serviceDefinition->setName($this->options['name']);
|
$this->serviceDefinition->setName($this->options['name']);
|
||||||
$this->serviceDefinition->setNamespace($this->options['namespace']);
|
$this->serviceDefinition->setNamespace($this->options['namespace']);
|
||||||
|
|
||||||
$this->serviceDefinition->setClassmap($this->classmap);
|
$cache->write('<?php return unserialize('.var_export(serialize($this->serviceDefinition), true).');');
|
||||||
$this->classmap = null;
|
|
||||||
|
|
||||||
$this->typeRepository->fixTypeInformation($this->serviceDefinition);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,18 +69,20 @@ class WebServiceContext
|
|||||||
public function getWsdlFile($endpoint = null)
|
public function getWsdlFile($endpoint = null)
|
||||||
{
|
{
|
||||||
$file = sprintf('%s/%s.%s.wsdl', $this->options['cache_dir'], $this->options['name'], md5($endpoint));
|
$file = sprintf('%s/%s.%s.wsdl', $this->options['cache_dir'], $this->options['name'], md5($endpoint));
|
||||||
$cacheWsdl = new ConfigCache($file, $this->options['debug']);
|
$cache = new ConfigCache($file, $this->options['debug']);
|
||||||
|
|
||||||
if(!$cacheWsdl->isFresh()) {
|
if (!$cache->isFresh()) {
|
||||||
$serviceDefinition = $this->getServiceDefinition();
|
$definition = $this->getServiceDefinition();
|
||||||
|
|
||||||
$cacheWsdl->write($this->wsdlFileDumper->dumpServiceDefinition($serviceDefinition, $endpoint));
|
if ($endpoint) {
|
||||||
|
$definition->setOption('location', $endpoint);
|
||||||
$cacheDefinition = new ConfigCache(sprintf('%s/%s.definition.php', $this->options['cache_dir'], $this->options['name']), $this->options['debug']);
|
|
||||||
$cacheDefinition->write('<?php return unserialize('.var_export(serialize($serviceDefinition), true).');');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (string) $cacheWsdl;
|
$dumper = new Dumper($definition, array('stylesheet' => $this->options['wsdl_stylesheet']));
|
||||||
|
$cache->write($dumper->dump());
|
||||||
|
}
|
||||||
|
|
||||||
|
return $cache->getPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getServiceBinder()
|
public function getServiceBinder()
|
||||||
@ -123,7 +104,7 @@ class WebServiceContext
|
|||||||
if (null === $this->serverBuilder) {
|
if (null === $this->serverBuilder) {
|
||||||
$this->serverBuilder = SoapServerBuilder::createWithDefaults()
|
$this->serverBuilder = SoapServerBuilder::createWithDefaults()
|
||||||
->withWsdl($this->getWsdlFile())
|
->withWsdl($this->getWsdlFile())
|
||||||
->withClassmap($this->getServiceDefinition()->getClassmap())
|
->withClassmap($this->getServiceDefinition()->getTypeRepository()->getClassmap())
|
||||||
->withTypeConverters($this->converters)
|
->withTypeConverters($this->converters)
|
||||||
;
|
;
|
||||||
|
|
||||||
|
@ -22,25 +22,24 @@
|
|||||||
"require": {
|
"require": {
|
||||||
"php": ">=5.3.0",
|
"php": ">=5.3.0",
|
||||||
"ext-soap": "*",
|
"ext-soap": "*",
|
||||||
"besimple/soap-common": "0.1.*",
|
"besimple/soap-common": "0.2.*",
|
||||||
"ass/xmlsecurity": "dev-master",
|
"besimple/soap-wsdl": "0.2.*",
|
||||||
"zendframework/zend-mail": "2.1.*",
|
"ass/xmlsecurity": "~1.0",
|
||||||
"zendframework/zend-mime": "2.1.*",
|
"symfony/framework-bundle": "~2.0|~3.0",
|
||||||
"zendframework/zend-soap": "2.1.*",
|
"symfony/twig-bundle": "~2.0|~3.0",
|
||||||
"symfony/framework-bundle": "~2.0"
|
"zendframework/zend-mime": "2.1.*"
|
||||||
},
|
},
|
||||||
"suggest": {
|
"suggest": {
|
||||||
"besimple/soap-client": "0.1.*",
|
"besimple/soap-client": "0.2.*",
|
||||||
"besimple/soap-server": "0.1.*"
|
"besimple/soap-server": "0.2.*"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-0": { "BeSimple\\SoapBundle": "" }
|
"psr-0": { "BeSimple\\SoapBundle": "" }
|
||||||
},
|
},
|
||||||
"target-dir": "BeSimple/SoapBundle",
|
"target-dir": "BeSimple/SoapBundle",
|
||||||
"minimum-stability": "dev",
|
|
||||||
"extra": {
|
"extra": {
|
||||||
"branch-alias": {
|
"branch-alias": {
|
||||||
"dev-master": "0.1-dev"
|
"dev-master": "0.2-dev"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -77,24 +77,41 @@ class Curl
|
|||||||
if (isset($options['compression']) && !($options['compression'] & SOAP_COMPRESSION_ACCEPT)) {
|
if (isset($options['compression']) && !($options['compression'] & SOAP_COMPRESSION_ACCEPT)) {
|
||||||
curl_setopt($this->ch, CURLOPT_ENCODING, 'identity');
|
curl_setopt($this->ch, CURLOPT_ENCODING, 'identity');
|
||||||
}
|
}
|
||||||
if (isset($options['connection_timeout'])) {
|
|
||||||
curl_setopt($this->ch, CURLOPT_CONNECTTIMEOUT, $options['connection_timeout']);
|
curl_setopt($this->ch, CURLOPT_CONNECTTIMEOUT, 10);
|
||||||
}
|
|
||||||
if (isset($options['proxy_host'])) {
|
if (isset($options['proxy_host'])) {
|
||||||
$port = isset($options['proxy_port']) ? $options['proxy_port'] : 8080;
|
if (false !== $options['proxy_host']) {
|
||||||
curl_setopt($this->ch, CURLOPT_PROXY, $options['proxy_host'] . ':' . $port);
|
$proxyHost = $options['proxy_host'].(isset($options['proxy_port']) ? $options['proxy_port'] : 8080);
|
||||||
|
} else {
|
||||||
|
$proxyHost = false;
|
||||||
}
|
}
|
||||||
if (isset($options['proxy_user'])) {
|
|
||||||
curl_setopt($this->ch, CURLOPT_PROXYUSERPWD, $options['proxy_user'] . ':' . $options['proxy_password']);
|
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['login'])) {
|
if (isset($options['login'])) {
|
||||||
curl_setopt($this->ch, CURLOPT_HTTPAUTH, 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']);
|
||||||
}
|
}
|
||||||
if (isset($options['local_cert'])) {
|
if (isset($options['local_cert'])) {
|
||||||
curl_setopt($this->ch, CURLOPT_SSLCERT, $options['local_cert']);
|
curl_setopt($this->ch, CURLOPT_SSLCERT, $options['local_cert']);
|
||||||
curl_setopt($this->ch, CURLOPT_SSLCERTPASSWD, $options['passphrase']);
|
curl_setopt($this->ch, CURLOPT_SSLCERTPASSWD, $options['passphrase']);
|
||||||
}
|
}
|
||||||
|
if (isset($options['ca_info'])) {
|
||||||
|
curl_setopt($this->ch, CURLOPT_CAINFO, $options['ca_info']);
|
||||||
|
}
|
||||||
|
if (isset($options['ca_path'])) {
|
||||||
|
curl_setopt($this->ch, CURLOPT_CAPATH, $options['ca_path']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -112,10 +129,11 @@ class Curl
|
|||||||
* @param string $location HTTP location
|
* @param string $location HTTP location
|
||||||
* @param string $request Request body
|
* @param string $request Request body
|
||||||
* @param array $requestHeaders Request header strings
|
* @param array $requestHeaders Request header strings
|
||||||
|
* @param array $requestOptions An array of request options
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function exec($location, $request = null, $requestHeaders = array())
|
public function exec($location, $request = null, $requestHeaders = array(), $requestOptions = array())
|
||||||
{
|
{
|
||||||
curl_setopt($this->ch, CURLOPT_URL, $location);
|
curl_setopt($this->ch, CURLOPT_URL, $location);
|
||||||
|
|
||||||
@ -128,7 +146,11 @@ class Curl
|
|||||||
curl_setopt($this->ch, CURLOPT_HTTPHEADER, $requestHeaders);
|
curl_setopt($this->ch, CURLOPT_HTTPHEADER, $requestHeaders);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->response = $this->execManualRedirect($this->followLocationMaxRedirects);
|
if (count($requestOptions) > 0) {
|
||||||
|
curl_setopt_array($this->ch, $requestOptions);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->response = $this->execManualRedirect();
|
||||||
|
|
||||||
return ($this->response === false) ? false : true;
|
return ($this->response === false) ? false : true;
|
||||||
}
|
}
|
||||||
@ -144,7 +166,6 @@ class Curl
|
|||||||
private function execManualRedirect($redirects = 0)
|
private function execManualRedirect($redirects = 0)
|
||||||
{
|
{
|
||||||
if ($redirects > $this->followLocationMaxRedirects) {
|
if ($redirects > $this->followLocationMaxRedirects) {
|
||||||
|
|
||||||
// TODO Redirection limit reached, aborting
|
// TODO Redirection limit reached, aborting
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -182,7 +203,7 @@ class Curl
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Error code mapping from cURL error codes to PHP ext/soap error messages
|
* Error code mapping from cURL error codes to PHP ext/soap error messages
|
||||||
* (where applicable)
|
* (where applicable).
|
||||||
*
|
*
|
||||||
* http://curl.haxx.se/libcurl/c/libcurl-errors.html
|
* http://curl.haxx.se/libcurl/c/libcurl-errors.html
|
||||||
*
|
*
|
||||||
@ -228,7 +249,6 @@ class Curl
|
|||||||
$errorCodeMapping = $this->getErrorCodeMapping();
|
$errorCodeMapping = $this->getErrorCodeMapping();
|
||||||
$errorNumber = curl_errno($this->ch);
|
$errorNumber = curl_errno($this->ch);
|
||||||
if (isset($errorCodeMapping[$errorNumber])) {
|
if (isset($errorCodeMapping[$errorNumber])) {
|
||||||
|
|
||||||
return $errorCodeMapping[$errorNumber];
|
return $errorCodeMapping[$errorNumber];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ class MimeFilter implements SoapRequestFilter, SoapResponseFilter
|
|||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
$headers = $multipart->getHeadersForHttp();
|
$headers = $multipart->getHeadersForHttp();
|
||||||
list($name, $contentType) = explode(': ', $headers[0]);
|
list(, $contentType) = explode(': ', $headers[0]);
|
||||||
|
|
||||||
$request->setContentType($contentType);
|
$request->setContentType($contentType);
|
||||||
}
|
}
|
||||||
|
34
src/BeSimple/SoapClient/README.md
Normal file
34
src/BeSimple/SoapClient/README.md
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
# BeSimpleSoapClient
|
||||||
|
|
||||||
|
The BeSimpleSoapClient is a component that extends the native PHP SoapClient with further features like SwA, MTOM and WS-Security.
|
||||||
|
|
||||||
|
# Features (only subsets of the linked specs implemented)
|
||||||
|
|
||||||
|
* SwA: SOAP Messages with Attachments [Spec](http://www.w3.org/TR/SOAP-attachments)
|
||||||
|
* MTOM: SOAP Message Transmission Optimization Mechanism [Spec](http://www.w3.org/TR/soap12-mtom/)
|
||||||
|
* WS-Security [Spec1](http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0.pdf), [Spec2](http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0.pdf)
|
||||||
|
* WS-Adressing [Spec](http://www.w3.org/2002/ws/addr/)
|
||||||
|
|
||||||
|
# Installation
|
||||||
|
|
||||||
|
If you do not yet have composer, install it like this:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
curl -s http://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin
|
||||||
|
```
|
||||||
|
|
||||||
|
Create a `composer.json` file:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"require": {
|
||||||
|
"besimple/soap-client": "0.2.*@dev"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Now you are ready to install the library:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
php /usr/local/bin/composer.phar install
|
||||||
|
```
|
@ -15,6 +15,7 @@ namespace BeSimple\SoapClient;
|
|||||||
use BeSimple\SoapCommon\Helper;
|
use BeSimple\SoapCommon\Helper;
|
||||||
use BeSimple\SoapCommon\Converter\MtomTypeConverter;
|
use BeSimple\SoapCommon\Converter\MtomTypeConverter;
|
||||||
use BeSimple\SoapCommon\Converter\SwaTypeConverter;
|
use BeSimple\SoapCommon\Converter\SwaTypeConverter;
|
||||||
|
use BeSimple\SoapCommon\SoapMessage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extended SoapClient that uses a a cURL wrapper for all underlying HTTP
|
* Extended SoapClient that uses a a cURL wrapper for all underlying HTTP
|
||||||
@ -98,7 +99,13 @@ class SoapClient extends \SoapClient
|
|||||||
if (isset($options['soap_version'])) {
|
if (isset($options['soap_version'])) {
|
||||||
$this->soapVersion = $options['soap_version'];
|
$this->soapVersion = $options['soap_version'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->curl = new Curl($options);
|
$this->curl = new Curl($options);
|
||||||
|
|
||||||
|
if (isset($options['extra_options'])) {
|
||||||
|
unset($options['extra_options']);
|
||||||
|
}
|
||||||
|
|
||||||
$wsdlFile = $this->loadWsdl($wsdl, $options);
|
$wsdlFile = $this->loadWsdl($wsdl, $options);
|
||||||
// TODO $wsdlHandler = new WsdlHandler($wsdlFile, $this->soapVersion);
|
// TODO $wsdlHandler = new WsdlHandler($wsdlFile, $this->soapVersion);
|
||||||
$this->soapKernel = new SoapKernel();
|
$this->soapKernel = new SoapKernel();
|
||||||
@ -124,16 +131,34 @@ class SoapClient extends \SoapClient
|
|||||||
private function __doHttpRequest(SoapRequest $soapRequest)
|
private function __doHttpRequest(SoapRequest $soapRequest)
|
||||||
{
|
{
|
||||||
// HTTP headers
|
// HTTP headers
|
||||||
|
$soapVersion = $soapRequest->getVersion();
|
||||||
|
$soapAction = $soapRequest->getAction();
|
||||||
|
if (SOAP_1_1 == $soapVersion) {
|
||||||
$headers = array(
|
$headers = array(
|
||||||
'Content-Type:' . $soapRequest->getContentType(),
|
'Content-Type:' . $soapRequest->getContentType(),
|
||||||
'SOAPAction: "' . $soapRequest->getAction() . '"',
|
'SOAPAction: "' . $soapAction . '"',
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
$headers = array(
|
||||||
|
'Content-Type:' . $soapRequest->getContentType() . '; action="' . $soapAction . '"',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$location = $soapRequest->getLocation();
|
||||||
|
$content = $soapRequest->getContent();
|
||||||
|
|
||||||
|
$headers = $this->filterRequestHeaders($soapRequest, $headers);
|
||||||
|
|
||||||
|
$options = $this->filterRequestOptions($soapRequest);
|
||||||
|
|
||||||
// execute HTTP request with cURL
|
// execute HTTP request with cURL
|
||||||
$responseSuccessfull = $this->curl->exec(
|
$responseSuccessfull = $this->curl->exec(
|
||||||
$soapRequest->getLocation(),
|
$location,
|
||||||
$soapRequest->getContent(),
|
$content,
|
||||||
$headers
|
$headers,
|
||||||
|
$options
|
||||||
);
|
);
|
||||||
|
|
||||||
// tracing enabled: store last request header and body
|
// tracing enabled: store last request header and body
|
||||||
if ($this->tracingEnabled === true) {
|
if ($this->tracingEnabled === true) {
|
||||||
$this->lastRequestHeaders = $this->curl->getRequestHeaders();
|
$this->lastRequestHeaders = $this->curl->getRequestHeaders();
|
||||||
@ -208,6 +233,31 @@ class SoapClient extends \SoapClient
|
|||||||
return $soapResponse;
|
return $soapResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filters HTTP headers which will be sent
|
||||||
|
*
|
||||||
|
* @param SoapRequest $soapRequest SOAP request object
|
||||||
|
* @param array $headers An array of HTTP headers
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function filterRequestHeaders(SoapRequest $soapRequest, array $headers)
|
||||||
|
{
|
||||||
|
return $headers;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds additional cURL options for the request
|
||||||
|
*
|
||||||
|
* @param SoapRequest $soapRequest SOAP request object
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function filterRequestOptions(SoapRequest $soapRequest)
|
||||||
|
{
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get last request HTTP headers.
|
* Get last request HTTP headers.
|
||||||
*
|
*
|
||||||
@ -309,7 +359,7 @@ class SoapClient extends \SoapClient
|
|||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
private function loadWsdl($wsdl, array $options)
|
protected function loadWsdl($wsdl, array $options)
|
||||||
{
|
{
|
||||||
// option to resolve wsdl/xsd includes
|
// option to resolve wsdl/xsd includes
|
||||||
$resolveRemoteIncludes = true;
|
$resolveRemoteIncludes = true;
|
||||||
|
@ -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;
|
||||||
|
@ -13,7 +13,6 @@
|
|||||||
namespace BeSimple\SoapClient;
|
namespace BeSimple\SoapClient;
|
||||||
|
|
||||||
use BeSimple\SoapCommon\SoapResponse as CommonSoapResponse;
|
use BeSimple\SoapCommon\SoapResponse as CommonSoapResponse;
|
||||||
use BeSimple\SoapCommon\SoapMessage;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SoapResponse class for SoapClient. Provides factory function for response object.
|
* SoapResponse class for SoapClient. Provides factory function for response object.
|
||||||
|
@ -23,8 +23,7 @@ abstract class AbstractWebServerTest extends \PHPUnit_Framework_TestCase
|
|||||||
/**
|
/**
|
||||||
* @var ProcessBuilder
|
* @var ProcessBuilder
|
||||||
*/
|
*/
|
||||||
static protected $webserver;
|
protected static $webserver;
|
||||||
static protected $websererPortLength;
|
|
||||||
|
|
||||||
public static function setUpBeforeClass()
|
public static function setUpBeforeClass()
|
||||||
{
|
{
|
||||||
@ -44,8 +43,6 @@ abstract class AbstractWebServerTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
self::$webserver->start();
|
self::$webserver->start();
|
||||||
usleep(100000);
|
usleep(100000);
|
||||||
|
|
||||||
self::$websererPortLength = strlen(WEBSERVER_PORT);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function tearDownAfterClass()
|
public static function tearDownAfterClass()
|
||||||
|
@ -0,0 +1,7 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BeSimple\SoapClient\Tests\AxisInterop\Fixtures;
|
||||||
|
|
||||||
|
class AttachmentRequest extends AttachmentType
|
||||||
|
{
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BeSimple\SoapClient\Tests\AxisInterop\Fixtures;
|
||||||
|
|
||||||
|
class AttachmentType
|
||||||
|
{
|
||||||
|
public $fileName;
|
||||||
|
public $binaryData;
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BeSimple\SoapClient\Tests\AxisInterop\Fixtures;
|
||||||
|
|
||||||
|
class BookInformation
|
||||||
|
{
|
||||||
|
public $type;
|
||||||
|
public $isbn;
|
||||||
|
public $author;
|
||||||
|
public $title;
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BeSimple\SoapClient\Tests\AxisInterop\Fixtures;
|
||||||
|
|
||||||
|
class addBook
|
||||||
|
{
|
||||||
|
public $type;
|
||||||
|
public $isbn;
|
||||||
|
public $author;
|
||||||
|
public $title;
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BeSimple\SoapClient\Tests\AxisInterop\Fixtures;
|
||||||
|
|
||||||
|
class addBookResponse
|
||||||
|
{
|
||||||
|
public $addBookReturn;
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BeSimple\SoapClient\Tests\AxisInterop\Fixtures;
|
||||||
|
|
||||||
|
class base64Binary
|
||||||
|
{
|
||||||
|
public $_;
|
||||||
|
public $contentType;
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BeSimple\SoapClient\Tests\AxisInterop\Fixtures;
|
||||||
|
|
||||||
|
class downloadFile
|
||||||
|
{
|
||||||
|
public $name;
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BeSimple\SoapClient\Tests\AxisInterop\Fixtures;
|
||||||
|
|
||||||
|
class downloadFileResponse
|
||||||
|
{
|
||||||
|
public $data;
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BeSimple\SoapClient\Tests\AxisInterop\Fixtures;
|
||||||
|
|
||||||
|
class getBook
|
||||||
|
{
|
||||||
|
public $isbn;
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BeSimple\SoapClient\Tests\AxisInterop\Fixtures;
|
||||||
|
|
||||||
|
class getBookResponse
|
||||||
|
{
|
||||||
|
public $getBookReturn;
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BeSimple\SoapClient\Tests\AxisInterop\Fixtures;
|
||||||
|
|
||||||
|
class getBooksByType
|
||||||
|
{
|
||||||
|
public $type;
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BeSimple\SoapClient\Tests\AxisInterop\Fixtures;
|
||||||
|
|
||||||
|
class getBooksByTypeResponse
|
||||||
|
{
|
||||||
|
public $getBooksByTypeReturn;
|
||||||
|
}
|
Before Width: | Height: | Size: 74 KiB After Width: | Height: | Size: 74 KiB |
@ -0,0 +1,9 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BeSimple\SoapClient\Tests\AxisInterop\Fixtures;
|
||||||
|
|
||||||
|
class uploadFile
|
||||||
|
{
|
||||||
|
public $data;
|
||||||
|
public $name;
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BeSimple\SoapClient\Tests\AxisInterop\Fixtures;
|
||||||
|
|
||||||
|
class uploadFileResponse
|
||||||
|
{
|
||||||
|
public $return;
|
||||||
|
}
|
@ -1,100 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use BeSimple\SoapCommon\Helper as BeSimpleSoapHelper;
|
|
||||||
use BeSimple\SoapClient\SoapClient as BeSimpleSoapClient;
|
|
||||||
|
|
||||||
require '../bootstrap.php';
|
|
||||||
|
|
||||||
class base64Binary
|
|
||||||
{
|
|
||||||
public $_;
|
|
||||||
public $contentType;
|
|
||||||
}
|
|
||||||
|
|
||||||
class AttachmentType
|
|
||||||
{
|
|
||||||
public $fileName;
|
|
||||||
public $binaryData;
|
|
||||||
}
|
|
||||||
|
|
||||||
class AttachmentRequest extends AttachmentType
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
class base64Binary
|
|
||||||
{
|
|
||||||
public $_;
|
|
||||||
public $contentType;
|
|
||||||
}
|
|
||||||
|
|
||||||
class AttachmentType
|
|
||||||
{
|
|
||||||
public $fileName;
|
|
||||||
public $binaryData;
|
|
||||||
}
|
|
||||||
|
|
||||||
class AttachmentRequest extends AttachmentType
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
class base64Binary
|
|
||||||
{
|
|
||||||
public $_;
|
|
||||||
public $contentType;
|
|
||||||
}
|
|
||||||
|
|
||||||
class AttachmentType
|
|
||||||
{
|
|
||||||
public $fileName;
|
|
||||||
public $binaryData;
|
|
||||||
}
|
|
||||||
|
|
||||||
class AttachmentRequest extends AttachmentType
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
$options = array(
|
|
||||||
'soap_version' => SOAP_1_1,
|
|
||||||
'features' => SOAP_SINGLE_ELEMENT_ARRAYS, // make sure that result is array for size=1
|
|
||||||
'trace' => true, // enables use of the methods SoapClient->__getLastRequest, SoapClient->__getLastRequestHeaders, SoapClient->__getLastResponse and SoapClient->__getLastResponseHeaders
|
|
||||||
'attachment_type' => BeSimpleSoapHelper::ATTACHMENTS_TYPE_MTOM,
|
|
||||||
'cache_wsdl' => WSDL_CACHE_NONE,
|
|
||||||
'classmap' => array(
|
|
||||||
'base64Binary' => 'base64Binary',
|
|
||||||
'AttachmentRequest' => 'AttachmentRequest',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Deploy "axis_services/sample-mtom.aar" to Apache Axis2 to get this
|
|
||||||
* example to work.
|
|
||||||
*
|
|
||||||
* Apache Axis2 MTOM example.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
$sc = new BeSimpleSoapClient('MTOM.wsdl', $options);
|
|
||||||
|
|
||||||
//var_dump($sc->__getFunctions());
|
|
||||||
//var_dump($sc->__getTypes());
|
|
||||||
|
|
||||||
try {
|
|
||||||
$b64 = new base64Binary();
|
|
||||||
$b64->_ = 'This is a test. :)';
|
|
||||||
$b64->contentType = 'text/plain';
|
|
||||||
|
|
||||||
$attachment = new AttachmentRequest();
|
|
||||||
$attachment->fileName = 'test123.txt';
|
|
||||||
$attachment->binaryData = $b64;
|
|
||||||
|
|
||||||
var_dump($sc->attachment($attachment));
|
|
||||||
|
|
||||||
} catch (Exception $e) {
|
|
||||||
var_dump($e);
|
|
||||||
}
|
|
||||||
|
|
||||||
// var_dump(
|
|
||||||
// $sc->__getLastRequestHeaders(),
|
|
||||||
// $sc->__getLastRequest(),
|
|
||||||
// $sc->__getLastResponseHeaders(),
|
|
||||||
// $sc->__getLastResponse()
|
|
||||||
// );
|
|
@ -0,0 +1,52 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Deploy "axis_services/sample-mtom.aar" to Apache Axis2 to get this
|
||||||
|
* example to work.
|
||||||
|
*
|
||||||
|
* Apache Axis2 MTOM example.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
use BeSimple\SoapCommon\Helper as BeSimpleSoapHelper;
|
||||||
|
use BeSimple\SoapClient\SoapClient as BeSimpleSoapClient;
|
||||||
|
|
||||||
|
use BeSimple\SoapClient\Tests\AxisInterop\Fixtures\AttachmentRequest;
|
||||||
|
use BeSimple\SoapClient\Tests\AxisInterop\Fixtures\AttachmentType;
|
||||||
|
use BeSimple\SoapClient\Tests\AxisInterop\Fixtures\base64Binary;
|
||||||
|
|
||||||
|
use BeSimple\SoapClient\Tests\AxisInterop\TestCase;
|
||||||
|
|
||||||
|
class MtomAxisInteropTest extends TestCase
|
||||||
|
{
|
||||||
|
private $options = array(
|
||||||
|
'soap_version' => SOAP_1_1,
|
||||||
|
'features' => SOAP_SINGLE_ELEMENT_ARRAYS, // make sure that result is array for size=1
|
||||||
|
'attachment_type' => BeSimpleSoapHelper::ATTACHMENTS_TYPE_MTOM,
|
||||||
|
'cache_wsdl' => WSDL_CACHE_NONE,
|
||||||
|
'classmap' => array(
|
||||||
|
'base64Binary' => 'BeSimple\SoapClient\Tests\AxisInterop\Fixtures\base64Binary',
|
||||||
|
'AttachmentRequest' => 'BeSimple\SoapClient\Tests\AxisInterop\Fixtures\AttachmentRequest',
|
||||||
|
),
|
||||||
|
'proxy_host' => false,
|
||||||
|
);
|
||||||
|
|
||||||
|
public function testAttachment()
|
||||||
|
{
|
||||||
|
$sc = new BeSimpleSoapClient(__DIR__.'/Fixtures/MTOM.wsdl', $this->options);
|
||||||
|
|
||||||
|
$b64 = new base64Binary();
|
||||||
|
$b64->_ = 'This is a test. :)';
|
||||||
|
$b64->contentType = 'text/plain';
|
||||||
|
|
||||||
|
$attachment = new AttachmentRequest();
|
||||||
|
$attachment->fileName = 'test123.txt';
|
||||||
|
$attachment->binaryData = $b64;
|
||||||
|
|
||||||
|
$this->assertEquals('File saved succesfully.', $sc->attachment($attachment));
|
||||||
|
|
||||||
|
// $fileCreatedByServer = __DIR__.'/'.$attachment->fileName;
|
||||||
|
// $this->assertEquals($b64->_, file_get_contents($fileCreatedByServer));
|
||||||
|
// unlink($fileCreatedByServer);
|
||||||
|
}
|
||||||
|
}
|
@ -1,84 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use BeSimple\SoapCommon\Helper as BeSimpleSoapHelper;
|
|
||||||
use BeSimple\SoapClient\SoapClient as BeSimpleSoapClient;
|
|
||||||
|
|
||||||
require '../bootstrap.php';
|
|
||||||
|
|
||||||
$options = array(
|
|
||||||
'soap_version' => SOAP_1_1,
|
|
||||||
'features' => SOAP_SINGLE_ELEMENT_ARRAYS, // make sure that result is array for size=1
|
|
||||||
'trace' => true, // enables use of the methods SoapClient->__getLastRequest, SoapClient->__getLastRequestHeaders, SoapClient->__getLastResponse and SoapClient->__getLastResponseHeaders
|
|
||||||
'attachment_type' => BeSimpleSoapHelper::ATTACHMENTS_TYPE_SWA,
|
|
||||||
'cache_wsdl' => WSDL_CACHE_NONE,
|
|
||||||
);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Deploy "axis_services/besimple-swa.aar" to Apache Axis2 to get this
|
|
||||||
* example to work.
|
|
||||||
*
|
|
||||||
* Run ant to rebuild aar.
|
|
||||||
*
|
|
||||||
* Example based on:
|
|
||||||
* http://axis.apache.org/axis2/java/core/docs/mtom-guide.html#a3
|
|
||||||
* http://wso2.org/library/1675
|
|
||||||
*
|
|
||||||
* Doesn't work directly with ?wsdl served by Apache Axis!
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
$sc = new BeSimpleSoapClient('SwA.wsdl', $options);
|
|
||||||
|
|
||||||
//var_dump($sc->__getFunctions());
|
|
||||||
//var_dump($sc->__getTypes());
|
|
||||||
|
|
||||||
try {
|
|
||||||
$file = new stdClass();
|
|
||||||
$file->name = 'upload.txt';
|
|
||||||
$file->data = 'This is a test text!';
|
|
||||||
$result = $sc->uploadFile($file);
|
|
||||||
|
|
||||||
var_dump(
|
|
||||||
$result->return
|
|
||||||
);
|
|
||||||
|
|
||||||
$file = new stdClass();
|
|
||||||
$file->name = 'upload.txt';
|
|
||||||
$result = $sc->downloadFile($file);
|
|
||||||
|
|
||||||
var_dump(
|
|
||||||
$result->data
|
|
||||||
);
|
|
||||||
|
|
||||||
$file = new stdClass();
|
|
||||||
$file->name = 'image.jpg'; // source: http://www.freeimageslive.com/galleries/light/pics/swirl3768.jpg
|
|
||||||
$file->data = file_get_contents('image.jpg');
|
|
||||||
$result = $sc->uploadFile($file);
|
|
||||||
|
|
||||||
var_dump(
|
|
||||||
$result->return
|
|
||||||
);
|
|
||||||
|
|
||||||
$crc32 = crc32($file->data);
|
|
||||||
|
|
||||||
$file = new stdClass();
|
|
||||||
$file->name = 'image.jpg';
|
|
||||||
$result = $sc->downloadFile($file);
|
|
||||||
|
|
||||||
file_put_contents('image2.jpg', $result->data);
|
|
||||||
|
|
||||||
|
|
||||||
var_dump(
|
|
||||||
crc32($result->data) === $crc32
|
|
||||||
);
|
|
||||||
|
|
||||||
} catch (Exception $e) {
|
|
||||||
var_dump($e);
|
|
||||||
}
|
|
||||||
|
|
||||||
// var_dump(
|
|
||||||
// $sc->__getLastRequestHeaders(),
|
|
||||||
// $sc->__getLastRequest(),
|
|
||||||
// $sc->__getLastResponseHeaders(),
|
|
||||||
// $sc->__getLastResponse()
|
|
||||||
// );
|
|
@ -0,0 +1,78 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Deploy "axis_services/besimple-swa.aar" to Apache Axis2 to get this
|
||||||
|
* example to work.
|
||||||
|
*
|
||||||
|
* Run ant to rebuild aar.
|
||||||
|
*
|
||||||
|
* Example based on:
|
||||||
|
* http://axis.apache.org/axis2/java/core/docs/mtom-guide.html#a3
|
||||||
|
* http://wso2.org/library/1675
|
||||||
|
*
|
||||||
|
* Doesn't work directly with ?wsdl served by Apache Axis!
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
use BeSimple\SoapCommon\Helper as BeSimpleSoapHelper;
|
||||||
|
use BeSimple\SoapClient\SoapClient as BeSimpleSoapClient;
|
||||||
|
|
||||||
|
use BeSimple\SoapClient\Tests\AxisInterop\Fixtures\uploadFile;
|
||||||
|
use BeSimple\SoapClient\Tests\AxisInterop\Fixtures\uploadFileResponse;
|
||||||
|
use BeSimple\SoapClient\Tests\AxisInterop\Fixtures\downloadFile;
|
||||||
|
use BeSimple\SoapClient\Tests\AxisInterop\Fixtures\downloadFileResponse;
|
||||||
|
|
||||||
|
use BeSimple\SoapClient\Tests\AxisInterop\TestCase;
|
||||||
|
|
||||||
|
class SwaAxisInteropTest extends TestCase
|
||||||
|
{
|
||||||
|
private $options = array(
|
||||||
|
'soap_version' => SOAP_1_1,
|
||||||
|
'features' => SOAP_SINGLE_ELEMENT_ARRAYS, // make sure that result is array for size=1
|
||||||
|
'attachment_type' => BeSimpleSoapHelper::ATTACHMENTS_TYPE_SWA,
|
||||||
|
'cache_wsdl' => WSDL_CACHE_NONE,
|
||||||
|
'classmap' => array(
|
||||||
|
'downloadFile' => 'BeSimple\SoapClient\Tests\AxisInterop\Fixtures\downloadFile',
|
||||||
|
'downloadFileResponse' => 'BeSimple\SoapClient\Tests\AxisInterop\Fixtures\downloadFileResponse',
|
||||||
|
'uploadFile' => 'BeSimple\SoapClient\Tests\AxisInterop\Fixtures\uploadFile',
|
||||||
|
'uploadFileResponse' => 'BeSimple\SoapClient\Tests\AxisInterop\Fixtures\uploadFileResponse',
|
||||||
|
),
|
||||||
|
'proxy_host' => false,
|
||||||
|
);
|
||||||
|
|
||||||
|
public function testUploadDownloadText()
|
||||||
|
{
|
||||||
|
$sc = new BeSimpleSoapClient(__DIR__.'/Fixtures/SwA.wsdl', $this->options);
|
||||||
|
|
||||||
|
$upload = new uploadFile();
|
||||||
|
$upload->name = 'upload.txt';
|
||||||
|
$upload->data = 'This is a test. :)';
|
||||||
|
$result = $sc->uploadFile($upload);
|
||||||
|
|
||||||
|
$this->assertEquals('File saved succesfully.', $result->return);
|
||||||
|
|
||||||
|
$download = new downloadFile();
|
||||||
|
$download->name = 'upload.txt';
|
||||||
|
$result = $sc->downloadFile($download);
|
||||||
|
|
||||||
|
$this->assertEquals($upload->data, $result->data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUploadDownloadImage()
|
||||||
|
{
|
||||||
|
$sc = new BeSimpleSoapClient(__DIR__.'/Fixtures/SwA.wsdl', $this->options);
|
||||||
|
|
||||||
|
$upload = new uploadFile();
|
||||||
|
$upload->name = 'image.jpg';
|
||||||
|
$upload->data = file_get_contents(__DIR__.'/Fixtures/image.jpg'); // source: http://www.freeimageslive.com/galleries/light/pics/swirl3768.jpg;
|
||||||
|
$result = $sc->uploadFile($upload);
|
||||||
|
|
||||||
|
$this->assertEquals('File saved succesfully.', $result->return);
|
||||||
|
|
||||||
|
$download = new downloadFile();
|
||||||
|
$download->name = 'image.jpg';
|
||||||
|
$result = $sc->downloadFile($download);
|
||||||
|
|
||||||
|
$this->assertEquals($upload->data, $result->data);
|
||||||
|
}
|
||||||
|
}
|
23
src/BeSimple/SoapClient/Tests/AxisInterop/TestCase.php
Normal file
23
src/BeSimple/SoapClient/Tests/AxisInterop/TestCase.php
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BeSimple\SoapClient\Tests\AxisInterop;
|
||||||
|
|
||||||
|
class TestCase extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
protected function setUp()
|
||||||
|
{
|
||||||
|
$ch = curl_init('http://localhost:8080/');
|
||||||
|
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
|
||||||
|
curl_setopt($ch, CURLOPT_HEADER, true);
|
||||||
|
curl_setopt($ch, CURLOPT_NOBODY, true);
|
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
|
|
||||||
|
if (curl_exec($ch) === false) {
|
||||||
|
$this->markTestSkipped(
|
||||||
|
'The Axis server is not started on port 8080.'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
curl_close($ch);
|
||||||
|
}
|
||||||
|
}
|
@ -1,73 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use BeSimple\SoapClient\SoapClient as BeSimpleSoapClient;
|
|
||||||
use BeSimple\SoapClient\WsAddressingFilter as BeSimpleWsAddressingFilter;
|
|
||||||
|
|
||||||
require '../bootstrap.php';
|
|
||||||
|
|
||||||
$options = array(
|
|
||||||
'soap_version' => SOAP_1_2,
|
|
||||||
'features' => SOAP_SINGLE_ELEMENT_ARRAYS, // make sure that result is array for size=1
|
|
||||||
'trace' => true, // enables use of the methods SoapClient->__getLastRequest, SoapClient->__getLastRequestHeaders, SoapClient->__getLastResponse and SoapClient->__getLastResponseHeaders
|
|
||||||
);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Deploy "axis_services/version2.aar" to Apache Axis2 to get this example to
|
|
||||||
* work.
|
|
||||||
*
|
|
||||||
* To rebuild the "axis_services/version2.aar" the following steps need to be
|
|
||||||
* done to build a working Apache Axis2 version service with SOAP session
|
|
||||||
* enabled.
|
|
||||||
*
|
|
||||||
* 1) Go to $AXIS_HOME/samples/version and edit the following files:
|
|
||||||
*
|
|
||||||
* resources/META-INF/services.xml:
|
|
||||||
* <service name="Version2" scope="soapsession">
|
|
||||||
* ...
|
|
||||||
* </service>
|
|
||||||
*
|
|
||||||
* build.xml:
|
|
||||||
* replace version.aar with version2.aar
|
|
||||||
*
|
|
||||||
* 2) Run ant build.xml in "$AXIS_HOME/samples/version"
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
$sc = new BeSimpleSoapClient('http://localhost:8080/axis2/services/Version2?wsdl', $options);
|
|
||||||
$soapKernel = $sc->getSoapKernel();
|
|
||||||
$wsaFilter = new BeSimpleWsAddressingFilter();
|
|
||||||
$soapKernel->registerFilter($wsaFilter);
|
|
||||||
|
|
||||||
//var_dump($sc->__getFunctions());
|
|
||||||
//var_dump($sc->__getTypes());
|
|
||||||
|
|
||||||
try {
|
|
||||||
$wsaFilter->setReplyTo(BeSimpleWsAddressingFilter::ENDPOINT_REFERENCE_ANONYMOUS);
|
|
||||||
$wsaFilter->setMessageId();
|
|
||||||
|
|
||||||
var_dump($sc->getVersion());
|
|
||||||
|
|
||||||
$soapSessionId1 = $wsaFilter->getReferenceParameter('http://ws.apache.org/namespaces/axis2', 'ServiceGroupId');
|
|
||||||
echo 'ID1: ' .$soapSessionId1 . PHP_EOL;
|
|
||||||
|
|
||||||
$wsaFilter->addReferenceParameter('http://ws.apache.org/namespaces/axis2', 'axis2', 'ServiceGroupId', $soapSessionId1);
|
|
||||||
|
|
||||||
var_dump($sc->getVersion());
|
|
||||||
|
|
||||||
$soapSessionId2 = $wsaFilter->getReferenceParameter('http://ws.apache.org/namespaces/axis2', 'ServiceGroupId');
|
|
||||||
echo 'ID2: ' . $soapSessionId2 . PHP_EOL;
|
|
||||||
|
|
||||||
if ($soapSessionId1 == $soapSessionId2) {
|
|
||||||
echo PHP_EOL;
|
|
||||||
echo 'SOAP session worked :)';
|
|
||||||
}
|
|
||||||
} catch (Exception $e) {
|
|
||||||
var_dump($e);
|
|
||||||
}
|
|
||||||
|
|
||||||
// var_dump(
|
|
||||||
// $sc->__getLastRequestHeaders(),
|
|
||||||
// $sc->__getLastRequest(),
|
|
||||||
// $sc->__getLastResponseHeaders(),
|
|
||||||
// $sc->__getLastResponse()
|
|
||||||
// );
|
|
@ -0,0 +1,60 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Deploy "axis_services/version2.aar" to Apache Axis2 to get this example to
|
||||||
|
* work.
|
||||||
|
*
|
||||||
|
* To rebuild the "axis_services/version2.aar" the following steps need to be
|
||||||
|
* done to build a working Apache Axis2 version service with SOAP session
|
||||||
|
* enabled.
|
||||||
|
*
|
||||||
|
* 1) Go to $AXIS_HOME/samples/version and edit the following files:
|
||||||
|
*
|
||||||
|
* resources/META-INF/services.xml:
|
||||||
|
* <service name="Version2" scope="soapsession">
|
||||||
|
* ...
|
||||||
|
* </service>
|
||||||
|
*
|
||||||
|
* build.xml:
|
||||||
|
* replace version.aar with version2.aar
|
||||||
|
*
|
||||||
|
* 2) Run ant build.xml in "$AXIS_HOME/samples/version"
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
use BeSimple\SoapClient\SoapClient as BeSimpleSoapClient;
|
||||||
|
use BeSimple\SoapClient\WsAddressingFilter as BeSimpleWsAddressingFilter;
|
||||||
|
|
||||||
|
use BeSimple\SoapClient\Tests\AxisInterop\TestCase;
|
||||||
|
|
||||||
|
class WsAddressingAxisInteropTest extends TestCase
|
||||||
|
{
|
||||||
|
private $options = array(
|
||||||
|
'soap_version' => SOAP_1_2,
|
||||||
|
'features' => SOAP_SINGLE_ELEMENT_ARRAYS, // make sure that result is array for size=1
|
||||||
|
'proxy_host' => false,
|
||||||
|
);
|
||||||
|
|
||||||
|
public function testSession()
|
||||||
|
{
|
||||||
|
$sc = new BeSimpleSoapClient('http://localhost:8080/axis2/services/Version2?wsdl', $this->options);
|
||||||
|
$soapKernel = $sc->getSoapKernel();
|
||||||
|
$wsaFilter = new BeSimpleWsAddressingFilter();
|
||||||
|
$soapKernel->registerFilter($wsaFilter);
|
||||||
|
|
||||||
|
$wsaFilter->setReplyTo(BeSimpleWsAddressingFilter::ENDPOINT_REFERENCE_ANONYMOUS);
|
||||||
|
$wsaFilter->setMessageId();
|
||||||
|
|
||||||
|
$version = $sc->getVersion();
|
||||||
|
|
||||||
|
$soapSessionId1 = $wsaFilter->getReferenceParameter('http://ws.apache.org/namespaces/axis2', 'ServiceGroupId');
|
||||||
|
|
||||||
|
$wsaFilter->addReferenceParameter('http://ws.apache.org/namespaces/axis2', 'axis2', 'ServiceGroupId', $soapSessionId1);
|
||||||
|
|
||||||
|
$version = $sc->getVersion();
|
||||||
|
|
||||||
|
$soapSessionId2 = $wsaFilter->getReferenceParameter('http://ws.apache.org/namespaces/axis2', 'ServiceGroupId');
|
||||||
|
|
||||||
|
$this->assertEquals($soapSessionId1, $soapSessionId2);
|
||||||
|
}
|
||||||
|
}
|
@ -1,116 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use ass\XmlSecurity\Key as XmlSecurityKey;
|
|
||||||
|
|
||||||
use BeSimple\SoapClient\SoapClient as BeSimpleSoapClient;
|
|
||||||
use BeSimple\SoapClient\WsSecurityFilter as BeSimpleWsSecurityFilter;
|
|
||||||
use BeSimple\SoapCommon\WsSecurityKey as BeSimpleWsSecurityKey;
|
|
||||||
|
|
||||||
require '../bootstrap.php';
|
|
||||||
|
|
||||||
echo '<pre>';
|
|
||||||
|
|
||||||
$options = array(
|
|
||||||
'soap_version' => SOAP_1_2,
|
|
||||||
'features' => SOAP_SINGLE_ELEMENT_ARRAYS, // make sure that result is array for size=1
|
|
||||||
'trace' => true, // enables use of the methods SoapClient->__getLastRequest, SoapClient->__getLastRequestHeaders, SoapClient->__getLastResponse and SoapClient->__getLastResponseHeaders
|
|
||||||
);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Deploy "axis_services/library-signencr.aar" to Apache Axis2 to get this
|
|
||||||
* example to work.
|
|
||||||
*
|
|
||||||
* Links:
|
|
||||||
* http://www.dcc.uchile.cl/~pcamacho/tutorial/web/xmlsec/xmlsec.html
|
|
||||||
* http://www.aleksey.com/xmlsec/xmldsig-verifier.html
|
|
||||||
*
|
|
||||||
* Using code from axis example:
|
|
||||||
* http://www.ibm.com/developerworks/java/library/j-jws5/index.html
|
|
||||||
*
|
|
||||||
* Download key tool to export private key
|
|
||||||
* http://couchpotato.net/pkeytool/
|
|
||||||
*
|
|
||||||
* keytool -export -alias serverkey -keystore server.keystore -storepass nosecret -file servercert.cer
|
|
||||||
* openssl x509 -out servercert.pem -outform pem -in servercert.pem -inform der
|
|
||||||
*
|
|
||||||
* keytool -export -alias clientkey -keystore client.keystore -storepass nosecret -file clientcert.cer
|
|
||||||
* openssl x509 -out clientcert.pem -outform pem -in clientcert.pem -inform der
|
|
||||||
* java -jar pkeytool.jar -exportkey -keystore client.keystore -storepass nosecret -keypass clientpass -rfc -alias clientkey -file clientkey.pem
|
|
||||||
*
|
|
||||||
* C:\Program Files\Java\jre6\bin\keytool -export -alias serverkey -keystore server.keystore -storepass nosecret -file servercert.cer
|
|
||||||
* C:\xampp\apache\bin\openssl x509 -out servercert.pem -outform pem -in servercert.cer -inform der
|
|
||||||
*
|
|
||||||
* C:\Program Files\Java\jre6\bin\keytool -export -alias clientkey -keystore client.keystore -storepass nosecret -file clientcert.cer
|
|
||||||
* C:\xampp\apache\bin\openssl x509 -out clientcert.pem -outform pem -in clientcert.cer -inform der
|
|
||||||
* java -jar C:\axis2\pkeytool\pkeytool.jar -exportkey -keystore client.keystore -storepass nosecret -keypass clientpass -rfc -alias clientkey -file clientkey.pem
|
|
||||||
*
|
|
||||||
* build.properties:
|
|
||||||
* server-policy=hash-policy-server.xml
|
|
||||||
*
|
|
||||||
* allows both text and digest!
|
|
||||||
*/
|
|
||||||
|
|
||||||
class getBook {}
|
|
||||||
class getBookResponse {}
|
|
||||||
class getBooksByType {}
|
|
||||||
class getBooksByTypeResponse {}
|
|
||||||
class addBook {}
|
|
||||||
class addBookResponse {}
|
|
||||||
class BookInformation {}
|
|
||||||
|
|
||||||
$options['classmap'] = array(
|
|
||||||
'getBook' => 'getBook',
|
|
||||||
'getBookResponse' => 'getBookResponse',
|
|
||||||
'getBooksByType' => 'getBooksByType',
|
|
||||||
'getBooksByTypeResponse' => 'getBooksByTypeResponse',
|
|
||||||
'addBook' => 'addBook',
|
|
||||||
'addBookResponse' => 'addBookResponse',
|
|
||||||
'BookInformation' => 'BookInformation',
|
|
||||||
);
|
|
||||||
|
|
||||||
$sc = new BeSimpleSoapClient('WsSecuritySigEnc.wsdl', $options);
|
|
||||||
|
|
||||||
$wssFilter = new BeSimpleWsSecurityFilter();
|
|
||||||
// user key for signature and encryption
|
|
||||||
$securityKeyUser = new BeSimpleWsSecurityKey();
|
|
||||||
$securityKeyUser->addPrivateKey(XmlSecurityKey::RSA_SHA1, 'clientkey.pem', true);
|
|
||||||
$securityKeyUser->addPublicKey(XmlSecurityKey::RSA_SHA1, 'clientcert.pem', true);
|
|
||||||
$wssFilter->setUserSecurityKeyObject($securityKeyUser);
|
|
||||||
// service key for encryption
|
|
||||||
$securityKeyService = new BeSimpleWsSecurityKey();
|
|
||||||
$securityKeyService->addPrivateKey(XmlSecurityKey::TRIPLEDES_CBC);
|
|
||||||
$securityKeyService->addPublicKey(XmlSecurityKey::RSA_1_5, 'servercert.pem', true);
|
|
||||||
$wssFilter->setServiceSecurityKeyObject($securityKeyService);
|
|
||||||
// TOKEN_REFERENCE_SUBJECT_KEY_IDENTIFIER | TOKEN_REFERENCE_SECURITY_TOKEN | TOKEN_REFERENCE_THUMBPRINT_SHA1
|
|
||||||
$wssFilter->setSecurityOptionsSignature(BeSimpleWsSecurityFilter::TOKEN_REFERENCE_SECURITY_TOKEN);
|
|
||||||
$wssFilter->setSecurityOptionsEncryption(BeSimpleWsSecurityFilter::TOKEN_REFERENCE_THUMBPRINT_SHA1);
|
|
||||||
|
|
||||||
$soapKernel = $sc->getSoapKernel();
|
|
||||||
$soapKernel->registerFilter($wssFilter);
|
|
||||||
|
|
||||||
//var_dump($sc->__getFunctions());
|
|
||||||
//var_dump($sc->__getTypes());
|
|
||||||
|
|
||||||
try {
|
|
||||||
$gb = new getBook();
|
|
||||||
$gb->isbn = '0061020052';
|
|
||||||
var_dump($sc->getBook($gb));
|
|
||||||
|
|
||||||
$ab = new addBook();
|
|
||||||
$ab->isbn = '0445203498';
|
|
||||||
$ab->title = 'The Dragon Never Sleeps';
|
|
||||||
$ab->author = 'Cook, Glen';
|
|
||||||
$ab->type = 'scifi';
|
|
||||||
var_dump($sc->addBook($ab));
|
|
||||||
|
|
||||||
// getBooksByType("scifi");
|
|
||||||
} catch (Exception $e) {
|
|
||||||
var_dump($e);
|
|
||||||
}
|
|
||||||
|
|
||||||
//var_dump(
|
|
||||||
// $sc->__getLastRequestHeaders(),
|
|
||||||
// $sc->__getLastRequest(),
|
|
||||||
// $sc->__getLastResponseHeaders(),
|
|
||||||
// $sc->__getLastResponse()
|
|
||||||
//);
|
|
@ -0,0 +1,107 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Deploy "axis_services/library-signencr.aar" to Apache Axis2 to get this
|
||||||
|
* example to work.
|
||||||
|
*
|
||||||
|
* Links:
|
||||||
|
* http://www.dcc.uchile.cl/~pcamacho/tutorial/web/xmlsec/xmlsec.html
|
||||||
|
* http://www.aleksey.com/xmlsec/xmldsig-verifier.html
|
||||||
|
*
|
||||||
|
* Using code from axis example:
|
||||||
|
* http://www.ibm.com/developerworks/java/library/j-jws5/index.html
|
||||||
|
*
|
||||||
|
* Download key tool to export private key
|
||||||
|
* http://couchpotato.net/pkeytool/
|
||||||
|
*
|
||||||
|
* keytool -export -alias serverkey -keystore server.keystore -storepass nosecret -file servercert.cer
|
||||||
|
* openssl x509 -out servercert.pem -outform pem -in servercert.pem -inform der
|
||||||
|
*
|
||||||
|
* keytool -export -alias clientkey -keystore client.keystore -storepass nosecret -file clientcert.cer
|
||||||
|
* openssl x509 -out clientcert.pem -outform pem -in clientcert.pem -inform der
|
||||||
|
* java -jar pkeytool.jar -exportkey -keystore client.keystore -storepass nosecret -keypass clientpass -rfc -alias clientkey -file clientkey.pem
|
||||||
|
*
|
||||||
|
* C:\Program Files\Java\jre6\bin\keytool -export -alias serverkey -keystore server.keystore -storepass nosecret -file servercert.cer
|
||||||
|
* C:\xampp\apache\bin\openssl x509 -out servercert.pem -outform pem -in servercert.cer -inform der
|
||||||
|
*
|
||||||
|
* C:\Program Files\Java\jre6\bin\keytool -export -alias clientkey -keystore client.keystore -storepass nosecret -file clientcert.cer
|
||||||
|
* C:\xampp\apache\bin\openssl x509 -out clientcert.pem -outform pem -in clientcert.cer -inform der
|
||||||
|
* java -jar C:\axis2\pkeytool\pkeytool.jar -exportkey -keystore client.keystore -storepass nosecret -keypass clientpass -rfc -alias clientkey -file clientkey.pem
|
||||||
|
*
|
||||||
|
* build.properties:
|
||||||
|
* server-policy=hash-policy-server.xml
|
||||||
|
*
|
||||||
|
* allows both text and digest!
|
||||||
|
*/
|
||||||
|
|
||||||
|
use ass\XmlSecurity\Key as XmlSecurityKey;
|
||||||
|
|
||||||
|
use BeSimple\SoapClient\SoapClient as BeSimpleSoapClient;
|
||||||
|
use BeSimple\SoapClient\WsSecurityFilter as BeSimpleWsSecurityFilter;
|
||||||
|
use BeSimple\SoapCommon\WsSecurityKey as BeSimpleWsSecurityKey;
|
||||||
|
|
||||||
|
use BeSimple\SoapClient\Tests\AxisInterop\Fixtures\getBook;
|
||||||
|
use BeSimple\SoapClient\Tests\AxisInterop\Fixtures\getBookResponse;
|
||||||
|
use BeSimple\SoapClient\Tests\AxisInterop\Fixtures\getBooksByType;
|
||||||
|
use BeSimple\SoapClient\Tests\AxisInterop\Fixtures\getBooksByTypeResponse;
|
||||||
|
use BeSimple\SoapClient\Tests\AxisInterop\Fixtures\addBook;
|
||||||
|
use BeSimple\SoapClient\Tests\AxisInterop\Fixtures\addBookResponse;
|
||||||
|
use BeSimple\SoapClient\Tests\AxisInterop\Fixtures\BookInformation;
|
||||||
|
|
||||||
|
use BeSimple\SoapClient\Tests\AxisInterop\TestCase;
|
||||||
|
|
||||||
|
class WsSecuritySigEncAxisInteropTest extends TestCase
|
||||||
|
{
|
||||||
|
private $options = array(
|
||||||
|
'soap_version' => SOAP_1_2,
|
||||||
|
'features' => SOAP_SINGLE_ELEMENT_ARRAYS, // make sure that result is array for size=1
|
||||||
|
'classmap' => array(
|
||||||
|
'getBook' => 'BeSimple\SoapClient\Tests\AxisInterop\Fixtures\getBook',
|
||||||
|
'getBookResponse' => 'BeSimple\SoapClient\Tests\AxisInterop\Fixtures\getBookResponse',
|
||||||
|
'getBooksByType' => 'BeSimple\SoapClient\Tests\AxisInterop\Fixtures\getBooksByType',
|
||||||
|
'getBooksByTypeResponse' => 'BeSimple\SoapClient\Tests\AxisInterop\Fixtures\getBooksByTypeResponse',
|
||||||
|
'addBook' => 'BeSimple\SoapClient\Tests\AxisInterop\Fixtures\addBook',
|
||||||
|
'addBookResponse' => 'BeSimple\SoapClient\Tests\AxisInterop\Fixtures\addBookResponse',
|
||||||
|
'BookInformation' => 'BeSimple\SoapClient\Tests\AxisInterop\Fixtures\BookInformation',
|
||||||
|
),
|
||||||
|
'proxy_host' => false,
|
||||||
|
);
|
||||||
|
|
||||||
|
public function testSigEnc()
|
||||||
|
{
|
||||||
|
$sc = new BeSimpleSoapClient(__DIR__.'/Fixtures/WsSecuritySigEnc.wsdl', $this->options);
|
||||||
|
|
||||||
|
$wssFilter = new BeSimpleWsSecurityFilter();
|
||||||
|
// user key for signature and encryption
|
||||||
|
$securityKeyUser = new BeSimpleWsSecurityKey();
|
||||||
|
$securityKeyUser->addPrivateKey(XmlSecurityKey::RSA_SHA1, __DIR__.'/Fixtures/clientkey.pem', true);
|
||||||
|
$securityKeyUser->addPublicKey(XmlSecurityKey::RSA_SHA1, __DIR__.'/Fixtures/clientcert.pem', true);
|
||||||
|
$wssFilter->setUserSecurityKeyObject($securityKeyUser);
|
||||||
|
// service key for encryption
|
||||||
|
$securityKeyService = new BeSimpleWsSecurityKey();
|
||||||
|
$securityKeyService->addPrivateKey(XmlSecurityKey::TRIPLEDES_CBC);
|
||||||
|
$securityKeyService->addPublicKey(XmlSecurityKey::RSA_1_5, __DIR__.'/Fixtures/servercert.pem', true);
|
||||||
|
$wssFilter->setServiceSecurityKeyObject($securityKeyService);
|
||||||
|
// TOKEN_REFERENCE_SUBJECT_KEY_IDENTIFIER | TOKEN_REFERENCE_SECURITY_TOKEN | TOKEN_REFERENCE_THUMBPRINT_SHA1
|
||||||
|
$wssFilter->setSecurityOptionsSignature(BeSimpleWsSecurityFilter::TOKEN_REFERENCE_SECURITY_TOKEN);
|
||||||
|
$wssFilter->setSecurityOptionsEncryption(BeSimpleWsSecurityFilter::TOKEN_REFERENCE_THUMBPRINT_SHA1);
|
||||||
|
|
||||||
|
$soapKernel = $sc->getSoapKernel();
|
||||||
|
$soapKernel->registerFilter($wssFilter);
|
||||||
|
|
||||||
|
$gb = new getBook();
|
||||||
|
$gb->isbn = '0061020052';
|
||||||
|
$result = $sc->getBook($gb);
|
||||||
|
$this->assertInstanceOf('BeSimple\SoapClient\Tests\AxisInterop\Fixtures\BookInformation', $result->getBookReturn);
|
||||||
|
|
||||||
|
$ab = new addBook();
|
||||||
|
$ab->isbn = '0445203498';
|
||||||
|
$ab->title = 'The Dragon Never Sleeps';
|
||||||
|
$ab->author = 'Cook, Glen';
|
||||||
|
$ab->type = 'scifi';
|
||||||
|
|
||||||
|
$this->assertTrue((bool) $sc->addBook($ab));
|
||||||
|
|
||||||
|
// getBooksByType("scifi");
|
||||||
|
}
|
||||||
|
}
|
@ -1,79 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use BeSimple\SoapClient\SoapClient as BeSimpleSoapClient;
|
|
||||||
use BeSimple\SoapClient\WsSecurityFilter as BeSimpleWsSecurityFilter;
|
|
||||||
|
|
||||||
require '../bootstrap.php';
|
|
||||||
|
|
||||||
$options = array(
|
|
||||||
'soap_version' => SOAP_1_2,
|
|
||||||
'features' => SOAP_SINGLE_ELEMENT_ARRAYS, // make sure that result is array for size=1
|
|
||||||
'trace' => true, // enables use of the methods SoapClient->__getLastRequest, SoapClient->__getLastRequestHeaders, SoapClient->__getLastResponse and SoapClient->__getLastResponseHeaders
|
|
||||||
);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Deploy "axis_services/library-username-digest.aar" to Apache Axis2 to get
|
|
||||||
* this example to work.
|
|
||||||
*
|
|
||||||
* Using code from axis example:
|
|
||||||
* http://www.ibm.com/developerworks/java/library/j-jws4/index.html
|
|
||||||
*
|
|
||||||
* build.properties:
|
|
||||||
* server-policy=hash-policy-server.xml
|
|
||||||
*
|
|
||||||
* allows both text and digest!
|
|
||||||
*/
|
|
||||||
|
|
||||||
class getBook {}
|
|
||||||
class getBookResponse {}
|
|
||||||
class getBooksByType {}
|
|
||||||
class getBooksByTypeResponse {}
|
|
||||||
class addBook {}
|
|
||||||
class addBookResponse {}
|
|
||||||
class BookInformation {}
|
|
||||||
|
|
||||||
$options['classmap'] = array(
|
|
||||||
'getBook' => 'getBook',
|
|
||||||
'getBookResponse' => 'getBookResponse',
|
|
||||||
'getBooksByType' => 'getBooksByType',
|
|
||||||
'getBooksByTypeResponse' => 'getBooksByTypeResponse',
|
|
||||||
'addBook' => 'addBook',
|
|
||||||
'addBookResponse' => 'addBookResponse',
|
|
||||||
'BookInformation' => 'BookInformation',
|
|
||||||
);
|
|
||||||
|
|
||||||
$sc = new BeSimpleSoapClient('WsSecurityUserPass.wsdl', $options);
|
|
||||||
|
|
||||||
$wssFilter = new BeSimpleWsSecurityFilter(true, 600);
|
|
||||||
$wssFilter->addUserData('libuser', 'books', BeSimpleWsSecurityFilter::PASSWORD_TYPE_TEXT);
|
|
||||||
//$wssFilter->addUserData( 'libuser', 'books', BeSimpleWsSecurityFilter::PASSWORD_TYPE_DIGEST );
|
|
||||||
|
|
||||||
$soapKernel = $sc->getSoapKernel();
|
|
||||||
$soapKernel->registerFilter($wssFilter);
|
|
||||||
|
|
||||||
//var_dump($sc->__getFunctions());
|
|
||||||
//var_dump($sc->__getTypes());
|
|
||||||
|
|
||||||
try {
|
|
||||||
$gb = new getBook();
|
|
||||||
$gb->isbn = '0061020052';
|
|
||||||
var_dump($sc->getBook($gb));
|
|
||||||
|
|
||||||
$ab = new addBook();
|
|
||||||
$ab->isbn = '0445203498';
|
|
||||||
$ab->title = 'The Dragon Never Sleeps';
|
|
||||||
$ab->author = 'Cook, Glen';
|
|
||||||
$ab->type = 'scifi';
|
|
||||||
var_dump($sc->addBook($ab));
|
|
||||||
|
|
||||||
// getBooksByType("scifi");
|
|
||||||
} catch (Exception $e) {
|
|
||||||
var_dump($e);
|
|
||||||
}
|
|
||||||
|
|
||||||
//var_dump(
|
|
||||||
// $sc->__getLastRequestHeaders(),
|
|
||||||
// $sc->__getLastRequest(),
|
|
||||||
// $sc->__getLastResponseHeaders(),
|
|
||||||
// $sc->__getLastResponse()
|
|
||||||
//);
|
|
@ -0,0 +1,97 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Deploy "axis_services/library-username-digest.aar" to Apache Axis2 to get
|
||||||
|
* this example to work.
|
||||||
|
*
|
||||||
|
* Using code from axis example:
|
||||||
|
* http://www.ibm.com/developerworks/java/library/j-jws4/index.html
|
||||||
|
*
|
||||||
|
* build.properties:
|
||||||
|
* server-policy=hash-policy-server.xml
|
||||||
|
*
|
||||||
|
* allows both text and digest!
|
||||||
|
*/
|
||||||
|
|
||||||
|
use BeSimple\SoapClient\SoapClient as BeSimpleSoapClient;
|
||||||
|
use BeSimple\SoapClient\WsSecurityFilter as BeSimpleWsSecurityFilter;
|
||||||
|
|
||||||
|
use BeSimple\SoapClient\Tests\AxisInterop\Fixtures\getBook;
|
||||||
|
use BeSimple\SoapClient\Tests\AxisInterop\Fixtures\getBookResponse;
|
||||||
|
use BeSimple\SoapClient\Tests\AxisInterop\Fixtures\getBooksByType;
|
||||||
|
use BeSimple\SoapClient\Tests\AxisInterop\Fixtures\getBooksByTypeResponse;
|
||||||
|
use BeSimple\SoapClient\Tests\AxisInterop\Fixtures\addBook;
|
||||||
|
use BeSimple\SoapClient\Tests\AxisInterop\Fixtures\addBookResponse;
|
||||||
|
use BeSimple\SoapClient\Tests\AxisInterop\Fixtures\BookInformation;
|
||||||
|
|
||||||
|
use BeSimple\SoapClient\Tests\AxisInterop\TestCase;
|
||||||
|
|
||||||
|
class WsSecurityUserPassAxisInteropTest extends TestCase
|
||||||
|
{
|
||||||
|
private $options = array(
|
||||||
|
'soap_version' => SOAP_1_2,
|
||||||
|
'features' => SOAP_SINGLE_ELEMENT_ARRAYS, // make sure that result is array for size=1
|
||||||
|
'classmap' => array(
|
||||||
|
'getBook' => 'BeSimple\SoapClient\Tests\AxisInterop\Fixtures\getBook',
|
||||||
|
'getBookResponse' => 'BeSimple\SoapClient\Tests\AxisInterop\Fixtures\getBookResponse',
|
||||||
|
'getBooksByType' => 'BeSimple\SoapClient\Tests\AxisInterop\Fixtures\getBooksByType',
|
||||||
|
'getBooksByTypeResponse' => 'BeSimple\SoapClient\Tests\AxisInterop\Fixtures\getBooksByTypeResponse',
|
||||||
|
'addBook' => 'BeSimple\SoapClient\Tests\AxisInterop\Fixtures\addBook',
|
||||||
|
'addBookResponse' => 'BeSimple\SoapClient\Tests\AxisInterop\Fixtures\addBookResponse',
|
||||||
|
'BookInformation' => 'BeSimple\SoapClient\Tests\AxisInterop\Fixtures\BookInformation',
|
||||||
|
),
|
||||||
|
'proxy_host' => false,
|
||||||
|
);
|
||||||
|
|
||||||
|
public function testUserPassText()
|
||||||
|
{
|
||||||
|
$sc = new BeSimpleSoapClient(__DIR__.'/Fixtures/WsSecurityUserPass.wsdl', $this->options);
|
||||||
|
|
||||||
|
$wssFilter = new BeSimpleWsSecurityFilter(true, 600);
|
||||||
|
$wssFilter->addUserData('libuser', 'books', BeSimpleWsSecurityFilter::PASSWORD_TYPE_TEXT);
|
||||||
|
|
||||||
|
$soapKernel = $sc->getSoapKernel();
|
||||||
|
$soapKernel->registerFilter($wssFilter);
|
||||||
|
|
||||||
|
$gb = new getBook();
|
||||||
|
$gb->isbn = '0061020052';
|
||||||
|
$result = $sc->getBook($gb);
|
||||||
|
$this->assertInstanceOf('BeSimple\SoapClient\Tests\AxisInterop\Fixtures\BookInformation', $result->getBookReturn);
|
||||||
|
|
||||||
|
$ab = new addBook();
|
||||||
|
$ab->isbn = '0445203498';
|
||||||
|
$ab->title = 'The Dragon Never Sleeps';
|
||||||
|
$ab->author = 'Cook, Glen';
|
||||||
|
$ab->type = 'scifi';
|
||||||
|
|
||||||
|
$this->assertTrue((bool) $sc->addBook($ab));
|
||||||
|
|
||||||
|
// getBooksByType("scifi");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUserPassDigest()
|
||||||
|
{
|
||||||
|
$sc = new BeSimpleSoapClient(__DIR__.'/Fixtures/WsSecurityUserPass.wsdl', $this->options);
|
||||||
|
|
||||||
|
$wssFilter = new BeSimpleWsSecurityFilter(true, 600);
|
||||||
|
$wssFilter->addUserData('libuser', 'books', BeSimpleWsSecurityFilter::PASSWORD_TYPE_DIGEST);
|
||||||
|
|
||||||
|
$soapKernel = $sc->getSoapKernel();
|
||||||
|
$soapKernel->registerFilter($wssFilter);
|
||||||
|
|
||||||
|
$gb = new getBook();
|
||||||
|
$gb->isbn = '0061020052';
|
||||||
|
$result = $sc->getBook($gb);
|
||||||
|
$this->assertInstanceOf('BeSimple\SoapClient\Tests\AxisInterop\Fixtures\BookInformation', $result->getBookReturn);
|
||||||
|
|
||||||
|
$ab = new addBook();
|
||||||
|
$ab->isbn = '0445203498';
|
||||||
|
$ab->title = 'The Dragon Never Sleeps';
|
||||||
|
$ab->author = 'Cook, Glen';
|
||||||
|
$ab->type = 'scifi';
|
||||||
|
|
||||||
|
$this->assertTrue((bool) $sc->addBook($ab));
|
||||||
|
|
||||||
|
// getBooksByType("scifi");
|
||||||
|
}
|
||||||
|
}
|
@ -21,7 +21,9 @@ class CurlTest extends AbstractWebserverTest
|
|||||||
{
|
{
|
||||||
public function testExec()
|
public function testExec()
|
||||||
{
|
{
|
||||||
$curl = new Curl();
|
$curl = new Curl(array(
|
||||||
|
'proxy_host' => false,
|
||||||
|
));
|
||||||
|
|
||||||
$this->assertTrue($curl->exec(sprintf('http://localhost:%d/curl.txt', WEBSERVER_PORT)));
|
$this->assertTrue($curl->exec(sprintf('http://localhost:%d/curl.txt', WEBSERVER_PORT)));
|
||||||
$this->assertTrue($curl->exec(sprintf('http://localhost:%d/404.txt', WEBSERVER_PORT)));
|
$this->assertTrue($curl->exec(sprintf('http://localhost:%d/404.txt', WEBSERVER_PORT)));
|
||||||
@ -29,7 +31,9 @@ class CurlTest extends AbstractWebserverTest
|
|||||||
|
|
||||||
public function testGetErrorMessage()
|
public function testGetErrorMessage()
|
||||||
{
|
{
|
||||||
$curl = new Curl();
|
$curl = new Curl(array(
|
||||||
|
'proxy_host' => false,
|
||||||
|
));
|
||||||
|
|
||||||
$curl->exec('http://unknown/curl.txt');
|
$curl->exec('http://unknown/curl.txt');
|
||||||
$this->assertEquals('Could not connect to host', $curl->getErrorMessage());
|
$this->assertEquals('Could not connect to host', $curl->getErrorMessage());
|
||||||
@ -41,24 +45,14 @@ class CurlTest extends AbstractWebserverTest
|
|||||||
$this->assertEquals('Unable to parse URL', $curl->getErrorMessage());
|
$this->assertEquals('Unable to parse URL', $curl->getErrorMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetRequestHeaders()
|
|
||||||
{
|
|
||||||
$curl = new Curl();
|
|
||||||
|
|
||||||
$curl->exec(sprintf('http://localhost:%d/curl.txt', WEBSERVER_PORT));
|
|
||||||
$this->assertEquals(132 + self::$websererPortLength, strlen($curl->getRequestHeaders()));
|
|
||||||
|
|
||||||
$curl->exec(sprintf('http://localhost:%s/404.txt', WEBSERVER_PORT));
|
|
||||||
$this->assertEquals(131 + self::$websererPortLength, strlen($curl->getRequestHeaders()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testGetResponse()
|
public function testGetResponse()
|
||||||
{
|
{
|
||||||
$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->assertSame('OK', $curl->getResponseStatusMessage());
|
$this->assertSame('OK', $curl->getResponseStatusMessage());
|
||||||
$this->assertEquals(145 + self::$websererPortLength, strlen($curl->getResponse()));
|
|
||||||
|
|
||||||
$curl->exec(sprintf('http://localhost:%d/404.txt', WEBSERVER_PORT));
|
$curl->exec(sprintf('http://localhost:%d/404.txt', WEBSERVER_PORT));
|
||||||
$this->assertSame('Not Found', $curl->getResponseStatusMessage());
|
$this->assertSame('Not Found', $curl->getResponseStatusMessage());
|
||||||
@ -66,7 +60,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());
|
||||||
@ -74,7 +70,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());
|
||||||
@ -83,20 +81,11 @@ class CurlTest extends AbstractWebserverTest
|
|||||||
$this->assertEquals('text/html; charset=UTF-8', $curl->getResponseContentType());
|
$this->assertEquals('text/html; charset=UTF-8', $curl->getResponseContentType());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetResponseHeaders()
|
|
||||||
{
|
|
||||||
$curl = new Curl();
|
|
||||||
|
|
||||||
$curl->exec(sprintf('http://localhost:%d/curl.txt', WEBSERVER_PORT));
|
|
||||||
$this->assertEquals(117 + self::$websererPortLength, strlen($curl->getResponseHeaders()));
|
|
||||||
|
|
||||||
$curl->exec(sprintf('http://localhost:%d/404.txt', WEBSERVER_PORT));
|
|
||||||
$this->assertEquals(124 + self::$websererPortLength, strlen($curl->getResponseHeaders()));
|
|
||||||
}
|
|
||||||
|
|
||||||
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());
|
||||||
|
@ -0,0 +1,7 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BeSimple\SoapClient\Tests\ServerInterop\Fixtures;
|
||||||
|
|
||||||
|
class AttachmentRequest extends AttachmentType
|
||||||
|
{
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user