Large refactoring of SoapKernel
This commit is contained in:
@ -1,34 +1,16 @@
|
||||
<?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\SoapCommon\Converter;
|
||||
|
||||
use BeSimple\SoapCommon\Mime\Part as MimePart;
|
||||
use BeSimple\SoapCommon\SoapKernel;
|
||||
use BeSimple\SoapCommon\Converter\SoapKernelAwareInterface;
|
||||
use BeSimple\SoapCommon\Converter\TypeConverterInterface;
|
||||
|
||||
/**
|
||||
* SwA type converter.
|
||||
*
|
||||
* @author Andreas Schamberger <mail@andreass.net>
|
||||
*/
|
||||
class SwaTypeConverter implements TypeConverterInterface, SoapKernelAwareInterface
|
||||
class SwaTypeConverter implements TypeConverterInterface
|
||||
{
|
||||
/**
|
||||
* @var \BeSimple\SoapCommon\SoapKernel $soapKernel SoapKernel instance
|
||||
*/
|
||||
protected $soapKernel = null;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@ -60,6 +42,7 @@ class SwaTypeConverter implements TypeConverterInterface, SoapKernelAwareInterfa
|
||||
if ('cid:' === substr($ref, 0, 4)) {
|
||||
$contentId = urldecode(substr($ref, 4));
|
||||
|
||||
// @todo-critical: ci je nyni zodpovednost vygetovat attachmenty
|
||||
if (null !== ($part = $this->soapKernel->getAttachment($contentId))) {
|
||||
|
||||
return $part->getContent();
|
||||
@ -80,16 +63,9 @@ class SwaTypeConverter implements TypeConverterInterface, SoapKernelAwareInterfa
|
||||
$part = new MimePart($data);
|
||||
$contentId = trim($part->getHeader('Content-ID'), '<>');
|
||||
|
||||
$this->soapKernel->addAttachment($part);
|
||||
// @todo-critical: ci je nyni zodpovednost nastrkat attachmenty
|
||||
//$this->soapKernel->addAttachment($part);
|
||||
|
||||
return sprintf('<%s href="%s"/>', $this->getTypeName(), 'cid:' . $contentId);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function setKernel(SoapKernel $soapKernel)
|
||||
{
|
||||
$this->soapKernel = $soapKernel;
|
||||
}
|
||||
}
|
||||
|
@ -1,23 +1,8 @@
|
||||
<?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\SoapCommon;
|
||||
|
||||
use BeSimple\SoapCommon\Mime\Part as MimePart;
|
||||
use BeSimple\SoapCommon\SoapRequest;
|
||||
use BeSimple\SoapCommon\SoapResponse;
|
||||
use BeSimple\SoapCommon\SoapRequestFilter;
|
||||
use BeSimple\SoapCommon\SoapResponseFilter;
|
||||
|
||||
/**
|
||||
* SoapKernel provides methods to pre- and post-process SoapRequests and SoapResponses using
|
||||
@ -25,30 +10,10 @@ use BeSimple\SoapCommon\SoapResponseFilter;
|
||||
* the chain-of-responsibility pattern).
|
||||
*
|
||||
* @author Christian Kerl <christian-kerl@web.de>
|
||||
* @author Petr Bechyně <petr.bechyne@vodafone.com>
|
||||
*/
|
||||
class SoapKernel
|
||||
{
|
||||
/**
|
||||
* Mime attachments.
|
||||
*
|
||||
* @var array(\BeSimple\SoapCommon\Mime\Part)
|
||||
*/
|
||||
protected $attachments = array();
|
||||
|
||||
/**
|
||||
* Request filters.
|
||||
*
|
||||
* @var array(SoapRequestFilter)
|
||||
*/
|
||||
private $requestFilters = array();
|
||||
|
||||
/**
|
||||
* Response filters.
|
||||
*
|
||||
* @var array(SoapResponseFilter)
|
||||
*/
|
||||
private $responseFilters = array();
|
||||
|
||||
/**
|
||||
* Add attachment.
|
||||
*
|
||||
@ -82,48 +47,40 @@ class SoapKernel
|
||||
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
|
||||
* before outer filters. This means the order is as follows: RequestFilter2->RequestFilter1 and
|
||||
* ResponseFilter1->ResponseFilter2.
|
||||
*
|
||||
* TODO: add priority mechanism to ensure correct order of filters
|
||||
*
|
||||
* @param SoapRequestFilter|SoapResponseFilter $filter Filter to register
|
||||
*/
|
||||
public function registerFilter($filter)
|
||||
{
|
||||
if ($filter instanceof SoapRequestFilter) {
|
||||
array_unshift($this->requestFilters, $filter);
|
||||
}
|
||||
|
||||
if ($filter instanceof SoapResponseFilter) {
|
||||
array_push($this->responseFilters, $filter);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies all registered SoapRequestFilter to the given SoapRequest.
|
||||
*
|
||||
* @param SoapRequest $request Soap request
|
||||
* @param SoapRequestFilter[]|SoapResponseFilter[] $filters
|
||||
* @return SoapRequest
|
||||
*/
|
||||
public function filterRequest(SoapRequest $request)
|
||||
public function filterRequest(SoapRequest $request, array $filters)
|
||||
{
|
||||
foreach ($this->requestFilters as $filter) {
|
||||
$filter->filterRequest($request);
|
||||
foreach ($filters as $filter) {
|
||||
if ($filter instanceof SoapRequestFilter) {
|
||||
$request = $filter->filterRequest($request);
|
||||
}
|
||||
}
|
||||
|
||||
return $request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies all registered SoapResponseFilter to the given SoapResponse.
|
||||
*
|
||||
* @param SoapResponse $response SOAP response
|
||||
* @param SoapRequestFilter[]|SoapResponseFilter[] $filters
|
||||
* @return SoapResponse
|
||||
*/
|
||||
public function filterResponse(SoapResponse $response)
|
||||
public function filterResponse(SoapResponse $response, array $filters)
|
||||
{
|
||||
foreach ($this->responseFilters as $filter) {
|
||||
$filter->filterResponse($response);
|
||||
foreach ($filters as $filter) {
|
||||
if ($filter instanceof SoapResponseFilter) {
|
||||
$response = $filter->filterResponse($response);
|
||||
}
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user