Skip to content

Commit

Permalink
Throwing exception instead notice in loadConfig.
Browse files Browse the repository at this point in the history
  • Loading branch information
jrbasso committed Jan 23, 2011
1 parent 175e008 commit 5b8f680
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 24 deletions.
40 changes: 18 additions & 22 deletions cake/libs/view/helpers/html.php
Expand Up @@ -937,34 +937,30 @@ public function loadConfig($configFile, $path = CONFIGS) {
$reader = $configFile[1];
}
} else {
return trigger_error(__('Cannot load the configuration file. Wrong "configFile" configuration.'), E_USER_NOTICE);
throw new ConfigureException(__('Cannot load the configuration file. Wrong "configFile" configuration.'));
}

$readerClass = Inflector::camelize($reader) . 'Reader';
if (!App::import('Lib', 'config/' . $readerClass)) {
return trigger_error(__('Cannot load the configuration file. Unknown reader.'), E_USER_NOTICE);
throw new ConfigureException(__('Cannot load the configuration file. Unknown reader.'));
}

try {
$readerObj = new $readerClass($path);
$configs = $readerObj->read($file);
if (isset($configs['tags']) && is_array($configs['tags'])) {
$this->_tags = array_merge($this->_tags, $configs['tags']);
}
if (isset($configs['minimizedAttributes']) && is_array($configs['minimizedAttributes'])) {
$this->_minimizedAttributes = array_merge($this->_minimizedAttributes, $configs['minimizedAttributes']);
}
if (isset($configs['docTypes']) && is_array($configs['docTypes'])) {
$this->__docTypes = array_merge($this->__docTypes, $configs['docTypes']);
}
if (isset($configs['attributeFormat'])) {
$this->_attributeFormat = $configs['attributeFormat'];
}
if (isset($configs['minimizedAttributeFormat'])) {
$this->_minimizedAttributeFormat = $configs['minimizedAttributeFormat'];
}
} catch (Exception $e) {
return trigger_error(__('Cannot load the configuration file. Failed to load the file.'), E_USER_NOTICE);
$readerObj = new $readerClass($path);
$configs = $readerObj->read($file);
if (isset($configs['tags']) && is_array($configs['tags'])) {
$this->_tags = array_merge($this->_tags, $configs['tags']);
}
if (isset($configs['minimizedAttributes']) && is_array($configs['minimizedAttributes'])) {
$this->_minimizedAttributes = array_merge($this->_minimizedAttributes, $configs['minimizedAttributes']);
}
if (isset($configs['docTypes']) && is_array($configs['docTypes'])) {
$this->__docTypes = array_merge($this->__docTypes, $configs['docTypes']);
}
if (isset($configs['attributeFormat'])) {
$this->_attributeFormat = $configs['attributeFormat'];
}
if (isset($configs['minimizedAttributeFormat'])) {
$this->_minimizedAttributeFormat = $configs['minimizedAttributeFormat'];
}
return $configs;
}
Expand Down
4 changes: 2 additions & 2 deletions cake/tests/cases/libs/view/helpers/html.test.php
Expand Up @@ -1400,11 +1400,11 @@ public function testLoadConfig() {
$this->assertEqual($result, $expected);
$this->assertEqual($this->Html->getAttribute('_minimizedAttributeFormat'), 'format');

$this->expectError();
$this->expectException('ConfigureException');
$result = $this->Html->loadConfig('wrong_file');
$this->assertFalse($result);

$this->expectError();
$this->expectException('ConfigureException');

This comment has been minimized.

Copy link
@markstory

markstory Jan 25, 2011

Member

This second expectation will probably never be met, as the assertions above throw an exception. Perhaps separate it out into a separate method?

$result = $this->Html->loadConfig(array('htmlhelper_tags', 'wrong_reader'), $path);
$this->assertFalse($result);
}
Expand Down

2 comments on commit 5b8f680

@markstory
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just remembered. Don't forget to update the wiki docs about the new setting :)

@jrbasso
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ow, I forgot the docs, updated now. Thanks to remember.

About the exception, really, the second test is not running, so I changed in another commit. Thanks again.

Please sign in to comment.