cvs: smarty / NEWS /libs/core core.write_compiled_include.php

"Messju Mohr" <[email protected]>
Newsgroups gmane.comp.php.cvs.smarty
Message-ID <cvsmessju1082041569@cvsserver>
messju		Thu Apr 15 11:06:09 2004 EDT

  Modified files:              
    /smarty	NEWS 
    /smarty/libs/core	core.write_compiled_include.php 
  Log:
  made smarty_core_write_compiled_include() php5-aware
  
  if someone knows a better way than patching the source with the
  tokenizer, please stand up!
  
  
  
http://cvs.php.net/diff.php/smarty/NEWS?r1=1.445&r2=1.446&ty=u
Index: smarty/NEWS
diff -u smarty/NEWS:1.445 smarty/NEWS:1.446
--- smarty/NEWS:1.445	Mon Apr 12 08:38:34 2004
+++ smarty/NEWS	Thu Apr 15 11:06:08 2004
@@ -1,3 +1,4 @@
+  - make smarty_core_write_compiled_include() php5-aware (messju)
   - removed unused functionality to load a subset of lines from a file (messju)
   - fix is_secure() should only check if a file is_readable, not if
     the directory where it is in is readable (sagi, messju)
http://cvs.php.net/diff.php/smarty/libs/core/core.write_compiled_include.php?r1=1.8&r2=1.9&ty=u
Index: smarty/libs/core/core.write_compiled_include.php
diff -u smarty/libs/core/core.write_compiled_include.php:1.8 smarty/libs/core/core.write_compiled_include.php:1.9
--- smarty/libs/core/core.write_compiled_include.php:1.8	Sat Oct 11 04:55:53 2003
+++ smarty/libs/core/core.write_compiled_include.php	Thu Apr 15 11:06:09 2004
@@ -35,12 +35,32 @@
 
     $_include_compiled .= $params['plugins_code'];
     $_include_compiled .= "<?php";
+
+    $this_varname = ((double)phpversion() >= 5.0) ? '_smarty' : 'this';
     for ($_i = 0, $_for_max = count($_match_source); $_i < $_for_max; $_i++) {
         $_match =& $_match_source[$_i];
+        $source = $_match[4];
+        if ($this_varname == '_smarty') {
+            /* rename $this to $_smarty in the sourcecode */
+            $tokens = token_get_all('<?php ' . $_match[4]);
+            array_shift($tokens); /* remove the opening <.?.php */
+            for ($i=0, $count = count($tokens); $i < $count; $i++) {
+                if (is_array($tokens[$i])) {
+                    if ($tokens[$i][0] == T_VARIABLE && $tokens[$i][1] == '$this') {
+                        $tokens[$i] = '$' . $this_varname;
+                    } else {
+                        $tokens[$i] = $tokens[$i][1];
+                    }                   
+                }
+            }
+            $source = implode('', $tokens);
+        }
+
+        /* add function to compiled include */
         $_include_compiled .= "
-function _smarty_tplfunc_$_match[2]_$_match[3](&\$this)
+function _smarty_tplfunc_$_match[2]_$_match[3](&\$$this_varname)
 {
-$_match[4]
+$source
 }
 
 ";


-- 
Smarty CVS Mailing List (http://cvs.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.