I'm still working on my XML based template engine. Now I've stumbled upon a problem.
The way I implemented it is as follows:
PHP Code:
//Handles basic variable replacement etc.
$processor = &new fusion();
//provide datasources (plugins)
$processor->registerDataSource(new datasource1());
$processor->registerDataSource(new datasource2());
//provide filterlibraries (plugins)
$processor->registerFilterSet(new filterset1());
$processor->registerFilterSet(new filterset2());
//variable assignment
$processor->setVar('author', 'fabien'); //etc...
//will call processor object's methods that match 'tagname'_open & 'tagname'_close
$handler = &new fusionhandler($processor);
//will call handler object's start, cdata & end element methods (like HTMLSax for example)
$parser = &new xmlparser($handler);
$parser->parseFile('templates/fusion.xml');
$parser->output();
The problem is that I want to have a bi-directional link between the handler object and the parser object.
So the handler should be able to call methods that correspond to the open and close events of tags
(like $this->processor->title_open($attrs)), while these methods themselves append output to $this->handler->output...
Most of the code works fine, but there's some wierd stuff going on with the processor's properties;
they won't stick after a new open tag event. If I try print_r($this) inside a processor method I can see that the handler
property isn't set, while print_r($processor) in the code above shows it correctly, although *RECURSION* apeared...
I've tried it like this, but I should have known it would get me into trouble once I saw *RECURSION* in a print_r() dump ;)
PHP Code:
class fusionhandler {
function fusionhandler(&$processor) {
$this->setProcessor(&$processor);
}
function setProcessor(&$processor) {
$this->processor = &$processor;
$this->processor->register($this);
}
...
}
class fusion {
...
function register(&$handler) {
$this->handler = &$handler;
}
...
}
- prefab