Browse Source

Rename View::addHelper() to View::loadHelper().

ADmad 11 years ago
parent
commit
333ffccd2d

+ 1 - 1
src/View/Helper.php

@@ -145,7 +145,7 @@ class Helper implements EventListener {
 	public function __get($name) {
 		if (isset($this->_helperMap[$name]) && !isset($this->{$name})) {
 			$config = ['enabled' => false] + (array)$this->_helperMap[$name]['config'];
-			$this->{$name} = $this->_View->addHelper($this->_helperMap[$name]['class'], $config);
+			$this->{$name} = $this->_View->loadHelper($this->_helperMap[$name]['class'], $config);
 		}
 		if (isset($this->{$name})) {
 			return $this->{$name};

+ 18 - 2
src/View/View.php

@@ -672,7 +672,7 @@ class View {
 		$registry = $this->helpers();
 		$helpers = $registry->normalizeArray($this->helpers);
 		foreach ($helpers as $properties) {
-			$this->addHelper($properties['class'], $properties['config']);
+			$this->loadHelper($properties['class'], $properties['config']);
 		}
 	}
 
@@ -753,6 +753,22 @@ class View {
 	}
 
 /**
+ * Alias for loadHelper() for backwards compatibility.
+ *
+ * @param string $helperName Name of the helper to load.
+ * @param array $config Settings for the helper
+ * @return Helper a constructed helper object.
+ * @deprecated 3.0.0 Use loadHelper() instead.
+ */
+	public function addHelper($helperName, array $config = []) {
+		trigger_error(
+			'addHelper() is deprecated, use loadHelper() instead.',
+			E_USER_DEPRECATED
+		);
+		return $this->loadHelper($helperName, $config);
+	}
+
+/**
  * Loads a helper. Delegates to the `HelperRegistry::load()` to load the helper
  *
  * @param string $helperName Name of the helper to load.
@@ -760,7 +776,7 @@ class View {
  * @return Helper a constructed helper object.
  * @see HelperRegistry::load()
  */
-	public function addHelper($helperName, array $config = []) {
+	public function loadHelper($helperName, array $config = []) {
 		list(, $class) = pluginSplit($helperName);
 		return $this->{$class} = $this->helpers()->load($helperName, $config);
 	}

+ 3 - 3
tests/TestCase/View/ViewTest.php

@@ -906,14 +906,14 @@ class ViewTest extends TestCase {
 	}
 
 /**
- * Test loading helper using addHelper().
+ * Test loading helper using loadHelper().
  *
  * @return void
  */
-	public function testAddHelper() {
+	public function testLoadHelper() {
 		$View = new View();
 
-		$View->addHelper('Html', ['foo' => 'bar']);
+		$View->loadHelper('Html', ['foo' => 'bar']);
 		$this->assertInstanceOf('Cake\View\Helper\HtmlHelper', $View->Html);
 
 		$config = $View->Html->config();

+ 1 - 1
tests/test_app/TestApp/Template/Layout/default.ctp

@@ -1,5 +1,5 @@
 <?php
-$this->addHelper('Html');
+$this->loadHelper('Html');
 
 $cakeDescription = 'CakePHP: the rapid development php framework';
 ?>