MimeFilters are now stateless
This commit is contained in:
parent
969709cae5
commit
bf494a42b5
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,47 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the BeSimpleSoapCommon.
|
||||
*
|
||||
* (c) Christian Kerl <christian-kerl@web.de>
|
||||
* (c) Francis Besset <francis.besset@gmail.com>
|
||||
* (c) Andreas Schamberger <mail@andreass.net>
|
||||
*
|
||||
* 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 <mail@andreass.net>
|
||||
*/
|
||||
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();
|
||||
}
|
||||
}
|
|
@ -1,15 +1,5 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the BeSimpleSoapClient.
|
||||
*
|
||||
* (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\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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -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);
|
||||
}
|
|
@ -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');
|
||||
|
|
|
@ -1,36 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace BeSimple\SoapServer;
|
||||
|
||||
use BeSimple\SoapCommon\SoapKernel;
|
||||
use BeSimple\SoapCommon\SoapRequest;
|
||||
|
||||
/**
|
||||
* SoapKernel for Server.
|
||||
*
|
||||
* @todo-critical: kill this shit
|
||||
* @author Andreas Schamberger <mail@andreass.net>
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue