From 12b281ac7bc678454c0e9d2e1f3a0c2055d02792 Mon Sep 17 00:00:00 2001 From: AD7six Date: Sat, 29 Mar 2014 22:04:09 +0000 Subject: [PATCH] remove needless _defaultConfig merging The config trait itself does that. Also replace calls to config() with direct access to _config for mandatory keys --- src/View/Helper.php | 7 ++----- src/View/Helper/FormHelper.php | 6 +++--- src/View/Helper/NumberHelper.php | 2 +- src/View/Helper/PaginatorHelper.php | 7 +++---- src/View/Helper/TextHelper.php | 2 +- src/View/Helper/TimeHelper.php | 2 +- src/View/View.php | 8 ++++---- 7 files changed, 15 insertions(+), 19 deletions(-) diff --git a/src/View/Helper.php b/src/View/Helper.php index 2b7e690f01d..005a51fa1bd 100644 --- a/src/View/Helper.php +++ b/src/View/Helper.php @@ -150,9 +150,6 @@ public function __construct(View $View, $config = array()) { $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 @@ public function __call($method, $params) { */ 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}; diff --git a/src/View/Helper/FormHelper.php b/src/View/Helper/FormHelper.php index d79452c81f5..441e2ccee6c 100755 --- a/src/View/Helper/FormHelper.php +++ b/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 @@ protected function _inputType($fieldName, $options) { } $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 @@ protected function _initInputField($field, $options = []) { 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; diff --git a/src/View/Helper/NumberHelper.php b/src/View/Helper/NumberHelper.php index 2edc77cbee2..79132cef860 100644 --- a/src/View/Helper/NumberHelper.php +++ b/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) { diff --git a/src/View/Helper/PaginatorHelper.php b/src/View/Helper/PaginatorHelper.php index 72fa3f9aab4..51d2f254c99 100644 --- a/src/View/Helper/PaginatorHelper.php +++ b/src/View/Helper/PaginatorHelper.php @@ -143,7 +143,7 @@ public function options($options = array()) { ); 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 @@ public function url($options = array(), $model = null) { '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); diff --git a/src/View/Helper/TextHelper.php b/src/View/Helper/TextHelper.php index 79ad1220bbe..521fd96ace7 100644 --- a/src/View/Helper/TextHelper.php +++ b/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); diff --git a/src/View/Helper/TimeHelper.php b/src/View/Helper/TimeHelper.php index a274294b9af..1b33f6bd06c 100644 --- a/src/View/Helper/TimeHelper.php +++ b/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) { diff --git a/src/View/View.php b/src/View/View.php index 7b7e93584cc..e0a5343a8c7 100644 --- a/src/View/View.php +++ b/src/View/View.php @@ -813,7 +813,7 @@ public function loadHelpers() { $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 @@ public function helpers() { * 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); } /**