BeSimpleSoap/src/BeSimple/SoapCommon/SoapKernel.php

89 lines
2.5 KiB
PHP
Raw Normal View History

<?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
* the chain-of-responsibility pattern).
2011-12-17 16:25:49 +01:00
*
* @author Christian Kerl <christian-kerl@web.de>
*/
class SoapKernel
{
2011-12-17 16:25:49 +01:00
/**
* Request filters.
*
* @var array(SoapRequestFilter)
*/
private $requestFilters = array();
2011-12-17 16:25:49 +01:00
/**
* Response filters.
*
* @var array(SoapResponseFilter)
*/
private $responseFilters = array();
2011-12-17 16:25:49 +01:00
/**
2011-12-17 16:25:49 +01:00
* 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
2011-12-17 16:25:49 +01:00
* before outer filters. This means the order is as follows: RequestFilter2->RequestFilter1 and
* ResponseFilter1->ResponseFilter2.
2011-12-17 16:25:49 +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
*/
public function registerFilter($filter)
2011-12-17 16:25:49 +01:00
{
if ($filter instanceof SoapRequestFilter) {
array_unshift($this->requestFilters, $filter);
}
2011-12-17 16:25:49 +01:00
if ($filter instanceof SoapResponseFilter) {
array_push($this->responseFilters, $filter);
}
}
2011-12-17 16:25:49 +01:00
/**
2011-12-17 16:25:49 +01:00
* Applies all registered SoapRequestFilter to the given SoapRequest.
*
* @param SoapRequest $request Soap request
*/
public function filterRequest(SoapRequest $request)
{
2011-12-17 16:25:49 +01:00
foreach ($this->requestFilters as $filter) {
$filter->filterRequest($request);
}
}
2011-12-17 16:25:49 +01:00
/**
2011-12-17 16:25:49 +01:00
* Applies all registered SoapResponseFilter to the given SoapResponse.
*
* @param SoapResponse $response SOAP response
*/
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);
}
}
}