diff --git a/src/BeSimple/SoapBundle/Cache.php b/src/BeSimple/SoapBundle/Cache.php index e1c6cf0..fe5621f 100644 --- a/src/BeSimple/SoapBundle/Cache.php +++ b/src/BeSimple/SoapBundle/Cache.php @@ -25,17 +25,15 @@ class Cache BaseCache::setEnabled($isEnabled); - if (BaseCache::ENABLED == BaseCache::isEnabled()) { - BaseCache::setType($type); - BaseCache::setDirectory($directory); + BaseCache::setType($type); + BaseCache::setDirectory($directory); - if (null !== $lifetime) { - BaseCache::setLifetime($lifetime); - } + if (null !== $lifetime) { + BaseCache::setLifetime($lifetime); + } - if (null !== $limit) { - BaseCache::setLimit($limit); - } + if (null !== $limit) { + BaseCache::setLimit($limit); } } -} \ No newline at end of file +} diff --git a/src/BeSimple/SoapBundle/Resources/config/client.xml b/src/BeSimple/SoapBundle/Resources/config/client.xml index a6b5406..0af3c34 100644 --- a/src/BeSimple/SoapBundle/Resources/config/client.xml +++ b/src/BeSimple/SoapBundle/Resources/config/client.xml @@ -16,6 +16,7 @@ + diff --git a/src/BeSimple/SoapBundle/Resources/config/soap.xml b/src/BeSimple/SoapBundle/Resources/config/soap.xml index 1d54d67..28a7b1b 100644 --- a/src/BeSimple/SoapBundle/Resources/config/soap.xml +++ b/src/BeSimple/SoapBundle/Resources/config/soap.xml @@ -12,7 +12,7 @@ %kernel.debug% %besimple.soap.cache.type% - %besimple.soap.cache.dir%/php + %besimple.soap.cache.dir%/cache %besimple.soap.cache.lifetime% %besimple.soap.cache.limit% diff --git a/src/BeSimple/SoapBundle/Resources/doc/index.rst b/src/BeSimple/SoapBundle/Resources/doc/index.rst index 68aae30..f86b83f 100644 --- a/src/BeSimple/SoapBundle/Resources/doc/index.rst +++ b/src/BeSimple/SoapBundle/Resources/doc/index.rst @@ -33,4 +33,8 @@ SoapServer SoapClient ---------- -Coming soon. +.. toctree:: + :maxdepth: 1 + :numbered: + + soapclient/configuration diff --git a/src/BeSimple/SoapBundle/Resources/doc/soapclient/configuration.rst b/src/BeSimple/SoapBundle/Resources/doc/soapclient/configuration.rst new file mode 100644 index 0000000..bd715a4 --- /dev/null +++ b/src/BeSimple/SoapBundle/Resources/doc/soapclient/configuration.rst @@ -0,0 +1,146 @@ +Configuration +============= + +Minimal client configuration +---------------------------- + +Configure your first client in your config file: + +.. code-block:: yaml + + # app/config/config.yml + be_simple_soap: + clients: + DemoApi: + wsdl: http://localhost:8086/app_dev.php/ws/DemoApi?wsdl + + +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" + } diff --git a/src/BeSimple/SoapClient/SoapClient.php b/src/BeSimple/SoapClient/SoapClient.php index eb05b6d..0fa3c7d 100644 --- a/src/BeSimple/SoapClient/SoapClient.php +++ b/src/BeSimple/SoapClient/SoapClient.php @@ -41,15 +41,6 @@ class SoapClient extends \SoapClient */ protected $tracingEnabled = false; - /** - * Work around missing header/php://input access in PHP cli webserver by - * setting headers additionally as GET parameters and SOAP request body - * explicitly as POST variable. - * - * @var boolean - */ - private $cliWebserverWorkaround = false; - /** * cURL instance. * @@ -108,10 +99,7 @@ class SoapClient extends \SoapClient if (isset($options['soap_version'])) { $this->soapVersion = $options['soap_version']; } - // activate cli webserver workaround - if (isset($options['cli_webserver_workaround'])) { - $this->cliWebserverWorkaround = $options['cli_webserver_workaround']; - } + $this->curl = new Curl($options); if (isset($options['extra_options'])) { @@ -158,25 +146,6 @@ class SoapClient extends \SoapClient $location = $soapRequest->getLocation(); $content = $soapRequest->getContent(); - /* - * Work around missing header/php://input access in PHP cli webserver by - * setting headers additionally as GET parameters and SOAP request body - * explicitly as POST variable - */ - if ($this->cliWebserverWorkaround === true) { - if (strpos($location, '?') === false) { - $location .= '?'; - } else { - $location .= '&'; - } - $location .= SoapMessage::CONTENT_TYPE_HEADER.'='.urlencode($soapRequest->getContentType()); - $location .= '&'; - $location .= SoapMessage::SOAP_ACTION_HEADER.'='.urlencode($soapRequest->getAction()); - - $content = http_build_query(array('request' => $content)); - - $headers = array(); - } $headers = $this->filterRequestHeaders($soapRequest, $headers); @@ -189,6 +158,7 @@ class SoapClient extends \SoapClient $headers, $options ); + // tracing enabled: store last request header and body if ($this->tracingEnabled === true) { $this->lastRequestHeaders = $this->curl->getRequestHeaders(); diff --git a/src/BeSimple/SoapClient/Tests/ServerInterop/MTOMClient.php b/src/BeSimple/SoapClient/Tests/ServerInterop/MTOMClient.php index 45b72de..df5c5e9 100644 --- a/src/BeSimple/SoapClient/Tests/ServerInterop/MTOMClient.php +++ b/src/BeSimple/SoapClient/Tests/ServerInterop/MTOMClient.php @@ -18,7 +18,6 @@ $options = array( 'base64Binary' => 'BeSimple\SoapClient\Tests\ServerInterop\Fixtures\base64Binary', 'AttachmentRequest' => 'BeSimple\SoapClient\Tests\ServerInterop\Fixtures\AttachmentRequest', ), - 'cli_webserver_workaround' => true, // Work around missing header access in PHP cli webserver by setting headers additionally as GET parameters. 'connection_timeout' => 1, ); diff --git a/src/BeSimple/SoapClient/Tests/ServerInterop/MtomServerInteropTest.php b/src/BeSimple/SoapClient/Tests/ServerInterop/MtomServerInteropTest.php index 7277bed..779313f 100644 --- a/src/BeSimple/SoapClient/Tests/ServerInterop/MtomServerInteropTest.php +++ b/src/BeSimple/SoapClient/Tests/ServerInterop/MtomServerInteropTest.php @@ -20,7 +20,6 @@ class MtomServerInteropTest extends TestCase 'base64Binary' => 'BeSimple\SoapClient\Tests\ServerInterop\Fixtures\base64Binary', 'AttachmentRequest' => 'BeSimple\SoapClient\Tests\ServerInterop\Fixtures\AttachmentRequest', ), - 'cli_webserver_workaround' => true, // Work around missing header access in PHP cli webserver by setting headers additionally as GET parameters. ); public function testAttachment() diff --git a/src/BeSimple/SoapClient/Tests/ServerInterop/SwaClient.php b/src/BeSimple/SoapClient/Tests/ServerInterop/SwaClient.php index 054fefe..96f34fd 100644 --- a/src/BeSimple/SoapClient/Tests/ServerInterop/SwaClient.php +++ b/src/BeSimple/SoapClient/Tests/ServerInterop/SwaClient.php @@ -24,7 +24,6 @@ $options = array( 'uploadFile' => 'BeSimple\SoapClient\Tests\ServerInterop\Fixtures\uploadFile', 'uploadFileResponse' => 'BeSimple\SoapClient\Tests\ServerInterop\Fixtures\uploadFileResponse', ), - 'cli_webserver_workaround' => true, // Work around missing header access in PHP cli webserver by setting headers additionally as GET parameters. ); $sc = new BeSimpleSoapClient(__DIR__.'/Fixtures/SwA.wsdl', $options); diff --git a/src/BeSimple/SoapClient/Tests/ServerInterop/SwaServerInteropTest.php b/src/BeSimple/SoapClient/Tests/ServerInterop/SwaServerInteropTest.php index 73dc2aa..5f3e6f3 100644 --- a/src/BeSimple/SoapClient/Tests/ServerInterop/SwaServerInteropTest.php +++ b/src/BeSimple/SoapClient/Tests/ServerInterop/SwaServerInteropTest.php @@ -23,7 +23,6 @@ class SwaServerInteropTest extends TestCase 'uploadFile' => 'BeSimple\SoapClient\Tests\ServerInterop\Fixtures\uploadFile', 'uploadFileResponse' => 'BeSimple\SoapClient\Tests\ServerInterop\Fixtures\uploadFileResponse', ), - 'cli_webserver_workaround' => true, // Work around missing header access in PHP cli webserver by setting headers additionally as GET parameters. ); public function testUploadDownloadText() diff --git a/src/BeSimple/SoapClient/Tests/ServerInterop/WsSecuritySigEncServerClient.php b/src/BeSimple/SoapClient/Tests/ServerInterop/WsSecuritySigEncServerClient.php index 6c7fe1d..1d529d6 100644 --- a/src/BeSimple/SoapClient/Tests/ServerInterop/WsSecuritySigEncServerClient.php +++ b/src/BeSimple/SoapClient/Tests/ServerInterop/WsSecuritySigEncServerClient.php @@ -31,7 +31,6 @@ $options = array( 'addBookResponse' => 'BeSimple\SoapClient\Tests\ServerInterop\Fixtures\addBookResponse', 'BookInformation' => 'BeSimple\SoapClient\Tests\ServerInterop\Fixtures\BookInformation', ), - 'cli_webserver_workaround' => true, // Work around missing header access in PHP cli webserver by setting headers additionally as GET parameters. ); $sc = new BeSimpleSoapClient(__DIR__.'/Fixtures/WsSecuritySigEnc.wsdl', $options); diff --git a/src/BeSimple/SoapClient/Tests/ServerInterop/WsSecuritySigEncServerInteropTest.php b/src/BeSimple/SoapClient/Tests/ServerInterop/WsSecuritySigEncServerInteropTest.php index 7cbbef4..0ff0142 100644 --- a/src/BeSimple/SoapClient/Tests/ServerInterop/WsSecuritySigEncServerInteropTest.php +++ b/src/BeSimple/SoapClient/Tests/ServerInterop/WsSecuritySigEncServerInteropTest.php @@ -30,7 +30,6 @@ class WsSecuritySigEncServerInteropTest extends TestCase 'addBookResponse' => 'BeSimple\SoapClient\Tests\ServerInterop\Fixtures\addBookResponse', 'BookInformation' => 'BeSimple\SoapClient\Tests\ServerInterop\Fixtures\BookInformation', ), - 'cli_webserver_workaround' => true, // Work around missing header access in PHP cli webserver by setting headers additionally as GET parameters. ); public function testSigEnc() diff --git a/src/BeSimple/SoapClient/Tests/ServerInterop/WsSecurityUserPassServerClient.php b/src/BeSimple/SoapClient/Tests/ServerInterop/WsSecurityUserPassServerClient.php index b69b3d9..90cf534 100644 --- a/src/BeSimple/SoapClient/Tests/ServerInterop/WsSecurityUserPassServerClient.php +++ b/src/BeSimple/SoapClient/Tests/ServerInterop/WsSecurityUserPassServerClient.php @@ -28,7 +28,6 @@ $options = array( 'addBookResponse' => 'BeSimple\SoapClient\Tests\ServerInterop\Fixtures\addBookResponse', 'BookInformation' => 'BeSimple\SoapClient\Tests\ServerInterop\Fixtures\BookInformation', ), - 'cli_webserver_workaround' => true, // Work around missing header access in PHP cli webserver by setting headers additionally as GET parameters. ); $sc = new BeSimpleSoapClient(__DIR__.'/Fixtures/WsSecurityUserPass.wsdl', $options); diff --git a/src/BeSimple/SoapClient/Tests/ServerInterop/WsSecurityUserPassServerInteropTest.php b/src/BeSimple/SoapClient/Tests/ServerInterop/WsSecurityUserPassServerInteropTest.php index 4030507..1df839c 100644 --- a/src/BeSimple/SoapClient/Tests/ServerInterop/WsSecurityUserPassServerInteropTest.php +++ b/src/BeSimple/SoapClient/Tests/ServerInterop/WsSecurityUserPassServerInteropTest.php @@ -29,7 +29,6 @@ class WsSecurityUserPassServerInteropTest extends TestCase 'addBookResponse' => 'BeSimple\SoapClient\Tests\ServerInterop\Fixtures\addBookResponse', 'BookInformation' => 'BeSimple\SoapClient\Tests\ServerInterop\Fixtures\BookInformation', ), - 'cli_webserver_workaround' => true, // Work around missing header access in PHP cli webserver by setting headers additionally as GET parameters. ); public function testUserPassText() diff --git a/src/BeSimple/SoapCommon/SoapMessage.php b/src/BeSimple/SoapCommon/SoapMessage.php index 6601bc1..1b91c1a 100644 --- a/src/BeSimple/SoapCommon/SoapMessage.php +++ b/src/BeSimple/SoapCommon/SoapMessage.php @@ -28,6 +28,13 @@ abstract class SoapMessage */ const CONTENT_TYPE_HEADER = 'CONTENT_TYPE'; + /** + * $_SERVER key for 'Content-Type' header (with PHP cli-webserver) + * + * @var string + */ + const HTTP_CONTENT_TYPE_HEADER = 'HTTP_CONTENT_TYPE'; + /** * $_SERVER key for 'SOAPAction' header. * diff --git a/src/BeSimple/SoapServer/SoapRequest.php b/src/BeSimple/SoapServer/SoapRequest.php index 3d410f5..7fae123 100644 --- a/src/BeSimple/SoapServer/SoapRequest.php +++ b/src/BeSimple/SoapServer/SoapRequest.php @@ -32,29 +32,19 @@ class SoapRequest extends CommonSoapRequest */ public static function create($content, $version) { - $location = self::getCurrentUrl(); - /* - * Work around missing header/php://input access in PHP cli webserver by - * setting headers additionally as GET parameters and SOAP request body - * explicitly as POST variable - */ - if (php_sapi_name() == "cli-server") { - $content = is_null($content) ? $_POST['request'] : $content; - $action = $_GET[SoapMessage::SOAP_ACTION_HEADER]; - $contentType = $_GET[SoapMessage::CONTENT_TYPE_HEADER]; - } else { - $content = is_null($content) ? file_get_contents("php://input") : $content; - $action = isset($_SERVER[SoapMessage::SOAP_ACTION_HEADER]) ? $_SERVER[SoapMessage::SOAP_ACTION_HEADER] : null; - $contentType = $_SERVER[SoapMessage::CONTENT_TYPE_HEADER]; - } - $request = new SoapRequest(); + // $content is if unmodified from SoapClient not a php string type! - $request->setContent((string) $content); - $request->setLocation($location); - $request->setAction($action); + $request->setContent((string) (null === $content ? file_get_contents("php://input") : $content)); + $request->setLocation(self::getCurrentUrl()); + $request->setAction(isset($_SERVER[SoapMessage::SOAP_ACTION_HEADER]) ? $_SERVER[SoapMessage::SOAP_ACTION_HEADER] : null); $request->setVersion($version); - $request->setContentType($contentType); + + if (isset($_SERVER[SoapMessage::CONTENT_TYPE_HEADER])) { + $request->setContentType($_SERVER[SoapMessage::CONTENT_TYPE_HEADER]); + } elseif (isset($_SERVER[SoapMessage::HTTP_CONTENT_TYPE_HEADER])) { + $request->setContentType($_SERVER[SoapMessage::HTTP_CONTENT_TYPE_HEADER]); + } return $request; }