Skip to content
Permalink
Browse files

Fixed request and response deprecations

  • Loading branch information...
Dominik Schmelz
Dominik Schmelz committed Apr 16, 2018
1 parent 9035038 commit ecd631fc0176aa48cac97710f110e6ca0bf3a542
@@ -254,7 +254,7 @@ public function initialize(array $config)
$controller = $this->_registry->getController();
$this->setEventManager($controller->getEventManager());
$this->response =& $controller->response;
$this->session = $controller->request->getSession();
$this->session = $controller->getRequest()->getSession();
if ($this->getConfig('ajaxLogin')) {
deprecationWarning(
@@ -295,7 +295,7 @@ public function authCheck(Event $event)
/** @var \Cake\Controller\Controller $controller */
$controller = $event->getSubject();
$action = strtolower($controller->request->getParam('action'));
$action = strtolower($controller->getRequest()->getParam('action'));
if (!$controller->isAction($action)) {
return null;
}
@@ -354,7 +354,7 @@ public function implementedEvents()
*/
protected function _isAllowed(Controller $controller)
{
$action = strtolower($controller->request->getParam('action'));
$action = strtolower($controller->getRequest()->getParam('action'));
return in_array($action, array_map('strtolower', $this->allowedActions));
}
@@ -383,12 +383,12 @@ protected function _unauthenticated(Controller $controller)
if ($auth === false) {
throw new Exception('At least one authenticate object must be available.');
}
$result = $auth->unauthenticated($controller->request, $response);
$result = $auth->unauthenticated($controller->getRequest(), $response);
if ($result !== null) {
return $result;
}
if (!$controller->request->is('ajax')) {
if (!$controller->getRequest()->is('ajax')) {
$this->flash($this->_config['authError']);
return $controller->redirect($this->_loginActionRedirectUrl());
@@ -439,7 +439,7 @@ protected function _loginActionRedirectUrl()
*/
protected function _isLoginAction(Controller $controller)
{
$url = $controller->request->getRequestTarget();
$url = $controller->getRequest()->getRequestTarget();
$url = Router::normalize($url);
$loginAction = Router::normalize($this->_config['loginAction']);
@@ -128,7 +128,7 @@ public function initialize(array $config)
}
if (empty($this->_config['path'])) {
$this->setConfig('path', $this->request->getAttribute('webroot'));
$this->setConfig('path', $this->getController()->getRequest()->getAttribute('webroot'));
}
}
@@ -246,7 +246,7 @@ protected function _load($key)
if (isset($this->_loaded[$first])) {
return;
}
$cookie = $this->request->getCookie($first);
$cookie = $this->getController()->getRequest()->getCookie($first);
if ($cookie === null) {
return;
}
@@ -80,8 +80,8 @@ public function startup(Event $event)
{
/** @var \Cake\Controller\Controller $controller */
$controller = $event->getSubject();
$request = $controller->request;
$response = $controller->response;
$request = $controller->getRequest();
$response = $controller->getResponse();
$cookieName = $this->_config['cookieName'];
$cookieData = $request->getCookie($cookieName);
@@ -90,20 +90,20 @@ public function startup(Event $event)
}
if ($request->is('requested')) {
$controller->request = $request;
$controller->setRequest($request);
return;
}
if ($request->is('get') && $cookieData === null) {
list($request, $response) = $this->_setCookie($request, $response);
$controller->response = $response;
$controller->setResponse($response);
}
if ($request->is(['put', 'post', 'delete', 'patch']) || $request->getData()) {
$this->_validateToken($request);
$request = $request->withoutData($this->_config['field']);
}
$controller->request = $request;
$controller->setRequest($request);
}
/**
@@ -60,7 +60,7 @@ class FlashComponent extends Component
public function __construct(ComponentRegistry $registry, array $config = [])
{
parent::__construct($registry, $config);
$this->_session = $registry->getController()->request->getSession();
$this->_session = $registry->getController()->getRequest()->getSession();
}
/**
@@ -191,7 +191,7 @@ public function implementedEvents()
*/
public function paginate($object, array $settings = [])
{
$request = $this->_registry->getController()->request;
$request = $this->_registry->getController()->getRequest();
try {
$results = $this->_paginator->paginate(
@@ -228,7 +228,7 @@ public function paginate($object, array $settings = [])
*/
public function mergeOptions($alias, $settings)
{
$request = $this->_registry->getController()->request;
$request = $this->_registry->getController()->getRequest();
return $this->_paginator->mergeOptions(
$request->getQueryParams(),
@@ -191,8 +191,8 @@ public function startup(Event $event)
{
/** @var \Cake\Controller\Controller $controller */
$controller = $event->getSubject();
$request = $controller->request;
$response = $controller->response;
$request = $controller->getRequest();
$response = $controller->getResponse();
if ($request->getParam('_ext')) {
$this->ext = $request->getParam('_ext');
@@ -202,7 +202,7 @@ public function startup(Event $event)
}
$isAjax = $request->is('ajax');
$controller->request = $request->withParam('isAjax', $isAjax);
$controller->setRequest($request->withParam('isAjax', $isAjax));
if (!$this->ext && $isAjax) {
$this->ext = 'ajax';
@@ -221,7 +221,7 @@ public function startup(Event $event)
}
if ($this->requestedWith($type)) {
$input = $request->input(...$handler);
$controller->request = $request->withParsedBody((array)$input);
$controller->setRequest($request->withParsedBody((array)$input));
}
}
}
@@ -268,7 +268,7 @@ public function beforeRedirect(Event $event, $url, Response $response)
'This functionality will be removed in 4.0.0. Set the `enableBeforeRedirect` ' .
'option to `false` to disable this warning.'
);
$request = $this->request;
$request = $this->getController()->getRequest();
if (!$request->is('ajax')) {
return null;
}
@@ -325,8 +325,8 @@ public function beforeRender(Event $event)
{
/** @var \Cake\Controller\Controller $controller */
$controller = $event->getSubject();
$response = $controller->response;
$request = $controller->request;
$response = $controller->getResponse();
$request = $controller->getRequest();
$isRecognized = (
!in_array($this->ext, ['html', 'htm']) &&
@@ -343,11 +343,11 @@ public function beforeRender(Event $event)
if ($this->_config['checkHttpCache'] &&
$response->checkNotModified($request)
) {
$controller->response = $response;
$controller->setResponse($response);
return false;
}
$controller->response = $response;
$controller->setResponse($response);
}
/**
@@ -388,7 +388,7 @@ public function isAtom()
*/
public function isMobile()
{
$request = $this->request;
$request = $this->getController()->getRequest();
return $request->is('mobile') || $this->accepts('wap');
}
@@ -432,8 +432,8 @@ public function isWap()
public function accepts($type = null)
{
$controller = $this->getController();
$request = $controller->request;
$response = $controller->response;
$request = $controller->getRequest();
$response = $controller->getResponse();
$accepted = $request->accepts();
if (!$type) {
@@ -467,8 +467,8 @@ public function accepts($type = null)
public function requestedWith($type = null)
{
$controller = $this->getController();
$request = $controller->request;
$response = $controller->response;
$request = $controller->getRequest();
$response = $controller->getResponse();
if (!$request->is('post') &&
!$request->is('put') &&
@@ -515,8 +515,8 @@ public function requestedWith($type = null)
public function prefers($type = null)
{
$controller = $this->getController();
$request = $controller->request;
$response = $controller->response;
$request = $controller->getRequest();
$response = $controller->getResponse();
$acceptRaw = $request->parseAccept();
if (empty($acceptRaw)) {
@@ -639,8 +639,8 @@ public function respondAs($type, array $options = [])
$cType = $type;
$controller = $this->getController();
$response = $controller->response;
$request = $controller->request;
$response = $controller->getResponse();
$request = $controller->getRequest();
if (strpos($type, '/') === false) {
$cType = $response->getMimeType($type);
@@ -669,7 +669,7 @@ public function respondAs($type, array $options = [])
if (!empty($options['attachment'])) {
$response = $response->withDownload($options['attachment']);
}
$controller->response = $response;
$controller->setResponse($response);
return true;
}
@@ -127,10 +127,10 @@ public function startup(Event $event)
}
$request = $this->generateToken($request);
if ($hasData && is_array($controller->request->getData())) {
if ($hasData && is_array($controller->getRequest()->getData())) {
$request = $request->withoutData('_Token');
}
$controller->request = $request;
$controller->setRequest($request);
}
/**
@@ -242,7 +242,7 @@ protected function _secureRequired(Controller $controller)
$requireSecure = $this->_config['requireSecure'];
if (in_array($this->_action, $requireSecure) || $requireSecure === ['*']) {
if (!$this->request->is('ssl')) {
if (!$this->getController()->getRequest()->is('ssl')) {
throw new SecurityException(
'Request is not SSL and the action is required to be secure'
);
@@ -262,7 +262,7 @@ protected function _secureRequired(Controller $controller)
*/
protected function _authRequired(Controller $controller)
{
$request = $controller->request;
$request = $controller->getRequest();
if (is_array($this->_config['requireAuth']) &&
!empty($this->_config['requireAuth']) &&
$request->getData()
@@ -343,7 +343,7 @@ protected function _validatePost(Controller $controller)
*/
protected function _validToken(Controller $controller)
{
$check = $controller->request->getData();
$check = $controller->getRequest()->getData();
$message = '\'%s\' was not found in request data.';
if (!isset($check['_Token'])) {
@@ -378,11 +378,11 @@ protected function _validToken(Controller $controller)
*/
protected function _hashParts(Controller $controller)
{
$fieldList = $this->_fieldsList($controller->request->getData());
$unlocked = $this->_sortedUnlocked($controller->request->getData());
$fieldList = $this->_fieldsList($controller->getRequest()->getData());
$unlocked = $this->_sortedUnlocked($controller->getRequest()->getData());
return [
$controller->request->getRequestTarget(),
$controller->getRequest()->getRequestTarget(),
serialize($fieldList),
$unlocked,
session_id(),
@@ -494,7 +494,7 @@ protected function _sortedUnlocked($data)
protected function _debugPostTokenNotMatching(Controller $controller, $hashParts)
{
$messages = [];
$expectedParts = json_decode(urldecode($controller->request->getData('_Token.debug')), true);
$expectedParts = json_decode(urldecode($controller->getRequest()->getData('_Token.debug')), true);
if (!is_array($expectedParts) || count($expectedParts) !== 3) {
return 'Invalid security debug token.';
}
@@ -734,7 +734,7 @@ public function redirect($url, $status = 302)
*/
public function setAction($action, ...$args)
{
$this->request = $this->request->withParam('action', $action);
$this->setRequest($this->getRequest()->withParam('action', $action));
return $this->$action(...$args);
}
@@ -754,7 +754,7 @@ public function render($view = null, $layout = null)
$builder->setTemplatePath($this->_viewPath());
}
if ($this->request->getParam('bare')) {
if ($this->getRequest()->getParam('bare')) {
$builder->enableAutoLayout(false);
}
$builder->getClassName($this->viewClass);
@@ -766,18 +766,18 @@ public function render($view = null, $layout = null)
return $event->getResult();
}
if ($event->isStopped()) {
return $this->response;
return $this->getResponse();
}
if ($builder->getTemplate() === null && $this->request->getParam('action')) {
$builder->setTemplate($this->request->getParam('action'));
if ($builder->getTemplate() === null && $this->getRequest()->getParam('action')) {
$builder->setTemplate($this->getRequest()->getParam('action'));
}
$this->View = $this->createView();
$contents = $this->View->render($view, $layout);
$this->response = $this->View->response->withStringBody($contents);
$this->setResponse($this->View->response->withStringBody($contents));
return $this->response;
return $this->getResponse();
}
/**
@@ -788,10 +788,10 @@ public function render($view = null, $layout = null)
protected function _viewPath()
{
$viewPath = $this->name;
if ($this->request->getParam('prefix')) {
if ($this->getRequest()->getParam('prefix')) {
$prefixes = array_map(
'Cake\Utility\Inflector::camelize',
explode('/', $this->request->getParam('prefix'))
explode('/', $this->getRequest()->getParam('prefix'))
);
$viewPath = implode(DIRECTORY_SEPARATOR, $prefixes) . DIRECTORY_SEPARATOR . $viewPath;
}
@@ -808,14 +808,14 @@ protected function _viewPath()
*/
public function referer($default = null, $local = false)
{
if (!$this->request) {
if (!$this->getRequest()) {
return Router::url($default, !$local);
}
$referer = $this->request->referer($local);
$referer = $this->getRequest()->referer($local);
if ($referer === '/' && $default && $default !== $referer) {
$url = Router::url($default, !$local);
$base = $this->request->getAttribute('base');
$base = $this->getRequest()->getAttribute('base');
if ($local && $base && strpos($url, $base) === 0) {
$url = substr($url, strlen($base));
if ($url[0] !== '/') {
Oops, something went wrong.

0 comments on commit ecd631f

Please sign in to comment.
You can’t perform that action at this time.