mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
Removing all the deprecated properties from Controller.
Adding a __get() method to provide the properties that were moved to CakeRequest. Tests added.
This commit is contained in:
parent
c7fb20d13a
commit
84565151de
2 changed files with 61 additions and 60 deletions
|
@ -47,29 +47,6 @@ class Controller extends Object {
|
|||
*/
|
||||
public $name = null;
|
||||
|
||||
/**
|
||||
* Stores the current URL, relative to the webroot of the application.
|
||||
*
|
||||
* @var string
|
||||
* @deprecated Will be removed in future versions. Use $this->request->here instead
|
||||
*/
|
||||
public $here = null;
|
||||
|
||||
/**
|
||||
* The webroot of the application.
|
||||
*
|
||||
* @var string
|
||||
* @deprecated Will be removed in future versions. Use $this->request->webroot instead
|
||||
*/
|
||||
public $webroot = null;
|
||||
|
||||
/**
|
||||
* The name of the currently requested controller action.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $action = null;
|
||||
|
||||
/**
|
||||
* An array containing the class names of models this controller uses.
|
||||
*
|
||||
|
@ -94,27 +71,10 @@ class Controller extends Object {
|
|||
*/
|
||||
public $helpers = array('Session', 'Html', 'Form');
|
||||
|
||||
/**
|
||||
* Parameters received in the current request: GET and POST data, information
|
||||
* about the request, etc.
|
||||
*
|
||||
* @var array
|
||||
* @link http://book.cakephp.org/view/963/The-Parameters-Attribute-params
|
||||
* @deprecated Will be removed in future versions. Use $this->request instead
|
||||
*/
|
||||
public $params = array();
|
||||
|
||||
/**
|
||||
* Data POSTed to the controller using the HtmlHelper. Data here is accessible
|
||||
* using the `$this->data['ModelName']['fieldName']` pattern.
|
||||
*
|
||||
* @var array
|
||||
* @deprecated Will be removed in future versions. Use $this->request->data instead
|
||||
*/
|
||||
public $data = array();
|
||||
|
||||
/**
|
||||
* An instance of a CakeRequest object that contains information about the current request.
|
||||
* This object contains all the information about a request and several methods for reading
|
||||
* additional information about the request.
|
||||
*
|
||||
* @var CakeRequest
|
||||
*/
|
||||
|
@ -127,7 +87,6 @@ class Controller extends Object {
|
|||
*/
|
||||
public $response;
|
||||
|
||||
|
||||
/**
|
||||
* The classname to use for creating the response object.
|
||||
*
|
||||
|
@ -183,14 +142,6 @@ class Controller extends Object {
|
|||
*/
|
||||
public $modelNames = array();
|
||||
|
||||
/**
|
||||
* Base URL path.
|
||||
*
|
||||
* @var string
|
||||
* @deprecated Will be removed in future versions. Use $this->request->base instead
|
||||
*/
|
||||
public $base = null;
|
||||
|
||||
/**
|
||||
* The name of the layout file to render the view inside of. The name specified
|
||||
* is the filename of the layout in /app/views/layouts without the .ctp
|
||||
|
@ -376,6 +327,27 @@ class Controller extends Object {
|
|||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides backwards compatbility access to the request object properties.
|
||||
* Also provides the params alias.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __get($name) {
|
||||
switch ($name) {
|
||||
case 'base':
|
||||
case 'here':
|
||||
case 'webroot':
|
||||
case 'data':
|
||||
return $this->request->{$name};
|
||||
case 'action':
|
||||
return $this->request->params['action'];
|
||||
case 'params':
|
||||
return $this->request;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the request objects and configures a number of controller properties
|
||||
* based on the contents of the request.
|
||||
|
@ -384,20 +356,13 @@ class Controller extends Object {
|
|||
* @return void
|
||||
*/
|
||||
protected function _setRequest(CakeRequest $request) {
|
||||
$this->base = $request->base;
|
||||
$this->here = $request->here;
|
||||
$this->webroot = $request->webroot;
|
||||
$this->request = $request;
|
||||
$this->plugin = isset($request->params['plugin']) ? $request->params['plugin'] : null;
|
||||
$this->params = $this->request = $request;
|
||||
$this->action =& $request->params['action'];
|
||||
|
||||
if (isset($request->params['pass']) && isset($request->params['named'])) {
|
||||
$this->passedArgs = array_merge($request->params['pass'], $request->params['named']);
|
||||
}
|
||||
|
||||
$this->data = null;
|
||||
if (!empty($request->params['data'])) {
|
||||
$this->data =& $request->params['data'];
|
||||
}
|
||||
if (array_key_exists('return', $request->params) && $request->params['return'] == 1) {
|
||||
$this->autoRender = false;
|
||||
}
|
||||
|
|
|
@ -1499,4 +1499,40 @@ class ControllerTest extends CakeTestCase {
|
|||
|
||||
$Controller->shutdownProcess();
|
||||
}
|
||||
|
||||
/**
|
||||
* test that BC works for attributes on the request object.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testPropertyBackwardsCompatibility() {
|
||||
$request = new CakeRequest('posts/index', null);
|
||||
$request->addParams(array('controller' => 'posts', 'action' => 'index'));
|
||||
$request->data = array('Post' => array('id' => 1));
|
||||
$request->here = '/posts/index';
|
||||
$request->webroot = '/';
|
||||
|
||||
$Controller = new TestController($request);
|
||||
$this->assertEquals($request->data, $Controller->data);
|
||||
$this->assertEquals($request->webroot, $Controller->webroot);
|
||||
$this->assertEquals($request->here, $Controller->here);
|
||||
$this->assertEquals($request->action, $Controller->action);
|
||||
|
||||
$this->assertEquals($request, $Controller->params);
|
||||
$this->assertEquals($request->params['controller'], $Controller->params['controller']);
|
||||
}
|
||||
|
||||
/**
|
||||
* test that the BC wrapper doesn't interfere with models and components.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testPropertyCompatibilityAndModelsComponents() {
|
||||
$request = new CakeRequest('controller_posts/index');
|
||||
|
||||
$Controller = new TestController($request);
|
||||
$Controller->constructClasses();
|
||||
$this->assertType('SecurityComponent', $Controller->Security);
|
||||
$this->assertType('ControllerComment', $Controller->ControllerComment);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue