Code: Select all
function __construct($options)
{
$this->_options = &$options;
// Get the default group and caching
if (isset($options['language'])) {
$this->_options['language'] = $options['language'];
} else {
$options['language'] = 'en-GB';
}
if (isset($options['cachebase'])) {
$this->_options['cachebase'] = $options['cachebase'];
} else {
$this->_options['cachebase'] = JPATH_ROOT.DS.'cache';
}
if (isset($options['defaultgroup'])) {
$this->_options['defaultgroup'] = $options['defaultgroup'];
} else {
$this->_options['defaultgroup'] = 'default';
}
if (isset($options['caching'])) {
$this->_options['caching'] = $options['caching'];
} else {
$this->_options['caching'] = true;
}
if (isset($options['storage'])) {
$this->_options['storage'] = $options['storage'];
} else {
$this->_options['storage'] = 'file';
}
//Fix to detect if template positions are enabled...
if (JRequest::getCMD('tpl',0)) {
$this->_options['caching'] = false;
}
}
Code: Select all
function __construct($options)
{
$this->_options = array(
'language'=>'en-GB',
'cachebase'=>JPATH_ROOT.DS.'cache',
'defaultgroup'=>'default',
'caching'=>true,
'storage'=>'file');
//Overwrite default options with given options
$this->_options = array_merge($this->_options,$options);
//or with the ampersand "...& $options);" for speed if array_merge or this construct would make a deep copy otherwise
//Fix to detect if template positions are enabled...
if (JRequest::getCMD('tpl',0)) {
$this->_options['caching'] = false;
}
}
- It generates far less php code.
- It is much faster.
- It allows quick and easy addition of future parameteres to developers
I also propose...
- ..to use this technique wherever this kind of constructor occurs in the joomla library (with array that sets options or similar).
- ..to make a function in JObject (e.g. setOptions(..)) to handle this (for even more improvement)
- ..to alter a lot of other joomla library objects to be written as thus (in stead of the old method e.g. function something(opt1, opt2, opt3))(and even more )
What do you thinks guys?