PATCH: Several enhancements

From: Date: Tue, 17 Dec 2002 12:21:42 +0000
Subject: PATCH: Several enhancements
References: 1  Groups: php.smarty.dev 
Request: Send a blank email to php-smarty-dev+get-426@lists.php.net to get a copy of this message
Hi everybody... Object handling works great now in Smarty thanks to the CVS update yesterday. A few thing didn't work until now so I wrote a patch with offers several enhancements. This is what Smarty can do now: {$foo->bar()} {$foo->bar("blah")} {$foo->bar("blah $my var")} {$foo->bar("blah $my var","blub")} Something more complex: {$foo->foo_it($bar->bar_it("blah"))} {$foo->bar("var1", _MY_CONSTANT, $blah, null, true)} Using modifiers work too: {$foo->foo_it($bar->bar_it("blah"))|@strtoupper} And this is also possible for attributes {fooFunction foo=$foo->bar("var1", _MY_CONSTANT, $blah, null, true)} Hope I've got nothing broke but my own application still works great and because of the latest CVS is even faster than before. Attached you find the changes I made to Smarty_Compiler to get this working. Would be great if these could make it into the official Smarty Compiler ;-) Thoughts? André Index: Smarty_Compiler.class.php =================================================================== RCS file: /repository/smarty/Smarty_Compiler.class.php,v retrieving revision 1.135 diff -r1.135 Smarty_Compiler.class.php 53a54 > var $_var_regexp = '"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"|\'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\'|\w+|\$\w+ (?:(?:\[(?:\$\w+|\w+(?:\.\w+)?)\]|(?:->|\.)\$?\w+(?:\(.*?\))?|^\w+))*'; 228c229 < (?: ' . $this->_qstr_regexp . ' | (?>[^"\'\s]+))+ --- > (?: ' . $this->_var_regexp . ' | (?>[^"\'\s]+))+ 236,240c237,242 < we simply process it. */ < < if (preg_match('!^\$\w+(?>(\[(\d+|\$\w+|\w+(\.\w+)?)\])|((\.|->)\$?\w+(?:\((?:' . $this->_qstr_regexp . ')*\))*))*(?>\|@?\w+(:(?>' . $this->_qstr_regexp . '|[^|]+))*)*$!', $tag_command) || // if a variable < preg_match('!^#(\w+)#(?>\|@?\w+(:(?>' . $this->_qstr_regexp . '|[^|]+))*)*$!', $tag_command) || // or a configuration variable < preg_match('!^%\w+\.\w+%(?>\|@?\w+(:(?>' . $this->_qstr_regexp . '|[^|]+))*)*$!', $tag_command)) { // or a section property --- > we simply process it. */ > > if (preg_match('!^\$\w+(?>(\[(\d+|\$\w+|\w+(\.\w+)?)\])|((\.|->)\$?\w+(?:\(\s*( ?:' . $this->_var_regexp . ')*(?:\s*,\s*(?:'.$this->_var_regexp.')*)*\s*\))*))*(?>\|@?\w+(:(?>' . $this->_qstr_regexp . '|[^|]+))*)*$!', $template_tag) || // if a variable > preg_match('!^#(\w+)#(?>\|@?\w+(:(?>' . $this->_qstr_regexp . '|[^|]+))*)*$!', $template_tag) || // or a configuration variable > preg_match('!^%\w+\.\w+%(?>\|@?\w+(:(?>' . $this->_qstr_regexp . '|[^|]+))*)*$!', $template_tag)) { // or a section property > $tag_command = $template_tag; 1076,1077c1078 < < $var_exprs = preg_grep('!^\$\w+(?>(\[(\d+|\$\w+|\w+(\.\w+)?)\])|((\.|->)\$?\w+(?:\((?:' . $this->_qstr_regexp . ')*\))?))*(?>\|@?\w+(:(?>' . $this->_qstr_regexp . '|[^|]+))*)*$!', $tokens); --- > $var_exprs = preg_grep('!^\$\w+(?>(\[(\d+|\$\w+|\w+(\.\w+)?)\])|((\.|->)\$?\w+(?:\(\s*(?: ' . $this->_var_regexp . ')*(?:\s*,\s*(?:'.$this->_var_regexp.')*)*\s*\))?))*(?>\|@?\w+(:(?>' . $this->_qstr_regexp . '|[^|]+))*)*$!', $tokens); 1081c1082 < --- > 1131,1133c1132,1134 < < preg_match_all('!\[(?:\$\w+|\w+(\.\w+)?)\]|(->|\.)\$?\w+(?:\((?:' . $this->_qstr_regexp . ')*\))?|^\w+!', $var_ref, $match); < --- > > preg_match_all('!\[(?:\$\w+|\w+(\.\w+)?)\]|(->|\.)\$?\w+|\(\s*(?:' . $this->_var_regexp . ')*(?:\s*,\s*(?:'.$this->_var_regexp.')*)*\s*\)|^\w+!', $var_ref, $match); > 1177a1179,1183 > } else if ($index{0} == '(') { > $index = trim(substr($index,1,-1)); > $index = preg_split('!\s*,\s*!',$index); // split into arguments > $this->_parse_vars_props($index); > $output .= "(".implode(", ",$index).")"; "Monte Ohrt" <monte@ispi.net> schrieb im Newsbeitrag news:1040068296.11922.76.camel@lena.ispi.prv... > I committed to CVS, this syntax is now allowed: > > {$foo->bar('blah')} > {include file=$foo->bar('blah')} > {include file=$foo->bar->bar2->bar3->bar4('blah')} > > You can also embed template vars: > > {$foo->bar("you $foo")} > {include file=$foo->bar("this is $my var")} > > Please help test this, it affects many core components. > > Monte > > begin 666 Smarty.diff M26YD97@Z(%-M87)T>5]#;VUP:6QE<BYC;&%S<RYP:' -"CT]/3T]/3T]/3T] M/3T]/3T]/3T]/3T]/3T]/3T]/3T]/3T]/3T]/3T]/3T]/3T]/3T]/3T]/3T] M/3T]/3T]/3T]/3T-"E)#4R!F:6QE.B O<F5P;W-I=&]R>2]S;6%R='DO4VUA M<G1Y7T-O;7!I;&5R+F-L87-S+G!H<"QV#0IR971R:65V:6YG(')E=FES:6]N M(#$N,3,U#0ID:69F("UR,2XQ,S4@4VUA<G1Y7T-O;7!I;&5R+F-L87-S+G!H M< T*-3-A-30-"CX@(" @('9A<B D7W9A<E]R96=E>' @(#T@)R);7B)<7%Q< M72HH/SI<7%Q<+EM>(EQ<7%Q=*BDJ(GQ<)UM>7"=<7%Q<72HH/SI<7%Q<+EM> M7"=<7%Q<72HI*EPG?%QW*WQ<)%QW*R@_.B@_.EQ;*#\Z7"1<=RM\7'<K*#\Z M7"Y<=RLI/RE<77PH/SHM/GQ<+BE<)#]<=RLH/SI<*"XJ/UPI*3]\7EQW*RDI M*B<[#0HR,CAC,C(Y#0H\(" @(" @(" @(" @(" @(" @(" @(" @*#\Z("<@ M+B D=&AI<RT^7W%S=')?<F5G97AP("X@)R!\("@_/EM>(EPG7'-=*RDI*PT* M+2TM#0H^(" @(" @(" @(" @(" @(" @(" @(" @*#\Z("<@+B D=&AI<RT^ M7W9A<E]R96=E>' @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