2012-05-09 14:26:29 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
2014-03-04 05:43:17 +01:00
|
|
|
* Represents a request processer that delegates pre and post request handling to nested request filters
|
2014-07-14 23:31:03 +02:00
|
|
|
*
|
2013-05-20 12:18:07 +02:00
|
|
|
* @package framework
|
|
|
|
* @subpackage control
|
2012-05-09 14:26:29 +02:00
|
|
|
*/
|
2014-03-04 05:43:17 +01:00
|
|
|
class RequestProcessor implements RequestFilter {
|
2012-05-09 14:26:29 +02:00
|
|
|
|
2014-03-04 05:43:17 +01:00
|
|
|
/**
|
|
|
|
* List of currently assigned request filters
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2012-05-09 14:26:29 +02:00
|
|
|
private $filters = array();
|
|
|
|
|
|
|
|
public function __construct($filters = array()) {
|
|
|
|
$this->filters = $filters;
|
|
|
|
}
|
|
|
|
|
2014-03-04 05:43:17 +01:00
|
|
|
/**
|
|
|
|
* Assign a list of request filters
|
2014-07-14 23:31:03 +02:00
|
|
|
*
|
2014-03-04 05:43:17 +01:00
|
|
|
* @param array $filters
|
|
|
|
*/
|
2012-07-19 03:57:48 +02:00
|
|
|
public function setFilters($filters) {
|
|
|
|
$this->filters = $filters;
|
|
|
|
}
|
|
|
|
|
2012-05-09 14:26:29 +02:00
|
|
|
public function preRequest(SS_HTTPRequest $request, Session $session, DataModel $model) {
|
|
|
|
foreach ($this->filters as $filter) {
|
|
|
|
$res = $filter->preRequest($request, $session, $model);
|
|
|
|
if ($res === false) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function postRequest(SS_HTTPRequest $request, SS_HTTPResponse $response, DataModel $model) {
|
|
|
|
foreach ($this->filters as $filter) {
|
|
|
|
$res = $filter->postRequest($request, $response, $model);
|
|
|
|
if ($res === false) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|