diff --git a/src/BeSimple/SoapClient/MimeFilter.php b/src/BeSimple/SoapClient/MimeFilter.php index 0dd9905..e06c04f 100644 --- a/src/BeSimple/SoapClient/MimeFilter.php +++ b/src/BeSimple/SoapClient/MimeFilter.php @@ -28,41 +28,8 @@ use BeSimple\SoapCommon\SoapResponseFilter; */ class MimeFilter implements SoapRequestFilter, SoapResponseFilter { - /** - * Attachment type. - * - * @var int Helper::ATTACHMENTS_TYPE_SWA | Helper::ATTACHMENTS_TYPE_MTOM - */ - protected $attachmentType = Helper::ATTACHMENTS_TYPE_SWA; - - /** - * Constructor. - * - * @param int $attachmentType Helper::ATTACHMENTS_TYPE_SWA | Helper::ATTACHMENTS_TYPE_MTOM - */ - public function __construct($attachmentType) + public function filterRequest(SoapRequest $request, $attachmentType) { - $this->attachmentType = $attachmentType; - } - - /** - * Reset all properties to default values. - */ - public function resetFilter() - { - $this->attachmentType = Helper::ATTACHMENTS_TYPE_SWA; - } - - /** - * Modify the given request XML. - * - * @param \BeSimple\SoapCommon\SoapRequest $request SOAP request - * - * @return void - */ - public function filterRequest(SoapRequest $request) - { - // get attachments from request object $attachmentsToSend = $request->getAttachments(); // build mime message if we have attachments @@ -71,7 +38,7 @@ class MimeFilter implements SoapRequestFilter, SoapResponseFilter $soapPart = new MimePart($request->getContent(), 'text/xml', 'utf-8', MimePart::ENCODING_EIGHT_BIT); $soapVersion = $request->getVersion(); // change content type headers for MTOM with SOAP 1.1 - if ($soapVersion == SOAP_1_1 && $this->attachmentType & Helper::ATTACHMENTS_TYPE_MTOM) { + if ($soapVersion == SOAP_1_1 && $attachmentType & Helper::ATTACHMENTS_TYPE_MTOM) { $multipart->setHeader('Content-Type', 'type', 'application/xop+xml'); $multipart->setHeader('Content-Type', 'start-info', 'text/xml'); $soapPart->setHeader('Content-Type', 'application/xop+xml'); @@ -94,19 +61,13 @@ class MimeFilter implements SoapRequestFilter, SoapResponseFilter $request->setContentType($contentType); } + + return $request; } - /** - * Modify the given response XML. - * - * @param \BeSimple\SoapCommon\SoapResponse $response SOAP response - * - * @return void - */ - public function filterResponse(SoapResponse $response) + public function filterResponse(SoapResponse $response, $attachmentType) { - // array to store attachments - $attachmentsRecieved = array(); + $attachmentsReceived = []; // check content type if it is a multipart mime message $responseContentType = $response->getContentType(); @@ -126,13 +87,13 @@ class MimeFilter implements SoapRequestFilter, SoapResponseFilter // store attachments $attachments = $multipart->getParts(false); foreach ($attachments as $cid => $attachment) { - $attachmentsRecieved[$cid] = $attachment; + $attachmentsReceived[$cid] = $attachment; } } - - // add attachments to response object - if (count($attachmentsRecieved) > 0) { - $response->setAttachments($attachmentsRecieved); + if (count($attachmentsReceived) > 0) { + $response->setAttachments($attachmentsReceived); } + + return $response; } } diff --git a/src/BeSimple/SoapClient/SoapKernel.php b/src/BeSimple/SoapClient/SoapKernel.php deleted file mode 100644 index e2e5093..0000000 --- a/src/BeSimple/SoapClient/SoapKernel.php +++ /dev/null @@ -1,47 +0,0 @@ - - * (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\SoapClient; - -use BeSimple\SoapCommon\SoapKernel as CommonSoapKernel; -use BeSimple\SoapCommon\SoapRequest as CommonSoapRequest; -use BeSimple\SoapCommon\SoapResponse as CommonSoapResponse; - -/** - * SoapKernel for Client. - * - * @author Andreas Schamberger - */ -class SoapKernel extends CommonSoapKernel -{ - /** - * {@inheritDoc} - */ - public function filterRequest(CommonSoapRequest $request) - { - $request->setAttachments($this->attachments); - $this->attachments = array(); - - parent::filterRequest($request); - } - - /** - * {@inheritDoc} - */ - public function filterResponse(CommonSoapResponse $response) - { - parent::filterResponse($response); - - $this->attachments = $response->getAttachments(); - } -} diff --git a/src/BeSimple/SoapClient/XmlMimeFilter.php b/src/BeSimple/SoapClient/XmlMimeFilter.php index ae8ed45..b34a23a 100644 --- a/src/BeSimple/SoapClient/XmlMimeFilter.php +++ b/src/BeSimple/SoapClient/XmlMimeFilter.php @@ -1,15 +1,5 @@ - * (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\SoapClient; use BeSimple\SoapCommon\FilterHelper; @@ -24,21 +14,7 @@ use BeSimple\SoapCommon\SoapRequestFilter; */ class XmlMimeFilter implements SoapRequestFilter { - /** - * Reset all properties to default values. - */ - public function resetFilter() - { - } - - /** - * Modify the given request XML. - * - * @param \BeSimple\SoapCommon\SoapRequest $request SOAP request - * - * @return void - */ - public function filterRequest(SoapRequest $request) + public function filterRequest(SoapRequest $request, $attachmentType) { // get \DOMDocument from SOAP request $dom = $request->getContentDocument(); @@ -66,5 +42,6 @@ class XmlMimeFilter implements SoapRequestFilter } } + return $request; } } diff --git a/src/BeSimple/SoapCommon/SoapKernel.php b/src/BeSimple/SoapCommon/SoapKernel.php index 0202feb..d968a4b 100644 --- a/src/BeSimple/SoapCommon/SoapKernel.php +++ b/src/BeSimple/SoapCommon/SoapKernel.php @@ -53,13 +53,14 @@ class SoapKernel * * @param SoapRequest $request Soap request * @param SoapRequestFilter[]|SoapResponseFilter[] $filters + * @param int $attachmentType = SoapOptions::SOAP_ATTACHMENTS_TYPE_SWA|SoapOptions::ATTACHMENTS_TYPE_MTOM|SoapOptions::ATTACHMENTS_TYPE_BASE64 * @return SoapRequest */ - public function filterRequest(SoapRequest $request, array $filters) + public function filterRequest(SoapRequest $request, array $filters, $attachmentType) { foreach ($filters as $filter) { if ($filter instanceof SoapRequestFilter) { - $request = $filter->filterRequest($request); + $request = $filter->filterRequest($request, $attachmentType); } } @@ -71,13 +72,14 @@ class SoapKernel * * @param SoapResponse $response SOAP response * @param SoapRequestFilter[]|SoapResponseFilter[] $filters + * @param int $attachmentType = SoapOptions::SOAP_ATTACHMENTS_TYPE_SWA|SoapOptions::ATTACHMENTS_TYPE_MTOM|SoapOptions::ATTACHMENTS_TYPE_BASE64 * @return SoapResponse */ - public function filterResponse(SoapResponse $response, array $filters) + public function filterResponse(SoapResponse $response, array $filters, $attachmentType) { foreach ($filters as $filter) { if ($filter instanceof SoapResponseFilter) { - $response = $filter->filterResponse($response); + $response = $filter->filterResponse($response, $attachmentType); } } diff --git a/src/BeSimple/SoapCommon/SoapOptions/SoapOptions.php b/src/BeSimple/SoapCommon/SoapOptions/SoapOptions.php index 4ea3f8a..8d7cb13 100644 --- a/src/BeSimple/SoapCommon/SoapOptions/SoapOptions.php +++ b/src/BeSimple/SoapCommon/SoapOptions/SoapOptions.php @@ -38,11 +38,11 @@ class SoapOptions * @param string $encoding = SoapOptions::SOAP_ENCODING_UTF8 * @param SoapFeatures $features * @param string $wsdlFile - * @param string $wsdlCacheType = SoapOptions::SOAP_CACHE_TYPE_NONE|SoapOptions::SOAP_CACHE_TYPE_MEMORY|SoapOptions::SOAP_CACHE_TYPE_DISK|SoapOptions::SOAP_CACHE_TYPE_DISK_MEMORY - * @param string $wsdlCacheDir = null + * @param int $wsdlCacheType = SoapOptions::SOAP_CACHE_TYPE_NONE|SoapOptions::SOAP_CACHE_TYPE_MEMORY|SoapOptions::SOAP_CACHE_TYPE_DISK|SoapOptions::SOAP_CACHE_TYPE_DISK_MEMORY + * @param string|null $wsdlCacheDir = null * @param ClassMap $classMap * @param TypeConverterCollection $typeConverterCollection - * @param string $attachmentType = SoapOptions::SOAP_ATTACHMENTS_OFF|SoapOptions::SOAP_ATTACHMENTS_TYPE_SWA|SoapOptions::ATTACHMENTS_TYPE_MTOM|SoapOptions::ATTACHMENTS_TYPE_BASE64 + * @param int|null $attachmentType = SoapOptions::SOAP_ATTACHMENTS_OFF|SoapOptions::SOAP_ATTACHMENTS_TYPE_SWA|SoapOptions::ATTACHMENTS_TYPE_MTOM|SoapOptions::ATTACHMENTS_TYPE_BASE64 */ public function __construct( $soapVersion, diff --git a/src/BeSimple/SoapCommon/SoapRequestFilter.php b/src/BeSimple/SoapCommon/SoapRequestFilter.php index dbc990c..26a2764 100644 --- a/src/BeSimple/SoapCommon/SoapRequestFilter.php +++ b/src/BeSimple/SoapCommon/SoapRequestFilter.php @@ -13,8 +13,6 @@ namespace BeSimple\SoapCommon; -use BeSimple\SoapCommon\SoapRequest; - /** * SOAP request filter interface. * @@ -26,6 +24,7 @@ interface SoapRequestFilter * Modify SOAP response. * * @param SoapRequest $request SOAP request + * @param int $attachmentType = SoapOptions::SOAP_ATTACHMENTS_TYPE_SWA|SoapOptions::ATTACHMENTS_TYPE_MTOM|SoapOptions::ATTACHMENTS_TYPE_BASE64 */ - public function filterRequest(SoapRequest $request); + public function filterRequest(SoapRequest $request, $attachmentType); } \ No newline at end of file diff --git a/src/BeSimple/SoapCommon/SoapResponseFilter.php b/src/BeSimple/SoapCommon/SoapResponseFilter.php index c7d6bb6..a124053 100644 --- a/src/BeSimple/SoapCommon/SoapResponseFilter.php +++ b/src/BeSimple/SoapCommon/SoapResponseFilter.php @@ -26,6 +26,7 @@ interface SoapResponseFilter * Modify SOAP response. * * @param SoapResponse $response SOAP response + * @param int $attachmentType = SoapOptions::SOAP_ATTACHMENTS_TYPE_SWA|SoapOptions::ATTACHMENTS_TYPE_MTOM|SoapOptions::ATTACHMENTS_TYPE_BASE64 */ - public function filterResponse(SoapResponse $response); + public function filterResponse(SoapResponse $response, $attachmentType); } \ No newline at end of file diff --git a/src/BeSimple/SoapServer/MimeFilter.php b/src/BeSimple/SoapServer/MimeFilter.php index f1194b3..c56e143 100644 --- a/src/BeSimple/SoapServer/MimeFilter.php +++ b/src/BeSimple/SoapServer/MimeFilter.php @@ -28,32 +28,7 @@ use BeSimple\SoapCommon\SoapResponseFilter; */ class MimeFilter implements SoapRequestFilter, SoapResponseFilter { - /** - * Attachment type. - * - * @var int Helper::ATTACHMENTS_TYPE_SWA | Helper::ATTACHMENTS_TYPE_MTOM - */ - protected $attachmentType = Helper::ATTACHMENTS_TYPE_SWA; - - /** - * Constructor. - * - * @param int $attachmentType Helper::ATTACHMENTS_TYPE_SWA | Helper::ATTACHMENTS_TYPE_MTOM - */ - public function __construct($attachmentType) - { - $this->attachmentType = $attachmentType; - } - - /** - * Reset all properties to default values. - */ - public function resetFilter() - { - $this->attachmentType = Helper::ATTACHMENTS_TYPE_SWA; - } - - public function filterRequest(SoapRequest $request) + public function filterRequest(SoapRequest $request, $attachmentType) { $attachmentsReceived = []; @@ -86,7 +61,7 @@ class MimeFilter implements SoapRequestFilter, SoapResponseFilter return $request; } - public function filterResponse(SoapResponse $response) + public function filterResponse(SoapResponse $response, $attachmentType) { $attachmentsToSend = $response->getAttachments(); if (count($attachmentsToSend) > 0) { @@ -94,7 +69,7 @@ class MimeFilter implements SoapRequestFilter, SoapResponseFilter $soapPart = new MimePart($response->getContent(), 'text/xml', 'utf-8', MimePart::ENCODING_EIGHT_BIT); $soapVersion = $response->getVersion(); // change content type headers for MTOM with SOAP 1.1 - if ($soapVersion == SOAP_1_1 && $this->attachmentType & Helper::ATTACHMENTS_TYPE_MTOM) { + if ($soapVersion == SOAP_1_1 && $attachmentType & Helper::ATTACHMENTS_TYPE_MTOM) { $multipart->setHeader('Content-Type', 'type', 'application/xop+xml'); $multipart->setHeader('Content-Type', 'start-info', 'text/xml'); $soapPart->setHeader('Content-Type', 'application/xop+xml'); diff --git a/src/BeSimple/SoapServer/SoapKernel.php b/src/BeSimple/SoapServer/SoapKernel.php deleted file mode 100644 index 7b3d05c..0000000 --- a/src/BeSimple/SoapServer/SoapKernel.php +++ /dev/null @@ -1,36 +0,0 @@ - - */ -class SoapServerKernel extends SoapKernel -{ - /** - * {@inheritDoc} - */ - public function filterRequest(SoapRequest $request, array $filters) - { - parent::filterRequest($request, $filters); - - // attachments are now gone from here - } - - /** - * {@inheritDoc} - */ - public function filterResponse(SoapResponse $response) - { - $response->setAttachments($this->attachments); - $this->attachments = array(); - - parent::filterResponse($response); - } -} diff --git a/src/BeSimple/SoapServer/SoapServer.php b/src/BeSimple/SoapServer/SoapServer.php index 66bb2d2..ab04ab1 100644 --- a/src/BeSimple/SoapServer/SoapServer.php +++ b/src/BeSimple/SoapServer/SoapServer.php @@ -100,7 +100,7 @@ class SoapServer extends \SoapServer private function handleSoapRequest(SoapRequest $soapRequest) { if ($this->soapOptions->hasAttachments()) { - $soapRequest = $this->soapKernel->filterRequest($soapRequest, $this->getFilters()); + $soapRequest = $this->soapKernel->filterRequest($soapRequest, $this->getFilters(), $this->soapOptions->getAttachmentType()); } ob_start(); @@ -120,7 +120,7 @@ class SoapServer extends \SoapServer ); if ($this->soapOptions->hasAttachments()) { - $this->soapKernel->filterResponse($soapResponse, $this->getFilters()); + $soapResponse = $this->soapKernel->filterResponse($soapResponse, $this->getFilters(), $this->soapOptions->getAttachmentType()); } return $soapResponse;