Re: [SMARTY-DEV] making Smarty_Compiler more flexible
| From: | Monte Ohrt | Date: | Wed, 29 Jan 2003 14:29:22 +0000 |
| Subject: | Re: [SMARTY-DEV] making Smarty_Compiler more flexible | ||
| References: | 1 2 3 4 5 | Groups: | php.smarty.dev |
| Request: | Send a blank email to php-smarty-dev+get-648@lists.php.net to get a copy of this message | ||
Many installations have this disabled, and will be (if not already) the
default setting in php.ini. It is also strongly discouraged, read the
comment in the php.ini file.
Monte
On Wed, 2003-01-29 at 03:14, André Rabold wrote:
> Why?! But I don't think it's really needed. I thought it might be useful in
> some cases.
>
>
> "Monte Ohrt" <monte@ispi.net> schrieb im Newsbeitrag
> news:1043789985.26644.52.camel@lena.ispi.prv...
> > We can't have call-time pass-by-reference in the Smarty library.
> >
> > On Tue, 2003-01-28 at 09:36, André Rabold wrote:
> > > Following changes:
> > > - Smarty_Compiler has a back reference to the calling Smarty class
> called
> > > Smarty_Compiler::$_smarty
> > > - New method Smarty::_load_compiler() which returns a compiler object
> > > - Altered Smarty::_compile_template() to use Smarty::_load_compiler()
> method
> > >
> > > bye,
> > > André
> > >
> > >
> > > ------------------------------------------------
> > >
> > > cvs diff Smarty_Compiler.class.php (in directory
> C:\CVS-Checkout\smarty\)
> > > Index: Smarty_Compiler.class.php
> > > ===================================================================
> > > RCS file: /repository/smarty/Smarty_Compiler.class.php,v
> > > retrieving revision 1.152
> > > diff -r1.152 Smarty_Compiler.class.php
> > > 66a67
> > > > var $_smarty = null; // caller reference
> > > 72c73
> > > < function Smarty_Compiler()
> > > ---
> > > > function Smarty_Compiler(&$smarty)
> > > 181c182,184
> > > < }
> > > ---
> > > > // Remember the caller reference
> > > > $this->_smarty =& $smarty;
> > > > }
> > >
> > >
> > > ------------------------------------------------
> > >
> > > cvs diff Smarty.class.php (in directory C:\CVS-Checkout\smarty\)
> > > Index: Smarty.class.php
> > > ===================================================================
> > > RCS file: /repository/smarty/Smarty.class.php,v
> > > retrieving revision 1.334
> > > diff -r1.334 Smarty.class.php
> > > 1120,1121c1120,1121
> > > < Function: _compile_template()
> > > < Purpose: called to compile the templates
> > > ---
> > > > Function: _load_compiler()
> > > > Input: instantiates the compiler class
> > > 1123c1123
> > > < function _compile_template($tpl_file, $template_source,
> > > &$template_compiled)
> > > ---
> > > > function &_load_compiler()
> > > 1132c1132,1133
> > > < $smarty_compiler = new $this->compiler_class;
> > > ---
> > > > return new $this->compiler_class(&$this);
> > > > }
> > > 1133a1135,1141
> > > >
> /*======================================================================*\
> > > > Function: _compile_template()
> > > > Purpose: called to compile the templates
> > > >
> \*======================================================================*/
> > > > function _compile_template($tpl_file, $template_source,
> > > &$template_compiled)
> > > > {
> > > > $smarty_compiler = $this->_load_compiler();
> > >
> > >
> > >
> > > ------------------------------------------------
> > >
> > >
> > >
> > >
> > > "Monte Ohrt" <monte@ispi.net> schrieb im Newsbeitrag
> > > news:1043766427.26389.28.camel@lena.ispi.prv...
> > > > 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.
> > > >
> > --
> > Monte Ohrt <monte@ispi.net>
> >
--
Monte Ohrt <monte@ispi.net>