[TYPO3-ect] Hippie loader

Elmar Hinz elmar.DOT.hinz at team.MINUS.red.DOT.net
Mon Mar 27 17:13:25 CEST 2006


Hello typoniks,

my good old emacs provides me with a pretty function that tries a
bunch of different rules to expand the beginning of a word to
something usefull. It's called hippie-expand.

With a similar idea I write some functions that try to guess an
extension key or a load and instanciate a class from a minimum of
given informations.

I do this because we still don't have a strict scheme how class files
are named. But there are some patterns that are often used.

This is a snippet of javadoc how a extKey is guessed from information:

     * 1.) A KEY itself is tried.
     *     Example: my_extension
     * 2.) A classname of the pattern tx_KEY_something_else is tried.
     *     Example: tx_myextension_view
     * 3.) A full classname of the pattern ' *
tx_KEY_something_else.php' is tried.
     *     Example: class.tx_myextension_view.php
     *     Example: brokenPath/class.tx_myextension_view.php
     * 4.) A path that starts with the KEY is tried.
     *     Example: my_extension/class.view.php

With this most classes can be loaded with a few bits of information:

tx_div::loadClass('tx_myextension_view');
tx_div::loadClass('my_extension/class.view.php');

But the mayor use of this is for cases like:

$view = tx_div::makeInstance('tx_myextension_view');

It includes autoloading, even for PHP4.

Please consider, that there is some danger in doing this, because you
can't be 100% sure which files will be included. Only use it the
hardcoded way, where you can check the results. Never pass user input
to the function.

Regards

Elmar













More information about the TYPO3-team-extension-coordination mailing list