From 155aa029ced96f9f84a0181a085836708e66cd66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Bechyn=C4=9B?= Date: Tue, 1 Nov 2016 16:23:21 +0100 Subject: [PATCH] SoapRequest is now SoapRequestFactory product --- src/BeSimple/SoapClient/SoapClient.php | 3 +- src/BeSimple/SoapCommon/SoapRequest.php | 40 ----------- .../SoapCommon/SoapRequestFactory.php | 30 ++++++++ .../SoapServer/SoapRequestFactory.php | 72 ------------------- src/BeSimple/SoapServer/SoapServer.php | 15 +++- 5 files changed, 44 insertions(+), 116 deletions(-) create mode 100644 src/BeSimple/SoapCommon/SoapRequestFactory.php delete mode 100644 src/BeSimple/SoapServer/SoapRequestFactory.php diff --git a/src/BeSimple/SoapClient/SoapClient.php b/src/BeSimple/SoapClient/SoapClient.php index 1e5ed87..2e5e141 100644 --- a/src/BeSimple/SoapClient/SoapClient.php +++ b/src/BeSimple/SoapClient/SoapClient.php @@ -17,6 +17,7 @@ use BeSimple\SoapCommon\Converter\MtomTypeConverter; use BeSimple\SoapCommon\Converter\SwaTypeConverter; use BeSimple\SoapCommon\SoapOptions\SoapOptions; use BeSimple\SoapCommon\SoapRequest; +use BeSimple\SoapCommon\SoapRequestFactory; /** * Extended SoapClient that uses a a cURL wrapper for all underlying HTTP @@ -186,7 +187,7 @@ class SoapClient extends \SoapClient public function __doRequest($request, $location, $action, $version, $oneWay = 0) { // wrap request data in SoapRequest object - $soapRequest = SoapRequest::create($request, $location, $action, $version); + $soapRequest = SoapRequestFactory::create($location, $action, $version, $request); // do actual SOAP request $soapResponse = $this->__doRequest2($soapRequest); diff --git a/src/BeSimple/SoapCommon/SoapRequest.php b/src/BeSimple/SoapCommon/SoapRequest.php index a35a358..b7951f0 100644 --- a/src/BeSimple/SoapCommon/SoapRequest.php +++ b/src/BeSimple/SoapCommon/SoapRequest.php @@ -1,47 +1,7 @@ - * (c) Francis Besset - * (c) Andreas Schamberger - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - namespace BeSimple\SoapCommon; - -/** - * SOAP request message. - * - * @author Christian Kerl - */ class SoapRequest extends SoapMessage { - /** - * Factory function for SoapRequest. - * - * @param string $content Content - * @param string $location Location - * @param string $action SOAP action - * @param string $version SOAP version - * - * @return SoapRequest - */ - public static function create($content, $location, $action, $version) - { - $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->setVersion($version); - $contentType = SoapMessage::getContentTypeForVersion($version); - $request->setContentType($contentType); - - return $request; - } } diff --git a/src/BeSimple/SoapCommon/SoapRequestFactory.php b/src/BeSimple/SoapCommon/SoapRequestFactory.php new file mode 100644 index 0000000..a327965 --- /dev/null +++ b/src/BeSimple/SoapCommon/SoapRequestFactory.php @@ -0,0 +1,30 @@ +setContent((string) $content); + $request->setLocation($location); + $request->setAction($action); + $request->setVersion($version); + $contentType = SoapMessage::getContentTypeForVersion($version); + $request->setContentType($contentType); + + return $request; + } +} diff --git a/src/BeSimple/SoapServer/SoapRequestFactory.php b/src/BeSimple/SoapServer/SoapRequestFactory.php deleted file mode 100644 index 7f5383a..0000000 --- a/src/BeSimple/SoapServer/SoapRequestFactory.php +++ /dev/null @@ -1,72 +0,0 @@ - - * (c) Francis Besset - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace BeSimple\SoapServer; - -use BeSimple\SoapCommon\SoapMessage; -use BeSimple\SoapCommon\SoapRequest; - -/** - * SoapRequest class for SoapClient. Provides factory function for request object. - * - * @author Andreas Schamberger - */ -class SoapRequestFactory extends SoapRequest -{ - /** - * Factory function for SoapRequest. - * - * @param string $content Content - * @param string $version SOAP version - * - * @return SoapRequest - */ - public static function create($content, $version) - { - $request = new SoapRequest(); - - // $content is if unmodified from SoapClient not a php string type! - $request->setContent($content); - $request->setLocation(self::getCurrentUrl()); - $request->setAction(isset($_SERVER[SoapMessage::SOAP_ACTION_HEADER]) ? $_SERVER[SoapMessage::SOAP_ACTION_HEADER] : null); - $request->setVersion($version); - - 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; - } - - /** - * Builds the current URL from the $_SERVER array. - * - * @return string - */ - public static function getCurrentUrl() - { - $url = ''; - if (isset($_SERVER['HTTPS']) && (strtolower($_SERVER['HTTPS']) === 'on' || $_SERVER['HTTPS'] === '1')) { - $url .= 'https://'; - } else { - $url .= 'http://'; - } - $url .= isset( $_SERVER['SERVER_NAME'] ) ? $_SERVER['SERVER_NAME'] : ''; - if (isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] != 80) { - $url .= ":{$_SERVER['SERVER_PORT']}"; - } - $url .= isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : ''; - return $url; - } -} diff --git a/src/BeSimple/SoapServer/SoapServer.php b/src/BeSimple/SoapServer/SoapServer.php index c08ba62..2755229 100644 --- a/src/BeSimple/SoapServer/SoapServer.php +++ b/src/BeSimple/SoapServer/SoapServer.php @@ -12,8 +12,10 @@ namespace BeSimple\SoapServer; +use BeSimple\SoapCommon\SoapMessage; use BeSimple\SoapCommon\SoapOptions\SoapOptions; use BeSimple\SoapCommon\SoapRequest; +use BeSimple\SoapCommon\SoapRequestFactory; use BeSimple\SoapServer\SoapOptions\SoapServerOptions; use BeSimple\SoapCommon\Converter\MtomTypeConverter; use BeSimple\SoapCommon\Converter\SwaTypeConverter; @@ -57,12 +59,19 @@ class SoapServer extends \SoapServer /** * Custom handle method to be able to modify the SOAP messages. * - * @param string $request Request string + * @param string $requestUrl + * @param string $soapAction + * @param string $requestContent = null * @return string */ - public function handle($request = null) + public function handle($requestUrl, $soapAction, $requestContent = null) { - $soapRequest = SoapRequestFactory::create($request, $this->soapVersion); + $soapRequest = SoapRequestFactory::create( + $requestUrl, + $soapAction, + $this->soapVersion, + $requestContent + ); try { $soapResponse = $this->handleSoapRequest($soapRequest);