[Typo3-dev] Library manager instead of globals
dan frost
dan at danfrost.co.uk
Tue Mar 16 11:51:20 CET 2004
Last night I built a library manager to cope with a load of the classes
I'm using. Basically you create a library object in a global:
$GLOBALS['LIBS']['myLib'] = libraryManager::newLibrary('default');
// newLibrary is a simple factor, itself integrated with the library
system..
Then, for each class.somethingorother.php file put:
$GLOBALS['LIBS']['myLib']->addLibraryEntry('libraryKey',
array('class'=>'classname', 'metadata'=>'etc'));
instead or as well as the of the "include once" stuff at the bottom of
source files.
Then, when you want an object:
$myObject = $GLOBALS['LIBS']['myLib']->getLibraryEntryOb('libraryKey');
E.g.:
$cObj = $GLOBALS['LIBS']['myLib']->getLibraryEntryOb('cObj');
This means:
1. you can have a default "object" or register errors when non-existent
objects are created
2. you can have lots of classes supplying the same "class name"
(libraryKey) - so for extensions you can have:
// Core file:
$GLOBALS['LIBS']['myLib']->addLibraryEntry('cObj',
array('class'=>'classname', 'location'=>'core'));
// Extension 1
$GLOBALS['LIBS']['myLib']->addLibraryEntry('cObj',
array('class'=>'classname', 'location'=>'ext1'));
// Extension 2
$GLOBALS['LIBS']['myLib']->addLibraryEntry('cObj',
array('class'=>'classname', 'location'=>'ext2'));
When the class "cObj" (which doesn't actually exist!) is required by the
core you can ask if there are any alternatives providing specific
functions or properties.
The library object can also create "sub libraries" based on, for
example, permissions, user's location.
I think this might be similar to servers...!
dan
More information about the TYPO3-dev
mailing list