浏览代码

remove needless _defaultConfig merging

The config trait itself does that.

Also replace calls to config() with direct access to _config for
mandatory keys
AD7six 12 年之前
父节点
当前提交
12b281ac7b

+ 2 - 5
src/View/Helper.php

@@ -150,9 +150,6 @@ class Helper extends Object implements EventListener {
 		$this->_View = $View;
 		$this->request = $View->request;
 
-		if ($config) {
-			$config = Hash::merge($this->_defaultConfig, $config);
-		}
 		$this->config($config);
 
 		if (!empty($this->helpers)) {
@@ -180,8 +177,8 @@ class Helper extends Object implements EventListener {
  */
 	public function __get($name) {
 		if (isset($this->_helperMap[$name]) && !isset($this->{$name})) {
-			$settings = array_merge((array)$this->_helperMap[$name]['settings'], array('enabled' => false));
-			$this->{$name} = $this->_View->addHelper($this->_helperMap[$name]['class'], $settings);
+			$settings = array_merge((array)$this->_helperMap[$name]['config'], array('enabled' => false));
+			$this->{$name} = $this->_View->addHelper($this->_helperMap[$name]['class'], $this->_config);
 		}
 		if (isset($this->{$name})) {
 			return $this->{$name};

+ 3 - 3
src/View/Helper/FormHelper.php

@@ -170,7 +170,7 @@ class FormHelper extends Helper {
  */
 	public function __construct(View $View, $config = []) {
 		parent::__construct($View, $config);
-		$config = $this->config();
+		$config = $this->_config;
 
 		$this->widgetRegistry($config['registry'], $config['widgets']);
 		$this->config(['widgets' => null, 'registry' => null]);
@@ -936,7 +936,7 @@ class FormHelper extends Helper {
 		}
 
 		$internalType = $context->type($fieldName);
-		$map = $this->config('typeMap');
+		$map = $this->_config['typeMap'];
 		$type = isset($map[$internalType]) ? $map[$internalType] : 'text';
 		$fieldName = array_slice(explode('.', $fieldName), -1)[0];
 
@@ -2093,7 +2093,7 @@ class FormHelper extends Helper {
 		unset($options['value'], $options['default']);
 
 		if ($context->hasError($field)) {
-			$options = $this->addClass($options, $this->config('errorClass'));
+			$options = $this->addClass($options, $this->_config['errorClass']);
 		}
 		if (!empty($options['disabled']) || $secure === static::SECURE_SKIP) {
 			return $options;

+ 1 - 1
src/View/Helper/NumberHelper.php

@@ -61,7 +61,7 @@ class NumberHelper extends Helper {
 	public function __construct(View $View, $config = array()) {
 		parent::__construct($View, $config);
 
-		$config = $this->config();
+		$config = $this->_config;
 
 		$engineClass = App::classname($config['engine'], 'Utility');
 		if ($engineClass) {

+ 3 - 4
src/View/Helper/PaginatorHelper.php

@@ -143,7 +143,7 @@ class PaginatorHelper extends Helper {
 			);
 			unset($options[$model]);
 		}
-		$this->_config['options'] = array_filter(array_merge($this->config('options'), $options));
+		$this->_config['options'] = array_filter(array_merge($this->_config['options'], $options));
 	}
 
 /**
@@ -410,9 +410,8 @@ class PaginatorHelper extends Helper {
 			'direction' => $paging['direction'],
 		];
 
-		$defaultUrl = $this->config('options.url');
-		if ($defaultUrl) {
-			$url = array_merge($defaultUrl, $url);
+		if (!empty($this->_config['options']['url'])) {
+			$url = array_merge($this->_config['options']['url'], $url);
 		}
 		$url = array_merge(array_filter($url), $options);
 

+ 1 - 1
src/View/Helper/TextHelper.php

@@ -77,7 +77,7 @@ class TextHelper extends Helper {
 	public function __construct(View $View, $config = array()) {
 		parent::__construct($View, $config);
 
-		$config = $this->config();
+		$config = $this->_config;
 		$engineClass = App::classname($config['engine'], 'Utility');
 		if ($engineClass) {
 			$this->_engine = new $engineClass($config);

+ 1 - 1
src/View/Helper/TimeHelper.php

@@ -65,7 +65,7 @@ class TimeHelper extends Helper {
 	public function __construct(View $View, $config = array()) {
 		parent::__construct($View, $config);
 
-		$config = $this->config();
+		$config = $this->_config;
 
 		$engineClass = App::classname($config['engine'], 'Utility');
 		if ($engineClass) {

+ 4 - 4
src/View/View.php

@@ -813,7 +813,7 @@ class View extends Object {
 		$helpers = $registry->normalizeArray($this->helpers);
 		foreach ($helpers as $properties) {
 			list(, $class) = pluginSplit($properties['class']);
-			$this->{$class} = $registry->load($properties['class'], $properties['settings']);
+			$this->{$class} = $registry->load($properties['class'], $properties['config']);
 		}
 	}
 
@@ -895,12 +895,12 @@ class View extends Object {
  * Loads a helper. Delegates to the `HelperRegistry::load()` to load the helper
  *
  * @param string $helperName Name of the helper to load.
- * @param array $settings Settings for the helper
+ * @param array $config Settings for the helper
  * @return Helper a constructed helper object.
  * @see HelperRegistry::load()
  */
-	public function addHelper($helperName, $settings = []) {
-		return $this->helpers()->load($helperName, $settings);
+	public function addHelper($helperName, $config = []) {
+		return $this->helpers()->load($helperName, $config);
 	}
 
 /**