2011-11-21 20:21:24 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace BeSimple\SoapCommon;
|
|
|
|
|
2012-01-03 16:38:50 +01:00
|
|
|
use BeSimple\SoapCommon\Mime\Part as MimePart;
|
2011-11-21 20:21:24 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* SoapKernel provides methods to pre- and post-process SoapRequests and SoapResponses using
|
2011-12-17 16:25:49 +01:00
|
|
|
* chains of SoapRequestFilter and SoapResponseFilter objects (roughly following
|
2011-11-21 20:21:24 +01:00
|
|
|
* the chain-of-responsibility pattern).
|
2011-12-17 16:25:49 +01:00
|
|
|
*
|
2011-11-21 20:21:24 +01:00
|
|
|
* @author Christian Kerl <christian-kerl@web.de>
|
2016-11-01 18:13:23 +01:00
|
|
|
* @author Petr Bechyně <petr.bechyne@vodafone.com>
|
2011-11-21 20:21:24 +01:00
|
|
|
*/
|
|
|
|
class SoapKernel
|
|
|
|
{
|
2012-01-03 16:38:50 +01:00
|
|
|
/**
|
|
|
|
* Add attachment.
|
|
|
|
*
|
|
|
|
* @param \BeSimple\SoapCommon\Mime\Part $attachment New attachment
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function addAttachment(MimePart $attachment)
|
|
|
|
{
|
2012-01-03 18:48:40 +01:00
|
|
|
$contentId = trim($attachment->getHeader('Content-ID'), '<>');
|
2012-01-03 16:38:50 +01:00
|
|
|
|
|
|
|
$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;
|
|
|
|
}
|
|
|
|
|
2011-12-17 16:25:49 +01:00
|
|
|
|
2011-11-21 20:21:24 +01:00
|
|
|
/**
|
2011-12-17 16:25:49 +01:00
|
|
|
* Applies all registered SoapRequestFilter to the given SoapRequest.
|
|
|
|
*
|
|
|
|
* @param SoapRequest $request Soap request
|
2016-11-01 18:13:23 +01:00
|
|
|
* @param SoapRequestFilter[]|SoapResponseFilter[] $filters
|
|
|
|
* @return SoapRequest
|
2011-11-21 20:21:24 +01:00
|
|
|
*/
|
2016-11-01 18:13:23 +01:00
|
|
|
public function filterRequest(SoapRequest $request, array $filters)
|
2011-11-21 20:21:24 +01:00
|
|
|
{
|
2016-11-01 18:13:23 +01:00
|
|
|
foreach ($filters as $filter) {
|
|
|
|
if ($filter instanceof SoapRequestFilter) {
|
|
|
|
$request = $filter->filterRequest($request);
|
|
|
|
}
|
2011-11-21 20:21:24 +01:00
|
|
|
}
|
2016-11-01 18:13:23 +01:00
|
|
|
|
|
|
|
return $request;
|
2011-11-21 20:21:24 +01:00
|
|
|
}
|
2011-12-17 16:25:49 +01:00
|
|
|
|
2011-11-21 20:21:24 +01:00
|
|
|
/**
|
2011-12-17 16:25:49 +01:00
|
|
|
* Applies all registered SoapResponseFilter to the given SoapResponse.
|
|
|
|
*
|
|
|
|
* @param SoapResponse $response SOAP response
|
2016-11-01 18:13:23 +01:00
|
|
|
* @param SoapRequestFilter[]|SoapResponseFilter[] $filters
|
|
|
|
* @return SoapResponse
|
2011-11-21 20:21:24 +01:00
|
|
|
*/
|
2016-11-01 18:13:23 +01:00
|
|
|
public function filterResponse(SoapResponse $response, array $filters)
|
2011-11-21 20:21:24 +01:00
|
|
|
{
|
2016-11-01 18:13:23 +01:00
|
|
|
foreach ($filters as $filter) {
|
|
|
|
if ($filter instanceof SoapResponseFilter) {
|
|
|
|
$response = $filter->filterResponse($response);
|
|
|
|
}
|
2011-11-21 20:21:24 +01:00
|
|
|
}
|
2016-11-01 18:13:23 +01:00
|
|
|
|
|
|
|
return $response;
|
2011-11-21 20:21:24 +01:00
|
|
|
}
|
2013-12-02 15:14:06 +01:00
|
|
|
}
|