Skip to content

Commit

Permalink
remove needless _defaultConfig merging
Browse files Browse the repository at this point in the history
The config trait itself does that.

Also replace calls to config() with direct access to _config for
mandatory keys
  • Loading branch information
AD7six committed Mar 29, 2014
1 parent 2430bcd commit 12b281a
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 19 deletions.
7 changes: 2 additions & 5 deletions src/View/Helper.php
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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};
Expand Down
6 changes: 3 additions & 3 deletions src/View/Helper/FormHelper.php
Expand Up @@ -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]);
Expand Down Expand Up @@ -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];

Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/View/Helper/NumberHelper.php
Expand Up @@ -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) {
Expand Down
7 changes: 3 additions & 4 deletions src/View/Helper/PaginatorHelper.php
Expand Up @@ -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));
}

/**
Expand Down Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/View/Helper/TextHelper.php
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/View/Helper/TimeHelper.php
Expand Up @@ -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) {
Expand Down
8 changes: 4 additions & 4 deletions src/View/View.php
Expand Up @@ -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']);
}
}

Expand Down Expand Up @@ -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);
}

/**
Expand Down

0 comments on commit 12b281a

Please sign in to comment.