View previous topic :: View next topic |
Author |
Message |
kimaz Smarty n00b
Joined: 25 Jun 2007 Posts: 2
|
Posted: Mon Jun 25, 2007 11:21 pm Post subject: PHP5 dereferencing support |
|
|
Anyone working with this?
E.g.: {$objectA->getObjectB()->performAction()}
Since dereferencing isn't supported in PHP4 or less it might not seem portable, but i would like Smarty to be able to utilize it if PHP5 is available (or even make a "fake"/manual PHP4 dereferencing support: fetch, call & return).
This, of course, contradicts the ease of use that Smarty presents to the template designers since they will have to know more about the objects then the data passed to them.
OTOH, it may prove useful in larger object clusters where you might have a lot of grouped data associated with one another but still as separate objects.
If there are low/none interest then i might implement support for it. Just need to know if there is anyone else implementing this.
Cheers. |
|
Back to top |
|
CChandler242 Smarty n00b
Joined: 26 Jun 2007 Posts: 2
|
Posted: Tue Jun 26, 2007 10:07 pm Post subject: |
|
|
I wasn't planning on it, but I may have use for it. When will you be done? |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Wed Jun 27, 2007 5:52 am Post subject: |
|
|
I suggest a search of the forums ("method derefrencing" is a good start). Others have already done work on it. A word of note: it is unlikely that this would make it into the 2.x codebase due to its PHP4 heritage/constraints. Not withstanding kimaz's comments, the reasons for it not appearing in the 2.x branch are pretty much covered in historical threads if you care to research it. A word of caution: some of the threads get heated
Best. |
|
Back to top |
|
kimaz Smarty n00b
Joined: 25 Jun 2007 Posts: 2
|
Posted: Wed Jun 27, 2007 10:45 am Post subject: |
|
|
boots wrote: | I suggest a search of the forums ("method derefrencing" is a good start). Others have already done work on it. A word of note: it is unlikely that this would make it into the 2.x codebase due to its PHP4 heritage/constraints. Not withstanding kimaz's comments, the reasons for it not appearing in the 2.x branch are pretty much covered in historical threads if you care to research it. A word of caution: some of the threads get heated
Best. |
Yeah, i did that previously and i agree with you.
Just checking if there were any concrete solutions available or perhaps any prior art to the solution.
Thanks for the heads up.
CChandler242 wrote: |
I wasn't planning on it, but I may have use for it. When will you be done?
|
No date available as of yet.
Im working alot this week. So perhaps by the end of next week is possible.
Cheers.
Edit: currently have'nt had the time to dig into the Smarty codebase. So i might not be able to comply for a while, im afraid. |
|
Back to top |
|
sleenen Smarty n00b
Joined: 20 Jul 2007 Posts: 1
|
Posted: Mon Jul 23, 2007 2:15 pm Post subject: |
|
|
hi guys,
I'd very much like derefrencing to work. Can you help me on 'hacking' this into the compiler. I found the regexp kind of hard to read and change.
line 144-164 of Smarty_Compiler is where I should change this I think (?)
Code: | // matches valid object call (one level of object nesting allowed in parameters):
// $foo->bar
// $foo->bar()
// $foo->bar("text")
// $foo->bar($foo, $bar, "text")
// $foo->bar($foo, "foo")
// $foo->bar->foo()
// $foo->bar->foo->bar()
// $foo->bar($foo->bar)
// $foo->bar($foo->bar())
// $foo->bar($foo->bar($blah,$foo,44,"foo",$foo[0].bar))
$this->_obj_ext_regexp = '\->(?:\$?' . $this->_dvar_guts_regexp . ')';
$this->_obj_restricted_param_regexp = '(?:'
. '(?:' . $this->_var_regexp . '|' . $this->_num_const_regexp . ')(?:' . $this->_obj_ext_regexp . '(?:\((?:(?:' . $this->_var_regexp . '|' . $this->_num_const_regexp . ')'
. '(?:\s*,\s*(?:' . $this->_var_regexp . '|' . $this->_num_const_regexp . '))*)?\))?)*)';
$this->_obj_single_param_regexp = '(?:\w+|' . $this->_obj_restricted_param_regexp . '(?:\s*,\s*(?:(?:\w+|'
. $this->_var_regexp . $this->_obj_restricted_param_regexp . ')))*)';
$this->_obj_params_regexp = '\((?:' . $this->_obj_single_param_regexp
. '(?:\s*,\s*' . $this->_obj_single_param_regexp . ')*)?\)';
$this->_obj_start_regexp = '(?:' . $this->_dvar_regexp . '(?:' . $this->_obj_ext_regexp . ')+)';
$this->_obj_call_regexp = '(?:' . $this->_obj_start_regexp . '(?:' . $this->_obj_params_regexp . ')?(?:' . $this->_dvar_math_regexp . '(?:' . $this->_num_const_regexp . '|' . $this->_dvar_math_var_regexp . ')*)?)'; |
can anyone assist me on getting more than 1 level deep, so I can use {$obj1->getObj2()->getFoo()} ?
Thanks in advance.
kind regards,
Stefan
ps I know I can use {assign}, I also understand very well the discussion of why you shouldn't allow this in the template etc. Please dont make this into that discussion again, since there has been enough of that on the forum already. |
|
Back to top |
|
AnteD Smarty Regular
Joined: 14 Dec 2004 Posts: 38
|
Posted: Wed Nov 28, 2007 8:04 pm Post subject: |
|
|
+1 ... this is for me ONLY smarty's drawback....1 year ago this would be very usefull today I'm almost anoyed with the lack of it.. |
|
Back to top |
|
dnfeitosa Smarty n00b
Joined: 31 Dec 2007 Posts: 2
|
Posted: Mon Dec 31, 2007 3:42 pm Post subject: |
|
|
I found a patch which allows this, but as I'm new here, the forum doesn't allow me make my first post with a link, so this is my first post.
|
|
Back to top |
|
dnfeitosa Smarty n00b
Joined: 31 Dec 2007 Posts: 2
|
|
Back to top |
|
Karamfil Smarty n00b
Joined: 25 Feb 2007 Posts: 4
|
Posted: Fri Mar 28, 2008 3:59 pm Post subject: |
|
|
Here is what i came with
Extend the Smarty class with yours, thus there is no chance somebody will overwrite edited smarty files, becuase you haven't edited them
Code: | /*
* Template.class.php
*/
require_once dirname(__FILE__).'/Smarty.class.php';
class Template extends Smarty
{
public $compiler_file = 'Smarty_Compiler_New.class.php';
public $compiler_class = 'Smarty_Compiler_New';
function __construct()
{
$this->Smarty();
// here you can define all the paths
$views_path = SystemConfig::$viewsPath;
$temp_path = SystemConfig::$tempPath;
$this->template_dir = $views_path;
$this->cache_dir = $views_path . 'configs';
$this->compile_dir = $temp_path . 'tpl_compile';
$this->config_dir = $temp_path . 'tpl_cache';
$this->plugins_dir[] = 'customs';
}
} |
Then extend the SmartyCompiler
Code: | /*
* Smarty_Compiler_New.class.php
*/
require_once dirname(__FILE__).'/Smarty_Compiler.class.php';
class Smarty_Compiler_New extends Smarty_Compiler {
var $_obj_call_regexp = null;
function __construct()
{
$this->Smarty_Compiler();
$this->_obj_call_regexp = '(?:' . $this->_obj_start_regexp . '(?:' . $this->_obj_params_regexp . ''.'(?:' . $this->_obj_ext_regexp . '(?:' . $this->_obj_params_regexp . '|' . $this->_obj_single_param_regexp . '(?:\s*,\s*' . $this->_obj_single_param_regexp . ')*))*' . ')?(?:' . $this->_dvar_math_regexp . '(?:' . $this->_num_const_regexp . '|' . $this->_dvar_math_var_regexp . ')*)?)';
}
} |
After searching and reading for about and hour that it it is failry simple
Hope it works if not please tell me |
|
Back to top |
|
|