Skip to content

Commit

Permalink
Fixed request and response deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominik Schmelz committed Apr 16, 2018
1 parent 9035038 commit ecd631f
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 60 deletions.
12 changes: 6 additions & 6 deletions src/Controller/Component/AuthComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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']);

Expand Down
4 changes: 2 additions & 2 deletions src/Controller/Component/CookieComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}
}

Expand Down Expand Up @@ -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;
}
Expand Down
10 changes: 5 additions & 5 deletions src/Controller/Component/CsrfComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Component/FlashComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Controller/Component/PaginatorComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(),
Expand Down
38 changes: 19 additions & 19 deletions src/Controller/Component/RequestHandlerComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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';
Expand All @@ -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));
}
}
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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']) &&
Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -388,7 +388,7 @@ public function isAtom()
*/
public function isMobile()
{
$request = $this->request;
$request = $this->getController()->getRequest();

return $request->is('mobile') || $this->accepts('wap');
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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') &&
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down
18 changes: 9 additions & 9 deletions src/Controller/Component/SecurityComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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'
);
Expand All @@ -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()
Expand Down Expand Up @@ -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'])) {
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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.';
}
Expand Down
24 changes: 12 additions & 12 deletions src/Controller/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
Expand All @@ -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();
}

/**
Expand All @@ -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;
}
Expand All @@ -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] !== '/') {
Expand Down
Loading

0 comments on commit ecd631f

Please sign in to comment.