|
|
@@ -195,9 +195,9 @@ class Controller extends Object implements EventListener {
|
|
|
/**
|
|
|
* Instance of ComponentRegistry used to create Components
|
|
|
*
|
|
|
- * @var ComponentRegistry
|
|
|
+ * @var \Cake\Controller\ComponentRegistry
|
|
|
*/
|
|
|
- public $Components = null;
|
|
|
+ public $_components = null;
|
|
|
|
|
|
/**
|
|
|
* Array containing the names of components this controller uses. Component names
|
|
|
@@ -319,7 +319,29 @@ class Controller extends Object implements EventListener {
|
|
|
if ($response instanceof Response) {
|
|
|
$this->response = $response;
|
|
|
}
|
|
|
- $this->Components = new ComponentRegistry($this);
|
|
|
+ }
|
|
|
+
|
|
|
+/**
|
|
|
+ * Get the component registry for this controller.
|
|
|
+ *
|
|
|
+ * @return \Cake\Controller\ComponentRegistry
|
|
|
+ */
|
|
|
+ public function components() {
|
|
|
+ if ($this->_components === null) {
|
|
|
+ $this->_components = new ComponentRegistry($this);
|
|
|
+ }
|
|
|
+ return $this->_components;
|
|
|
+ }
|
|
|
+
|
|
|
+/**
|
|
|
+ * Add a component to the controller's registry
|
|
|
+ *
|
|
|
+ * @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, $config = []) {
|
|
|
+ return $this->components()->load($name, $config);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -486,10 +508,11 @@ class Controller extends Object implements EventListener {
|
|
|
if (empty($this->components)) {
|
|
|
return;
|
|
|
}
|
|
|
- $components = $this->Components->normalizeArray($this->components);
|
|
|
+ $registry = $this->components();
|
|
|
+ $components = $registry->normalizeArray($this->components);
|
|
|
foreach ($components as $properties) {
|
|
|
list(, $class) = pluginSplit($properties['class']);
|
|
|
- $this->{$class} = $this->Components->load($properties['class'], $properties['settings']);
|
|
|
+ $this->{$class} = $registry->load($properties['class'], $properties['settings']);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -677,7 +700,7 @@ class Controller extends Object implements EventListener {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- $this->Paginator = $this->Components->load('Paginator');
|
|
|
+ $this->Paginator = $this->addComponent('Paginator');
|
|
|
if (
|
|
|
!in_array('Paginator', $this->helpers) &&
|
|
|
!array_key_exists('Paginator', $this->helpers)
|