Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

PHP5 dereferencing support

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Feature Requests
View previous topic :: View next topic  
Author Message
kimaz
Smarty n00b


Joined: 25 Jun 2007
Posts: 2

PostPosted: Mon Jun 25, 2007 11:21 pm    Post subject: PHP5 dereferencing support Reply with quote

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
View user's profile Send private message
CChandler242
Smarty n00b


Joined: 26 Jun 2007
Posts: 2

PostPosted: Tue Jun 26, 2007 10:07 pm    Post subject: Reply with quote

I wasn't planning on it, but I may have use for it. When will you be done?
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Wed Jun 27, 2007 5:52 am    Post subject: Reply with quote

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 Wink

Best.
Back to top
View user's profile Send private message
kimaz
Smarty n00b


Joined: 25 Jun 2007
Posts: 2

PostPosted: Wed Jun 27, 2007 10:45 am    Post subject: Reply with quote

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 Wink

Best.


Yeah, i did that previously and i agree with you. Smile
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. Sad
Back to top
View user's profile Send private message
sleenen
Smarty n00b


Joined: 20 Jul 2007
Posts: 1

PostPosted: Mon Jul 23, 2007 2:15 pm    Post subject: Reply with quote

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
View user's profile Send private message
AnteD
Smarty Regular


Joined: 14 Dec 2004
Posts: 38

PostPosted: Wed Nov 28, 2007 8:04 pm    Post subject: Reply with quote

+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
View user's profile Send private message
dnfeitosa
Smarty n00b


Joined: 31 Dec 2007
Posts: 2

PostPosted: Mon Dec 31, 2007 3:42 pm    Post subject: Reply with quote

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.

Smile
Back to top
View user's profile Send private message
dnfeitosa
Smarty n00b


Joined: 31 Dec 2007
Posts: 2

PostPosted: Mon Dec 31, 2007 3:43 pm    Post subject: Reply with quote

There's a patch to allow this at:

http://codepoets.co.uk/smarty_chained_function_calls
Back to top
View user's profile Send private message
Karamfil
Smarty n00b


Joined: 25 Feb 2007
Posts: 4

PostPosted: Fri Mar 28, 2008 3:59 pm    Post subject: Reply with quote

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 Wink

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 Wink it is failry simple

Hope it works if not please tell me Smile
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Feature Requests All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP