silverstripe-framework/control/RequestProcessor.php
Hamish Friedlander 35cc65820c BUG Make RequestProcessor->filters settable as a property too
filters was a DI property that could only be set via constructor. This meant that modules couldnt add a
filter without interfering with other modules. With this change you can now add a config block like:

Injector:
  RequestProcessor:
    properties:
      filters:
        - "%$MyFilter"

Which will add a filter to RequestProcessors list of filters
2012-07-19 13:58:58 +12:00

41 lines
915 B
PHP

<?php
/**
* Description of RequestProcessor
*
* @author marcus@silverstripe.com.au
* @license BSD License http://silverstripe.org/bsd-license/
*/
class RequestProcessor {
private $filters = array();
public function __construct($filters = array()) {
$this->filters = $filters;
}
public function setFilters($filters) {
$this->filters = $filters;
}
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;
}
}
}
/**
* Filter executed AFTER a request
*/
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;
}
}
}
}