2011-11-21 20:21:24 +01:00
|
|
|
<?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\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
|
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>
|
|
|
|
*/
|
|
|
|
class SoapKernel
|
|
|
|
{
|
2011-12-17 16:25:49 +01:00
|
|
|
/**
|
|
|
|
* Request filters.
|
|
|
|
*
|
|
|
|
* @var array(SoapRequestFilter)
|
|
|
|
*/
|
2011-11-21 20:21:24 +01:00
|
|
|
private $requestFilters = array();
|
2011-12-17 16:25:49 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Response filters.
|
|
|
|
*
|
|
|
|
* @var array(SoapResponseFilter)
|
|
|
|
*/
|
2011-11-21 20:21:24 +01:00
|
|
|
private $responseFilters = array();
|
2011-12-17 16:25:49 +01:00
|
|
|
|
2011-11-21 20:21:24 +01:00
|
|
|
/**
|
2011-12-17 16:25:49 +01:00
|
|
|
* Registers the given object either as filter for SoapRequests or as filter for SoapResponses
|
2011-11-21 20:21:24 +01:00
|
|
|
* or as filter for both depending on the implemented interfaces. Inner filters have to be registered
|
2011-12-17 16:25:49 +01:00
|
|
|
* before outer filters. This means the order is as follows: RequestFilter2->RequestFilter1 and
|
2011-11-21 20:21:24 +01:00
|
|
|
* ResponseFilter1->ResponseFilter2.
|
2011-12-17 16:25:49 +01:00
|
|
|
*
|
2011-11-21 20:21:24 +01:00
|
|
|
* TODO: add priority mechanism to ensure correct order of filters
|
2011-12-17 16:25:49 +01:00
|
|
|
*
|
|
|
|
* @param SoapRequestFilter|SoapResponseFilter $filter Filter to register
|
2011-11-21 20:21:24 +01:00
|
|
|
*/
|
|
|
|
public function registerFilter($filter)
|
2011-12-17 16:25:49 +01:00
|
|
|
{
|
|
|
|
if ($filter instanceof SoapRequestFilter) {
|
2011-11-21 20:21:24 +01:00
|
|
|
array_unshift($this->requestFilters, $filter);
|
|
|
|
}
|
2011-12-17 16:25:49 +01:00
|
|
|
|
|
|
|
if ($filter instanceof SoapResponseFilter) {
|
2011-11-21 20:21:24 +01:00
|
|
|
array_push($this->responseFilters, $filter);
|
|
|
|
}
|
|
|
|
}
|
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
|
2011-11-21 20:21:24 +01:00
|
|
|
*/
|
|
|
|
public function filterRequest(SoapRequest $request)
|
|
|
|
{
|
2011-12-17 16:25:49 +01:00
|
|
|
foreach ($this->requestFilters as $filter) {
|
2011-11-21 20:21:24 +01:00
|
|
|
$filter->filterRequest($request);
|
|
|
|
}
|
|
|
|
}
|
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
|
2011-11-21 20:21:24 +01:00
|
|
|
*/
|
|
|
|
public function filterResponse(SoapResponse $response)
|
|
|
|
{
|
2011-12-17 16:25:49 +01:00
|
|
|
foreach ($this->responseFilters as $filter) {
|
2011-11-21 20:28:31 +01:00
|
|
|
$filter->filterResponse($response);
|
2011-11-21 20:21:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|