[TYPO3-ect]  div/lib extensions
    Ernesto Baschny [cron IT] 
    ernst at cron-it.de
       
    Tue May  2 11:28:29 CEST 2006
    
    
  
Hi Elmar and Elmar-fans,
In my current project, I'm starting to use the proposed div/lib
extensions. Here are my first impressions and suggestions:
They currently only work on PHP5, but the changes needed to make it work
also on PHP4 are very small (and I did it, because I need my extension
working on PHP4):
1) change "self::" with "<classname>::", as "self" is not known. In this
particular cases it shouldn't matter (1x in div/class.tx_div.php and 3x
in lib/class.tx_lib_t3Loader.php).
2) remove the "private function v", as "private" is not known in PHP4.
These functions seems not to be used anyway.
Other than that I needed an easy way of generating singletons of some of
my classes. The easiest and most generic method I found is the one
described in [1]: a helper class. It would be cool to have such a helper
as tx_div::getSingleton($className) which could also use the fancy
"class finder" routines (load et all). Something like:
    /**
     * Static method to get a singleton
     *
     * @param   string  classname 'tx_key_path_file'
     * @param   mixed   loadertype 't3', 'pear', 'classPear', 'hippie'
resp. 2, 3, 6, 9, 68
     * @return  object  the instance else FALSE
     */
    function getSingleton($className, $type = 3) {
        static $instances = array();  // array of instance names
        $className = str_tolower($className);
        if (!array_key_exists($className, $instances)) {
            // instance does not exist, so create it
            $instances[$class] =& tx_div::makeInstance($class, $type);
        }
        $instance =& $instances[$class];
        return $instance;
    }
And while I am not a 100%-fan of the TYPO3 coding style, it would be
nice to use it in these extensions to set an example. In this case,
indenting with a TAB, using TABs before opening "{" and using phpdoc
comments like in TYPO3-core (@params instead of @par). Maybe others, but
those are the ones that I first noticed.
Cheers,
Ernesto
[1]
http://www.developertutorials.com/tutorials/php/php-singleton-design-pattern-050729/page4.html
    
    
More information about the TYPO3-team-extension-coordination
mailing list