Merge pull request #4141 from stevie-mayhew/pulls/getrequest

UPDATE: change all instances of $this->request to use appropriate getter/setter
This commit is contained in:
Ingo Schommer 2015-04-30 11:56:26 +12:00
commit f275076908
22 changed files with 95 additions and 74 deletions

View File

@ -264,7 +264,7 @@ class LeftAndMain extends Controller implements PermissionProvider {
if($this->redirectedTo()) return;
// Audit logging hook
if(empty($_REQUEST['executeForm']) && !$this->request->isAjax()) $this->extend('accessedCMS');
if(empty($_REQUEST['executeForm']) && !$this->getRequest()->isAjax()) $this->extend('accessedCMS');
// Set the members html editor config
if(Member::currentUser()) {
@ -472,10 +472,10 @@ class LeftAndMain extends Controller implements PermissionProvider {
* See LeftAndMain.js for the required jQuery ajaxComplete handlers.
*/
public function redirect($url, $code=302) {
if($this->request->isAjax()) {
if($this->getRequest()->isAjax()) {
$this->response->addHeader('X-ControllerURL', $url);
if($this->request->getHeader('X-Pjax') && !$this->response->getHeader('X-Pjax')) {
$this->response->addHeader('X-Pjax', $this->request->getHeader('X-Pjax'));
if($this->getRequest()->getHeader('X-Pjax') && !$this->response->getHeader('X-Pjax')) {
$this->response->addHeader('X-Pjax', $this->getRequest()->getHeader('X-Pjax'));
}
$oldResponse = $this->response;
$newResponse = new LeftAndMain_HTTPResponse(
@ -786,7 +786,7 @@ class LeftAndMain extends Controller implements PermissionProvider {
$filterFunction = null, $nodeCountThreshold = 30) {
// Filter criteria
$params = $this->request->getVar('q');
$params = $this->getRequest()->getVar('q');
if(isset($params['FilterClass']) && $filterClass = $params['FilterClass']){
if(!is_subclass_of($filterClass, 'CMSSiteTreeFilter')) {
throw new Exception(sprintf('Invalid filter class passed: %s', $filterClass));
@ -1006,7 +1006,7 @@ class LeftAndMain extends Controller implements PermissionProvider {
$this->setCurrentPageID($record->ID);
$this->response->addHeader('X-Status', rawurlencode(_t('LeftAndMain.SAVEDUP', 'Saved.')));
return $this->getResponseNegotiator()->respond($this->request);
return $this->getResponseNegotiator()->respond($this->getRequest());
}
public function delete($data, $form) {
@ -1021,7 +1021,7 @@ class LeftAndMain extends Controller implements PermissionProvider {
$this->response->addHeader('X-Status', rawurlencode(_t('LeftAndMain.DELETED', 'Deleted.')));
return $this->getResponseNegotiator()->respond(
$this->request,
$this->getRequest(),
array('currentform' => array($this, 'EmptyForm'))
);
}
@ -1443,8 +1443,8 @@ class LeftAndMain extends Controller implements PermissionProvider {
* @return int
*/
public function currentPageID() {
if($this->request->requestVar('ID') && is_numeric($this->request->requestVar('ID'))) {
return $this->request->requestVar('ID');
if($this->getRequest()->requestVar('ID') && is_numeric($this->getRequest()->requestVar('ID'))) {
return $this->getRequest()->requestVar('ID');
} elseif (isset($this->urlParams['ID']) && is_numeric($this->urlParams['ID'])) {
return $this->urlParams['ID'];
} elseif(Session::get($this->sessionNamespace() . ".currentPage")) {

View File

@ -98,8 +98,8 @@ abstract class ModelAdmin extends LeftAndMain {
$models = $this->getManagedModels();
if($this->request->param('ModelClass')) {
$this->modelClass = $this->unsanitiseClassName($this->request->param('ModelClass'));
if($this->getRequest()->param('ModelClass')) {
$this->modelClass = $this->unsanitiseClassName($this->getRequest()->param('ModelClass'));
} else {
reset($models);
$this->modelClass = key($models);
@ -200,7 +200,7 @@ abstract class ModelAdmin extends LeftAndMain {
$form->setFormAction($this->Link($this->sanitiseClassName($this->modelClass)));
$form->addExtraClass('cms-search-form');
$form->disableSecurityToken();
$form->loadDataFrom($this->request->getVars());
$form->loadDataFrom($this->getRequest()->getVars());
$this->extend('updateSearchForm', $form);
@ -209,7 +209,7 @@ abstract class ModelAdmin extends LeftAndMain {
public function getList() {
$context = $this->getSearchContext();
$params = $this->request->requestVar('q');
$params = $this->getRequest()->requestVar('q');
if(is_array($params)) {
$params = array_map('trim', $params);
@ -449,7 +449,7 @@ abstract class ModelAdmin extends LeftAndMain {
// Show the class name rather than ModelAdmin title as root node
$models = $this->getManagedModels();
$params = $this->request->getVars();
$params = $this->getRequest()->getVars();
if(isset($params['url'])) unset($params['url']);
$items[0]->Title = $models[$this->modelClass]['title'];

View File

@ -166,7 +166,7 @@ class SecurityAdmin extends LeftAndMain implements PermissionProvider {
$rolesTab->push($rolesField);
}
$actionParam = $this->request->param('Action');
$actionParam = $this->getRequest()->param('Action');
if($actionParam == 'groups') {
$groupsTab->addExtraClass('ui-state-active');
} elseif($actionParam == 'users') {
@ -273,7 +273,7 @@ class SecurityAdmin extends LeftAndMain implements PermissionProvider {
// Name root breadcrumb based on which record is edited,
// which can only be determined by looking for the fieldname of the GridField.
// Note: Titles should be same titles as tabs in RootForm().
$params = $this->request->allParams();
$params = $this->getRequest()->allParams();
if(isset($params['FieldName'])) {
// TODO FieldName param gets overwritten by nested GridFields,
// so shows "Members" rather than "Groups" for the following URL:

View File

@ -81,8 +81,8 @@ class CMSFormTest_Controller extends Controller implements TestOnly {
protected $template = 'BlankPage';
public function Link($action = null) {
return Controller::join_links('CMSFormTest_Controller', $this->request->latestParam('Action'),
$this->request->latestParam('ID'), $action);
return Controller::join_links('CMSFormTest_Controller', $this->getRequest()->latestParam('Action'),
$this->getRequest()->latestParam('ID'), $action);
}
public function Form() {

View File

@ -118,7 +118,7 @@ class Controller extends RequestHandler implements TemplateGlobalProvider {
$this->pushCurrent();
$this->urlParams = $request->allParams();
$this->request = $request;
$this->setRequest($request);
$this->response = new SS_HTTPResponse();
$this->setDataModel($model);
@ -487,13 +487,13 @@ class Controller extends RequestHandler implements TemplateGlobalProvider {
// In edge-cases, this will be called outside of a handleRequest() context; in that case,
// redirect to the homepage - don't break into the global state at this stage because we'll
// be calling from a test context or something else where the global state is inappropraite
if($this->request) {
if($this->request->requestVar('BackURL')) {
$url = $this->request->requestVar('BackURL');
} else if($this->request->isAjax() && $this->request->getHeader('X-Backurl')) {
$url = $this->request->getHeader('X-Backurl');
} else if($this->request->getHeader('Referer')) {
$url = $this->request->getHeader('Referer');
if($this->getRequest()) {
if($this->getRequest()->requestVar('BackURL')) {
$url = $this->getRequest()->requestVar('BackURL');
} else if($this->getRequest()->isAjax() && $this->getRequest()->getHeader('X-Backurl')) {
$url = $this->getRequest()->getHeader('X-Backurl');
} else if($this->getRequest()->getHeader('Referer')) {
$url = $this->getRequest()->getHeader('Referer');
}
}

View File

@ -111,7 +111,7 @@ class RequestHandler extends ViewableData {
$this->brokenOnConstruct = false;
// Check necessary to avoid class conflicts before manifest is rebuilt
if(class_exists('NullHTTPRequest')) $this->request = new NullHTTPRequest();
if(class_exists('NullHTTPRequest')) $this->setRequest(new NullHTTPRequest());
// This will prevent bugs if setDataModel() isn't called.
$this->model = DataModel::inst();
@ -155,7 +155,7 @@ class RequestHandler extends ViewableData {
user_error("parent::__construct() needs to be called on {$handlerClass}::__construct()", E_USER_WARNING);
}
$this->request = $request;
$this->setRequest($request);
$this->setDataModel($model);
$match = $this->findAction($request);
@ -462,11 +462,14 @@ class RequestHandler extends ViewableData {
* @uses SS_HTTPResponse_Exception
*/
public function httpError($errorCode, $errorMessage = null) {
$request = $this->getRequest();
// Call a handler method such as onBeforeHTTPError404
$this->extend('onBeforeHTTPError' . $errorCode, $this->request);
$this->extend('onBeforeHTTPError' . $errorCode, $request);
// Call a handler method such as onBeforeHTTPError, passing 404 as the first arg
$this->extend('onBeforeHTTPError', $errorCode, $this->request);
$this->extend('onBeforeHTTPError', $errorCode, $request);
// Throw a new exception
throw new SS_HTTPResponse_Exception($errorMessage, $errorCode);

View File

@ -28,7 +28,7 @@ class PaginatedList extends SS_ListDecorator {
throw new Exception('The request must be readable as an array.');
}
$this->request = $request;
$this->setRequest($request);
parent::__construct($list);
}
@ -92,13 +92,14 @@ class PaginatedList extends SS_ListDecorator {
* @return int
*/
public function getPageStart() {
$request = $this->getRequest();
if ($this->pageStart === null) {
if(
$this->request
&& isset($this->request[$this->getPaginationGetVar()])
&& $this->request[$this->getPaginationGetVar()] > 0
$request
&& isset($request[$this->getPaginationGetVar()])
&& $request[$this->getPaginationGetVar()] > 0
) {
$this->pageStart = (int)$this->request[$this->getPaginationGetVar()];
$this->pageStart = (int)$request[$this->getPaginationGetVar()];
} else {
$this->pageStart = 0;
}
@ -433,4 +434,20 @@ class PaginatedList extends SS_ListDecorator {
}
}
/**
* Set the request object for this list
*
* @param SS_HTTPRequest
*/
public function setRequest($request) {
$this->request = $request;
}
/**
* Get the request object for this list
*/
public function getRequest() {
return $this->request;
}
}

View File

@ -33,7 +33,7 @@ class DevelopmentAdmin extends Controller {
parent::init();
// Special case for dev/build: Defer permission checks to DatabaseAdmin->init() (see #4957)
$requestedDevBuild = (stripos($this->request->getURL(), 'dev/build') === 0);
$requestedDevBuild = (stripos($this->getRequest()->getURL(), 'dev/build') === 0);
// We allow access to this controller regardless of live-status or ADMIN permission only
// if on CLI. Access to this controller is always allowed in "dev-mode", or of the user is ADMIN.

View File

@ -357,8 +357,8 @@ class TestRunner extends Controller {
// Optionally skip certain tests
$skipTests = array();
if($this->request->getVar('SkipTests')) {
$skipTests = explode(',', $this->request->getVar('SkipTests'));
if($this->getRequest()->getVar('SkipTests')) {
$skipTests = explode(',', $this->getRequest()->getVar('SkipTests'));
}
$abstractClasses = array();

View File

@ -84,7 +84,7 @@ Variables can come from your database fields, or custom methods you define on yo
:::php
public function UsersIpAddress() {
return $this->request->getIP();
return $this->getRequest()->getIP();
}
**mysite/code/Page.ss**

View File

@ -17,7 +17,7 @@ The `PaginatedList` will automatically set up query limits and read the request
public function PaginatedPages() {
$list = Page::get();
return new PaginatedList($list, $this->request);
return new PaginatedList($list, $this->getRequest());
}
<div class="notice" markdown="1">
@ -78,14 +78,14 @@ when using custom lists.
:::php
$myPreLimitedList = Page::get()->limit(10);
$pages = new PaginatedList($myPreLimitedList, $this->request);
$pages = new PaginatedList($myPreLimitedList, $this->getRequest());
$pages->setLimitItems(false);
## Setting the limit of items
:::php
$pages = new PaginatedList(Page::get(), $this->request);
$pages = new PaginatedList(Page::get(), $this->getRequest());
$pages->setPageLength(25);
If you set this limit to 0 it will disable paging entirely, effectively causing it to appear as a single page

View File

@ -41,10 +41,10 @@ This route has defined that any URL beginning with `team` should create, and be
It also contains 3 `parameters` or `params` for short. `$Action`, `$ID` and `$Name`. These variables are placeholders
which will be filled when the user makes their request. Request parameters are available on the `SS_HTTPRequest` object
and able to be pulled out from a controller using `$this->request->param($name)`.
and able to be pulled out from a controller using `$this->getRequest()->param($name)`.
<div class="info" markdown="1">
All Controllers have access to `$this->request` for the request object and `$this->response` for the response.
All Controllers have access to `$this->getRequest()` for the request object and `$this->response` for the response.
</div>
Here is what those parameters would look like for certain requests
@ -52,7 +52,7 @@ Here is what those parameters would look like for certain requests
:::php
// GET /teams/
print_r($this->request->params());
print_r($this->getRequest()->params());
// Array
// (
@ -63,7 +63,7 @@ Here is what those parameters would look like for certain requests
// GET /teams/players/
print_r($this->request->params());
print_r($this->getRequest()->params());
// Array
// (
@ -74,7 +74,7 @@ Here is what those parameters would look like for certain requests
// GET /teams/players/1
print_r($this->request->params());
print_r($this->getRequest()->params());
// Array
// (
@ -89,7 +89,7 @@ You can also fetch one parameter at a time.
// GET /teams/players/1/
echo $this->request->param('ID');
echo $this->getRequest()->param('ID');
// returns '1'
@ -184,8 +184,8 @@ parameters.
);
public function go() {
$this->validateUser(
$this->request->param('UserName'),
$this->request->param('AuthToken')
$this->getRequest()->param('UserName'),
$this->getRequest()->param('AuthToken')
);
/* more processing goes here */
}

View File

@ -116,7 +116,7 @@ in order to read page limit information. It is also passed the current
:::php
public function getResults($searchCriteria = array()) {
$start = ($this->request->getVar('start')) ? (int)$this->request->getVar('start') : 0;
$start = ($this->getRequest()->getVar('start')) ? (int)$this->getRequest()->getVar('start') : 0;
$limit = 10;
$context = singleton('MyDataObject')->getCustomSearchContext();
@ -124,7 +124,7 @@ in order to read page limit information. It is also passed the current
$records = $context->getResults($searchCriteria, null, array('start'=>$start,'limit'=>$limit));
if($records) {
$records = new PaginatedList($records, $this->request);
$records = new PaginatedList($records, $this->getRequest());
$records->setPageStart($start);
$records->setPageLength($limit);
$records->setTotalItems($query->unlimitedRowCount());

View File

@ -215,7 +215,7 @@ checkbox which limits search results to expensive products (over $100).
public function getList() {
$list = parent::getList();
$params = $this->request->requestVar('q'); // use this to access search parameters
$params = $this->getRequest()->requestVar('q'); // use this to access search parameters
if($this->modelClass == 'Product' && isset($params['ExpensiveOnly']) && $params['ExpensiveOnly']) {
$list = $list->exclude('Price:LessThan', '100');

View File

@ -506,7 +506,7 @@ class HtmlEditorField_Toolbar extends RequestHandler {
* @return array
*/
public function getanchors() {
$id = (int)$this->request->getVar('PageID');
$id = (int)$this->getRequest()->getVar('PageID');
$anchors = array();
if (($page = Page::get()->byID($id)) && !empty($page)) {

View File

@ -689,10 +689,10 @@ class GridField extends FormField {
user_error("parent::__construct() needs to be called on {$handlerClass}::__construct()", E_USER_WARNING);
}
$this->request = $request;
$this->setRequest($request);
$this->setDataModel($model);
$fieldData = $this->request->requestVar($this->getName());
$fieldData = $this->getRequest()->requestVar($this->getName());
if($fieldData && isset($fieldData['GridState'])) $this->getState(false)->setValue($fieldData['GridState']);
foreach($this->getComponents() as $component) {

View File

@ -50,7 +50,7 @@ class CMSSecurity extends Security {
* @return Member
*/
public function getTargetMember() {
if($tempid = $this->request->requestVar('tempid')) {
if($tempid = $this->getRequest()->requestVar('tempid')) {
return Member::member_from_tempid($tempid);
}
}
@ -191,7 +191,7 @@ PHP
// Get redirect url
$controller = $this->getResponseController(_t('CMSSecurity.SUCCESS', 'Success'));
$backURL = $this->request->requestVar('BackURL')
$backURL = $this->getRequest()->requestVar('BackURL')
?: Session::get('BackURL')
?: Director::absoluteURL(AdminRootController::config()->url_base, true);

View File

@ -318,7 +318,7 @@ class Security extends Controller implements TemplateGlobalProvider {
* @return string Class name of Authenticator
*/
protected function getAuthenticator() {
$authenticator = $this->request->requestVar('AuthenticationMethod');
$authenticator = $this->getRequest()->requestVar('AuthenticationMethod');
if($authenticator) {
$authenticators = Authenticator::get_authenticators();
if(in_array($authenticator, $authenticators)) {
@ -420,7 +420,7 @@ class Security extends Controller implements TemplateGlobalProvider {
// This step is necessary in cases such as automatic redirection where a user is authenticated
// upon landing on an SSL secured site and is automatically logged in, or some other case
// where the user has permissions to continue but is not given the option.
if($this->request->requestVar('BackURL')
if($this->getRequest()->requestVar('BackURL')
&& !$this->getLoginMessage()
&& ($member = Member::currentUser())
&& $member->exists()

View File

@ -10,13 +10,14 @@ class FakeController extends Controller {
$this->pushCurrent();
$this->request = new SS_HTTPRequest(
$request = new SS_HTTPRequest(
(isset($_SERVER['X-HTTP-Method-Override']))
? $_SERVER['X-HTTP-Method-Override']
: $_SERVER['REQUEST_METHOD'],
'/'
);
$this->setRequest($request);
$this->response = new SS_HTTPResponse();
$this->init();

View File

@ -343,18 +343,18 @@ class RestfulServiceTest_Controller extends Controller implements TestOnly {
public function index() {
$request = '';
foreach ($this->request->requestVars() as $key=>$value) {
foreach ($this->getRequest()->requestVars() as $key=>$value) {
$request .= "\t\t<request_item name=\"$key\">$value</request_item>\n";
}
$get = '';
foreach ($this->request->getVars() as $key => $value) {
foreach ($this->getRequest()->getVars() as $key => $value) {
$get .= "\t\t<get_item name=\"$key\">$value</get_item>\n";
}
$post = '';
foreach ($this->request->postVars() as $key => $value) {
foreach ($this->getRequest()->postVars() as $key => $value) {
$post .= "\t\t<post_item name=\"$key\">$value</post_item>\n";
}
$body = $this->request->getBody();
$body = $this->getRequest()->getBody();
$out = <<<XML
<?xml version="1.0"?>

View File

@ -84,8 +84,8 @@ class EmailFieldTest_Controller extends Controller implements TestOnly {
function Link($action = null) {
return Controller::join_links(
'EmailFieldTest_Controller',
$this->request->latestParam('Action'),
$this->request->latestParam('ID'),
$this->getRequest()->latestParam('Action'),
$this->getRequest()->latestParam('ID'),
$action
);
}

View File

@ -654,8 +654,8 @@ class FormTest_Controller extends Controller implements TestOnly {
protected $template = 'BlankPage';
public function Link($action = null) {
return Controller::join_links('FormTest_Controller', $this->request->latestParam('Action'),
$this->request->latestParam('ID'), $action);
return Controller::join_links('FormTest_Controller', $this->getRequest()->latestParam('Action'),
$this->getRequest()->latestParam('ID'), $action);
}
public function Form() {
@ -706,8 +706,8 @@ class FormTest_ControllerWithSecurityToken extends Controller implements TestOnl
protected $template = 'BlankPage';
public function Link($action = null) {
return Controller::join_links('FormTest_ControllerWithSecurityToken', $this->request->latestParam('Action'),
$this->request->latestParam('ID'), $action);
return Controller::join_links('FormTest_ControllerWithSecurityToken', $this->getRequest()->latestParam('Action'),
$this->getRequest()->latestParam('ID'), $action);
}
public function Form() {
@ -741,8 +741,8 @@ class FormTest_ControllerWithStrictPostCheck extends Controller implements TestO
public function Link($action = null) {
return Controller::join_links(
'FormTest_ControllerWithStrictPostCheck',
$this->request->latestParam('Action'),
$this->request->latestParam('ID'),
$this->getRequest()->latestParam('Action'),
$this->getRequest()->latestParam('ID'),
$action
);
}