[TYPO3-ect] PEAR compatible keynames
Joerg Schoppet
joerg at schoppet.de
Wed Mar 22 13:03:11 CET 2006
Elmar Hinz Wrote:
> Elmar Hinz schrieb:
> > 2.) We can then use autoloading:
> >
>
I played a while with the __autoload function of php and implemented it in my own extensions. These extensions are not public, so I've no problem at the moment with problems to other exts.
The first thing I made was defining th coding guideline, that an ext-key has no underscrore, to my subworkers.
Then I implemented the function in a library-ext. So the only thing I have to include in every ext is one file.
The function looks like this:
function __autoload($sClassName) {
if (substr($sClassName, 0, 3) == 'tx_') {
$aParts = explode ('_', $sClassName);
if (t3lib_extMgm::isLoaded($aParts[1])) {
$sExtPath = t3lib_extMgm::extPath($aParts[1]);
if (is_dir($sExtPath)) {
for ($i = 2; $i < count($aParts); $i++) {
$sSpecialPath = $sExtPath . $aParts[$i] . '/';
if (!is_dir($sSpecialPath)) {
break;
} else {
$sExtPath = $sSpecialPath;
} // if (!is_dir($sSpecialPath))
} // for ($i = 2; i < count($aParts); $i++)
if (is_file($sExtPath . 'class.' . $sClassName . '.php')) {
require_once $sExtPath . 'class.' . $sClassName . '.php';
} else {
die ('The file ' . $sExtPath . 'class.' . $sClassName . '.php does not exists');
} // if (is_file($sExtPath . 'class.' . $sClassName . '.php'))
} else {
die ('The directory ' . $sExtPath . ' does not exists');
} // if (is_dir($sExtPath))
} else {
die ('The extension ' . $aParts[1] . ' is not loaded');
} // if (t3lib_extMgm::isLoaded($aParts[1]))
} elseif (substr($sClassName, 0, 3) == 'ux_') {
} elseif (substr($sClassName, 0, 5) == 't3lib' || substr($sClassName, 0, 5) == 'tslib') {
} else {
t3lib_div::debug(debug_backtrace());
die ($sClassName . ' could not be autoloaded');
} // if (substr($sClassName, 0, 3) == 'tx_')
}
I really know that this implementation is very specific to my needs and would need a lot of improvement to have a general acceptation, but it is a beginning ;-)
usage:
extkey: myexample
directory and files
- myexample
- pi1
- tx_myexample_pi1.php (classname: tx_myexample_pi1)
- domain
-tx_myexample_domain_article.php (classname: tx_myexample_domain_article)
And so on.
Regards
Joerg
More information about the TYPO3-team-extension-coordination
mailing list