Skip to content
Permalink
Browse files

Rename Controller::addComponent() to Controller::loadComponent().

  • Loading branch information...
ADmad committed Sep 17, 2014
1 parent cca12c5 commit a7b44e5bc1b0586aa2498c7425e9675f316be651
@@ -315,21 +315,37 @@ public function components() {
return $this->_components;
}
/**
* Alias for loadComponent() for backwards compatibility.
*
* @param string $name The name of the component to load.
* @param array $config The config for the component.
* @return \Cake\Controller\Component
* @deprecated 3.0.0 Use loadComponent() instead.
*/
public function addComponent($name, array $config = []) {
trigger_error(
'addComponent() is deprecated, use loadComponent() instead.',
E_USER_DEPRECATED
);
return $this->loadComponent($name, $config);
}
/**
* Add a component to the controller's registry.
*
* This method will also set the component to a property.
* For example:
*
* `$this->addComponent('Acl.Acl');`
* `$this->loadComponent('Acl.Acl');`
*
* Will result in a `Toolbar` property being set.
*
* @param string $name The name of the component to load.
* @param array $config The config for the component.
* @return \Cake\Controller\Component
*/
public function addComponent($name, array $config = []) {
public function loadComponent($name, array $config = []) {
list(, $prop) = pluginSplit($name);
$this->{$prop} = $this->components()->load($name, $config);
return $this->{$prop};
@@ -487,7 +503,7 @@ protected function _loadComponents() {
$registry = $this->components();
$components = $registry->normalizeArray($this->components);
foreach ($components as $properties) {
$this->addComponent($properties['class'], $properties['config']);
$this->loadComponent($properties['class'], $properties['config']);
}
}
@@ -659,7 +675,7 @@ public function paginate($object = null) {
}
}
$this->addComponent('Paginator');
$this->loadComponent('Paginator');
if (
!in_array('Paginator', $this->helpers) &&
!array_key_exists('Paginator', $this->helpers)
@@ -34,7 +34,7 @@ public function __construct($request = null, $response = null) {
if (count(Router::extensions()) &&
!isset($this->RequestHandler)
) {
$this->addComponent('RequestHandler');
$this->loadComponent('RequestHandler');
}
$eventManager = $this->eventManager();
if (isset($this->Auth)) {
@@ -41,7 +41,7 @@ public function setUp() {
array('redirect'),
array(new Request(), new Response())
);
$controller->addComponent('Cookie');
$controller->loadComponent('Cookie');
$this->Controller = $controller;
$this->Cookie = $controller->Cookie;
$this->request = $controller->request;
@@ -130,7 +130,7 @@ public function testSetWithException() {
public function testSetWithComponentConfiguration() {
$this->assertNull($this->Session->read('Flash.flash'));
$this->Controller->addComponent('Flash', ['element' => 'test']);
$this->Controller->loadComponent('Flash', ['element' => 'test']);
$this->Controller->Flash->set('This is a test message');
$expected = [
'message' => 'This is a test message',
@@ -112,7 +112,7 @@ public function testMultipleComponentInitialize() {
*/
public function testSomethingReferencingCookieComponent() {
$Controller = new ComponentTestController();
$Controller->addComponent('SomethingWithCookie');
$Controller->loadComponent('SomethingWithCookie');
$Controller->startupProcess();
$this->assertInstanceOf('TestApp\Controller\Component\SomethingWithCookieComponent', $Controller->SomethingWithCookie);
@@ -339,7 +339,7 @@ public function testConstructClassesWithComponents() {
Plugin::load('TestPlugin');
$Controller = new TestPluginController(new Request(), new Response());
$Controller->addComponent('TestPlugin.Other');
$Controller->loadComponent('TestPlugin.Other');
$this->assertInstanceOf('TestPlugin\Controller\Component\OtherComponent', $Controller->Other);
}
@@ -818,7 +818,7 @@ public function testAddComponent() {
$response = $this->getMock('Cake\Network\Response');
$controller = new TestController($request, $response);
$result = $controller->addComponent('Paginator');
$result = $controller->loadComponent('Paginator');
$this->assertInstanceOf('Cake\Controller\Component\PaginatorComponent', $result);
$this->assertSame($result, $controller->Paginator);

0 comments on commit a7b44e5

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