[TYPO3-dev] XCLASS conflict examples

Michael Scharkow mscharkow at gmx.net
Sun Feb 12 13:27:21 CET 2006


Bernhard Kraft wrote:

> 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.

Bernard, you can my cited proposal in 
http://www.underused.org/code/a-simple-controller-class-for-typo3/


> 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.

In my prototype there is a little more magic going on because you really 
only add methods by subclassing the controller and registering the method:

class tt_news_pi1 extends fe_controller{
	$this->register = array('index','singleview','latest','search');
	function index(){
		return 'foo';
	}
	function singleview(){
		return 'bar';
	}
	...
}

myplugin = new tt_news_pi1;
myplugin->main();

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

Actually, the overhead is minimal because (ignoring filters) you only 
lookup a dictionary key (in $this->register) and do a cheap 
method_exists call. So it scales O(1).

A comparable switch statement will probably not be much faster.

> 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)

The above *is* practically also using hooks internally.

However, for the XCLASS problem the difficulty remains to create 
cascading subclassing, so

foo extends bar
foo2 extends bar, but should really extend foo
etc.

We basically need a class merge (or mixins) which is impossible with PHP 
except using eval() which is not an option.

One possible hook-like way would be to not subclass a real class but an 
alias that is filled by TYPO3:

class my_news extends $latest_tt_news_class {
}

However, this is fairly complex and much harder to implement than a 
simple hook that only modifies some local variable.

Cheers,
Michael




More information about the TYPO3-dev mailing list