cvs: smarty /libs Smarty_Compiler.class.php

"Messju Mohr" <[email protected]>
Newsgroups gmane.comp.php.cvs.smarty
Message-ID <cvsmessju1093292479@cvsserver>
messju		Mon Aug 23 16:21:19 2004 EDT

  Modified files:              
    /smarty/libs	Smarty_Compiler.class.php 
  Log:
  cleaned up attribute-handling in Smarty_Compiler::_compile_foreach_start()
  
  
  
http://cvs.php.net/diff.php/smarty/libs/Smarty_Compiler.class.php?r1=1.331&r2=1.332&ty=u
Index: smarty/libs/Smarty_Compiler.class.php
diff -u smarty/libs/Smarty_Compiler.class.php:1.331 smarty/libs/Smarty_Compiler.class.php:1.332
--- smarty/libs/Smarty_Compiler.class.php:1.331	Fri Aug 13 09:32:27 2004
+++ smarty/libs/Smarty_Compiler.class.php	Mon Aug 23 16:21:19 2004
@@ -26,7 +26,7 @@
  * @package Smarty
  */
 
-/* $Id: Smarty_Compiler.class.php,v 1.331 2004/08/13 13:32:27 messju Exp $ */
+/* $Id: Smarty_Compiler.class.php,v 1.332 2004/08/23 20:21:19 messju Exp $ */
 
 /**
  * Template compiling class
@@ -1122,46 +1122,39 @@
         $arg_list = array();
 
         if (empty($attrs['from'])) {
-            $this->_syntax_error("foreach: missing 'from' attribute", E_USER_ERROR, __FILE__, __LINE__);
+            return $this->_syntax_error("foreach: missing 'from' attribute", E_USER_ERROR, __FILE__, __LINE__);
         }
         $from = $attrs['from'];
 
         if (empty($attrs['item'])) {
-            $this->_syntax_error("foreach: missing 'item' attribute", E_USER_ERROR, __FILE__, __LINE__);
+            return $this->_syntax_error("foreach: missing 'item' attribute", E_USER_ERROR, __FILE__, __LINE__);
         }
         $item = $this->_dequote($attrs['item']);
         if (!preg_match('!^\w+$!', $item)) {
-            $this->_syntax_error("'foreach: item' must be a variable name (literal string)", E_USER_ERROR, __FILE__, __LINE__);
+            return $this->_syntax_error("'foreach: item' must be a variable name (literal string)", E_USER_ERROR, __FILE__, __LINE__);
         }
 
-        if (isset($attrs['name']))
-            $name = $attrs['name'];
-
-        $output = '<?php ';
-        if (isset($name)) {
-            $output .= "if (isset(\$this->_foreach[$name])) unset(\$this->_foreach[$name]);\n";
-            $foreach_props = "\$this->_foreach[$name]";
+        if (isset($attrs['key'])) {
+            $key  = $this->_dequote($attrs['key']);
+            if (!preg_match('!^\w+$!', $key)) {
+                return $this->_syntax_error("foreach: 'key' must to be a variable name (literal string)", E_USER_ERROR, __FILE__, __LINE__);
+            }
+            $key_part = "\$this->_tpl_vars['$key'] => ";
+        } else {
+            $key = null;
+            $key_part = '';
         }
 
-        $key_part = '';
-
-        foreach ($attrs as $attr_name => $attr_value) {
-            switch ($attr_name) {
-                case 'key':
-                    $key  = $this->_dequote($attrs['key']);
-                    if (!preg_match('!^\w+$!', $key)) {
-                        $this->_syntax_error("foreach: 'key' must to be a variable name (literal string)", E_USER_ERROR, __FILE__, __LINE__);
-                    }
-                    $key_part = "\$this->_tpl_vars['$key'] => ";
-                    break;
-
-                case 'name':
-                    $output .= "{$foreach_props}['$attr_name'] = $attr_value;\n";
-                    break;
-            }
+        if (isset($attrs['name'])) {
+            $name = $attrs['name'];
+        } else {
+            $name = null;
         }
 
+        $output = '<?php ';
         if (isset($name)) {
+            $foreach_props = "\$this->_foreach[$name]";
+            $output .= "if (isset(\$this->_foreach[$name])) unset(\$this->_foreach[$name]);\n";
             $output .= "{$foreach_props}['total'] = count(\$_from = (array)$from);\n";
             $output .= "{$foreach_props}['show'] = {$foreach_props}['total'] > 0;\n";
             $output .= "if ({$foreach_props}['show']):\n";

-- 
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.