2012-05-09 14:26:29 +02:00
|
|
|
<?php
|
|
|
|
|
2016-08-19 00:51:35 +02:00
|
|
|
namespace SilverStripe\Control;
|
|
|
|
|
|
|
|
use SilverStripe\Core\Injector\Injectable;
|
2016-06-15 06:03:16 +02:00
|
|
|
use SilverStripe\ORM\DataModel;
|
|
|
|
|
2012-05-09 14:26:29 +02:00
|
|
|
/**
|
2014-03-04 05:43:17 +01:00
|
|
|
* Represents a request processer that delegates pre and post request handling to nested request filters
|
2012-05-09 14:26:29 +02:00
|
|
|
*/
|
2014-03-04 05:43:17 +01:00
|
|
|
class RequestProcessor implements RequestFilter {
|
2016-08-19 00:51:35 +02:00
|
|
|
use Injectable;
|
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;
|
|
|
|
}
|
|
|
|
|
2016-09-09 08:43:05 +02:00
|
|
|
public function preRequest(HTTPRequest $request, Session $session, DataModel $model) {
|
2012-05-09 14:26:29 +02:00
|
|
|
foreach ($this->filters as $filter) {
|
|
|
|
$res = $filter->preRequest($request, $session, $model);
|
|
|
|
if ($res === false) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2016-08-19 00:51:35 +02:00
|
|
|
return null;
|
2012-05-09 14:26:29 +02:00
|
|
|
}
|
|
|
|
|
2016-09-09 08:43:05 +02:00
|
|
|
public function postRequest(HTTPRequest $request, HTTPResponse $response, DataModel $model) {
|
2012-05-09 14:26:29 +02:00
|
|
|
foreach ($this->filters as $filter) {
|
|
|
|
$res = $filter->postRequest($request, $response, $model);
|
|
|
|
if ($res === false) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2016-08-19 00:51:35 +02:00
|
|
|
return null;
|
2012-05-09 14:26:29 +02:00
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
}
|