fix parser and add attachment support

This commit is contained in:
Andreas Schamberger
2012-01-03 16:38:50 +01:00
parent e151d06371
commit f6ea609f46
4 changed files with 80 additions and 5 deletions

View File

@ -13,6 +13,8 @@
namespace BeSimple\SoapCommon;
use BeSimple\SoapCommon\Mime\Part as MimePart;
use BeSimple\SoapCommon\SoapRequest;
use BeSimple\SoapCommon\SoapResponse;
@ -28,6 +30,13 @@ use BeSimple\SoapCommon\SoapResponseFilter;
*/
class SoapKernel
{
/**
* Mime attachments.
*
* @var array(\BeSimple\SoapCommon\Mime\Part)
*/
protected $attachments = array();
/**
* Request filters.
*
@ -42,6 +51,39 @@ class SoapKernel
*/
private $responseFilters = array();
/**
* Add attachment.
*
* @param \BeSimple\SoapCommon\Mime\Part $attachment New attachment
*
* @return void
*/
public function addAttachment(MimePart $attachment)
{
$contentId = trim($part->getHeader('Content-ID'), '<>');
$this->attachments[$contentId] = $attachment;
}
/**
* Get attachment and remove from array.
*
* @param string $contentId Content ID of attachment
*
* @return \BeSimple\SoapCommon\Mime\Part|null
*/
public function getAttachment($contentId)
{
if (isset($this->attachments[$contentId])) {
$part = $this->attachments[$contentId];
unset($this->attachments[$contentId]);
return $part;
}
return null;
}
/**
* Registers the given object either as filter for SoapRequests or as filter for SoapResponses
* or as filter for both depending on the implemented interfaces. Inner filters have to be registered
@ -70,6 +112,9 @@ class SoapKernel
*/
public function filterRequest(SoapRequest $request)
{
$request->setAttachments($this->attachments);
$this->attachments = array();
foreach ($this->requestFilters as $filter) {
$filter->filterRequest($request);
}
@ -85,5 +130,7 @@ class SoapKernel
foreach ($this->responseFilters as $filter) {
$filter->filterResponse($response);
}
$this->attachments = $response->getAttachments();
}
}