[TYPO3-ect] Reminder: where to put fh_library?
Franz Holzinger
franz at fholzinger.com
Mon Jul 30 12:56:12 CEST 2007
Hello Elmar,
> The idea tx_div_all comes to it's limit, if the arguments of functions
> change between alpha and stable.
If the parameters change, then the function must be renamed.
The former function name should be moved into the deprecated class.
>> Use this:
>> class myExtension extends tslib_pibase {
>>
>> $divOjb;
>>
>> $divOjb = &t3lib_div::getUserObj('&myExtensionDiv');
>> ...
>>
>> }
>>
>> So we create a DIV object inside of each pibase extension which will
>> additiionally be globally available to other extensions.
>
> I don't understand the idea. div is not an object. div is not lib.
This has drawbacks. So it is not possible to derive from it and enhance it.
It would be an advantage to have a global div-object available. I wanted
to have a solution with
$divOjb = &t3lib_div::getUserObj('&tx_div_all');
So someone could adapt his div methods for an extension.
The $divObj could be used to have a constant interface.
class tx_div_all {
$tx_divArray;
$useState;
$methodArray;
function init ($useState='stable') {
$this->useState = $useState;
$this->methodArray = array();
$this->tx_divArray = array();
$tx_divArray['stable'] = &t3lib_div::getUserObj('&tx_div');
$tx_divArray['alpha'] = &t3lib_div::getUserObj('&tx_div_alpha');
$tx_divArray['beta'] = &t3lib_div::getUserObj('&tx_div_beta');
$this->methodArray['alpha'] = get_class_methods('tx_div_alpha');
$this->methodArray['beta'] = get_class_methods('tx_div_beta');
}
function func1_v001 ($param1) { // take always the next alpha version
if present
if ($this->useState == 'alpha' && method_exists($this->tx_alpha,
'func1_v001')) {
return $this->tx_div_alpha->func_v001($param1);
} else if ($this->useState != 'stable' && method_exists($this->tx_beta,
'func1_v001')) {
return $this->tx_div_beta->func_v001($param1);
} else return FALSE;
}
// This method finds the highest method from alpha or beta between 2
given version numbers.
function getLatestMethod($version1, $version2, $name) {
$k = array_search ($name.'_'.$version2,
$this->methodArray[$this->useState]);
// take the method with the highes version number starting with
a minimum of $version1 and maximum of version 2
$next = $version2-1;
while ($k === FALSE && $next >= $version1) {
$k = array_search ($name.'_'.$next, $this->methodArray[$this->useState]);
...
return $this->methodArray[$this->useState][$k];
}
function func1 ($version1, $version2, $param1) {
if ($this->useState == 'stable') {
return $this->tx_div->func1($param1);
} else {
$method = $this->getLatestMethod ($version1, $version2, 'func1');
return call_user_func(array( &$tx_divArray[$this->useState], $method
), $param1);
}
}
This can be improved to have only one function for the whole object.
func_get_args will deliver all parameters. The first parameter can be
the method to be called.
This can be used for beta versions of extensions. When the method
finally has arrived in tx_div then it can be called directly.
- Franz
More information about the TYPO3-team-extension-coordination
mailing list