Re: [SMARTY-DEV] making Smarty_Compiler more flexible
| From: | Monte Ohrt | Date: | Tue, 28 Jan 2003 15:07:08 +0000 |
| Subject: | Re: [SMARTY-DEV] making Smarty_Compiler more flexible | ||
| References: | 1 | Groups: | php.smarty.dev |
| Request: | Send a blank email to php-smarty-dev+get-642@lists.php.net to get a copy of this message | ||
On Tue, 2003-01-28 at 04:32, André Rabold wrote:
> Hi,
>
> Some using some advanced features I need to make Smarty_Compiler more
> flexible.
> Here a some feature request:
>
> 1) Smarty::$compiler_class can be set to anything I like but Smarty tries to
> load it from SMARTY_DIR with extension ".class.php". That's not really a
> good solution I think. I would first try to check if the compiler class does
> not already exists. So the programmer could include his own class manually.
I think this has come up before, I'm not sure why it was done this way.
It might be that the $compiler_class variable is used for both the
filename and the class name, so with one variable it can know what file
to load and what class to reference. We could introduce a new variable
with the full pathname/filename.
>
> Line 1125:
> if (!class_exists($this->compiler_class))
> include_once SMARTY_DIR.$this->compiler_class . '.class.php';
>
> 2) function _compile_template is not flexible enough. I needed to set some
> more variables of the compiler class which is not possible easily. You need
> to copy past the whole function to your own Smarty class. Perhaps you could
> consider instantiating the Compiler in another function
>
> Smarty.class.php:
> function _load_compiler() {
> if (!class_exists($this->compiler_class))
> include_once SMARTY_DIR.$this->compiler_class . '.class.php';
> $this->_compiler = new $this->compiler_class;
> }
>
> This way a programmer could override the default _compile_template method
> this way:
>
> MySmarty.class.php:
> function _compile_template (...) {
> parent::_compile_template(...);
> $this->_compiler->foo = $bar;
> }
>
> 3) Perhaps a back-reference in the compiler class to the calling Smarty
> class whould also be useful. Perhaps you could give the current object to
> the compiler as parameter:
>
> Smarty.class.php:
> function _load_compiler() {
> if (!class_exists($this->compiler_class))
> include_once SMARTY_DIR.$this->compiler_class . '.class.php';
> $this->_compiler = new $this->compiler_class ($this); // <-------- HERE!!!
> }
>
> This could make things even more flexible.
These changes look fine to me, go ahead and submit the patches directly
to me.