From 8d62141a3d81f25be630fbe6cf941d8cc5a93a43 Mon Sep 17 00:00:00 2001 From: Andreas Schamberger Date: Fri, 23 Aug 2013 20:55:26 +0200 Subject: [PATCH] add workaround for cli webserver option --- src/BeSimple/SoapClient/SoapClient.php | 41 ++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/src/BeSimple/SoapClient/SoapClient.php b/src/BeSimple/SoapClient/SoapClient.php index d0d99e8..b8a75c7 100644 --- a/src/BeSimple/SoapClient/SoapClient.php +++ b/src/BeSimple/SoapClient/SoapClient.php @@ -15,6 +15,7 @@ namespace BeSimple\SoapClient; use BeSimple\SoapCommon\Helper; use BeSimple\SoapCommon\Converter\MtomTypeConverter; use BeSimple\SoapCommon\Converter\SwaTypeConverter; +use BeSimple\SoapCommon\SoapMessage; /** * Extended SoapClient that uses a a cURL wrapper for all underlying HTTP @@ -40,6 +41,15 @@ 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. * @@ -98,6 +108,10 @@ 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); $wsdlFile = $this->loadWsdl($wsdl, $options); // TODO $wsdlHandler = new WsdlHandler($wsdlFile, $this->soapVersion); @@ -128,10 +142,33 @@ class SoapClient extends \SoapClient 'Content-Type:' . $soapRequest->getContentType(), 'SOAPAction: "' . $soapRequest->getAction() . '"', ); + + $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(); + } + // execute HTTP request with cURL $responseSuccessfull = $this->curl->exec( - $soapRequest->getLocation(), - $soapRequest->getContent(), + $location, + $content, $headers ); // tracing enabled: store last request header and body