[TYPO3-mvc] Alternative to hooks
Sebastian Fischer
sf at marketing-factory.de
Wed Jan 5 15:12:53 CET 2011
On 05.01.2011 14:24, Pascal Jungblut wrote:
> Hi guys,
>
> I was wondering that now, having a nice and clean Framework to develop extensions, we'd eventually migrate from hooks to something that is more object-oriented. Don't get me wrong. Hooks work and they're very simple to use. However, I think every time you put a function-name concatenated with a filename into a global array that gets called by call_user_func.. a little kitten dies.
>
> For example there is this great thing called Chain Of Responsibility [1] which is an OOP design-pattern that can, slightly modified, achieve pretty much the same as hooks do. Extbase could hold a class that manages these chains and provide basic interfaces to implement the pattern. If you guys have another good method to do this I'd like to hear it, but hooks always make me shiver - so I'm searching for a different approach. What do you think?
>
> Regards
> Pascal
>
> [1]<https://secure.wikimedia.org/wikipedia/en/wiki/Chain-of-responsibility_pattern>
Well chain of responsibility is nice, yeah you got it here comes the
but. Somehow you need to register your own command object and then again
we are somewhere in an global array.
Beside having function names in a string with filenames you could use a
another approach that is used by tt_news too.
if
(is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['tt_news']['extraItemMarkerHook']))
{
foreach($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['tt_news']['extraItemMarkerHook'] as $_classRef) {
$_procObj = & t3lib_div::getUserObj($_classRef);
if (method_exists($_procObj, 'extraItemMarkerProcessor')) {
$markerArray = $_procObj->extraItemMarkerProcessor($markerArray,
$row, $lConf, $this);
}
}
}
By this you only register the class and in the hook a certain method
needs be implemented. This way you have no combination of function and
filename.
Greetings
Sebastian
More information about the TYPO3-project-typo3v4mvc
mailing list