[TYPO3-dev] XCLASS conflict examples

Bernhard Kraft kraftb at kraftb.at
Sun Feb 12 13:02:52 CET 2006


Elmar Hinz wrote:
> If we have one action controller that contains a switch-case construct it is
> difficult to extend by 2 differnet extensions, that both want to add new
> actions. They get into conflicts by extending the same controller function.
> That's the same for hooks, services, XCLASS. It doesn't depend on the
> technology. It depends on the style of coding.

With hooks and services you have the possibiilty to let more than one extension decide
what to do or even combine their functionality easily.

If you look at the pre or post Process hooks in t3lib_tcemain you will notice that each of
the called hooks can perform some action on the fields to process. Of course if two extensions
do different things with the same field you will get problems.

Also you could look at the hook(s) in t3lib_matchcondition. There also all hook methods will
get called until one decides it is clever enough to give a result.

How and if the return values of the hooks are concerned (if further hooks shall get called) depends
on each single implementation and is choosen by the author who implements the hook into the core
files very well (because they have to know what the method does and how it's functionality can get
changed)


> One step further you could even use one class for each action.
> 
> function main(....){
>  [...]
>  if ($obj = $this->getControllerObject($action)) ){
>   $out = $obj->main(....);
>  } else {		
>   $out =  $this->error404();
>  }
>  [...]
>  return $out;
> }


And your getControllerObject would do something like:

foreach ($this->objs as $idx => $obj) {
   if is_method($obj, $action) {
     return $this->objs[$idx];
   }
}

And you will call every method of the class via:

$class->main('callThisMethod', $param1, $param2, ...)

or write wrappers with code like yours but with $action set to a fixed value into every actual
method so backwards compatibility doesn't break.

So you will have something like
function typolink($conf) {
   $link = '';
   $this->getControllerObject('typolink')
   do {
     if ($obj = $this->getControllerNextObject()) ){
       $out = $obj->typolink(....);
     }
   }
}

And if you look for such a pattern in OO books you will find that it is called "decorator" pattern or
some other similar names.

The backdraw of such an construct is that it consumes time evertime it is executed. It is some kind
of overhead.

An hook is more or less somehow a decorated method but not the whole method is decorated only special
parts of it. And everbody knows that also hooks decrease performance altough only minimal if they are
not set. (Just one if statement and an array lookup)


greets,
Bernhard




More information about the TYPO3-dev mailing list