random patches against smarty-1.4.4

From: Date: Thu, 19 Jul 2001 11:15:21 +0000
Subject: random patches against smarty-1.4.4
Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-1197@lists.php.net to get a copy of this message
Hi there, playing with 1.4.4, there are some things that I think deserve improving. Patches (diff -u) below. But first, couple of ideas: 1) How about changing the default location of Smarty::compile_dir and Smarty::config_dir. I always felt like three dirs in every directory of an application is too much clobber. What about st. like this? ./templates/ ./templates/compiled/ ./templates/configs/ 2) 1.3.2 didn't bug me with missing Smarty::config_dir (i. e. when the directory didn't actually exist). 1.4.4 does. Is this by design? I looked at the code, and I must admit I don't quite understand it. I got rid of the error message by commenting out this block from Smarty::fetch(), but it serves a purpose there. if ($this->_conf_obj === null) { /* Prepare the configuration object. */ if (!class_exists('Config_File')) include_once 'Config_File.class.php'; $this->_conf_obj = new Config_File($this->config_dir); } else $this->_conf_obj->set_path($this->config_dir); 3) Nevertheless, would it be possible to defer the instantiation into the compiled template _if_ the template contains {config_load}, and not instantiate the Config_file class at all otherwise? That would probably mean the logic would move from Smarty::fetch() into Smarty_compiler::somewhere(), but I'm not really sure. 4) Next, if you have several applications which use Smarty with different configurations, you have to either a) copy the class around and change Smarty.class.php, b) change the config in each PHP script, or c) write yourself a wrapper that'll do b). Would it be desirable to implement a kind of config files for Smarty itself? I was thinking about st. like this: require 'Smarty.class.php'; $smarty = new Smarty; $smarty->loadConfig('./smarty.ini'); After all, the parser is there. :) Now for the patches: 1) Smarty.class.php.1 fixes a notice in _assign_smarty_interface() triggered by undefined EGPCS arrays. 2) Smarty.class.php.2 somewhat simplifies _assign_smarty_interface(). 3) Smarty.class.php.3 changes _assign_smarty_interface() so that it uses Smarty::undefined for $HTTP_*_VARS arrays spcified in Smarty::request_vars_order but not set. But it can be easily modified for any behavior: function _assign_smarty_interface() { $egpcs = array('e' => 'env', 'g' => 'get', 'p' => 'post', 'c' => 'cookie', 's' => 'server'); $globals = array('env' => 'HTTP_ENV_VARS', 'get' => 'HTTP_GET_VARS', 'post' => 'HTTP_POST_VARS', 'cookie' => 'HTTP_COOKIE_VARS', 'server' => 'HTTP_SERVER_VARS', 'session' => 'HTTP_SESSION_VARS'); $smarty = array('request' => array()); foreach ($globals as $key => $arr) { $smarty[$key] = isset($GLOBALS[$arr]) ? $GLOBALS[$arr] : $this->undefined ; } foreach (preg_split('!!', strtolower($this->request_vars_order)) as $c) { if(isset($egpcs[$c])) { $arr = $globals[$egpcs[$c]]; $smarty['request'] = array_merge($smarty['request'], isset($GLOBALS[$arr]) ? $GLOBALS[$arr] : $this->undefined); } } $this->assign('smarty', $smarty); } 4) Smarty_Compiler.class.php.1 cleans up some notices issued across Smarty_Compiler.class.php. There are others, and I hope to get around to fixing more during weekend. HTH

Attachment: [application/octet-stream] Smarty.class.php.1
Attachment: [application/octet-stream] Smarty.class.php.2
Attachment: [application/octet-stream] Smarty.class.php.3
Attachment: [application/octet-stream] Smarty_Compiler.class.php.1
« previous php.smarty.general (#1197) next »