Re: [SMARTY] Smarty-Light

From: Date: Thu, 15 Jul 2004 00:45:30 +0000
Subject: Re: [SMARTY] Smarty-Light
References: 1 2 3  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-11596@lists.php.net to get a copy of this message
// call a static method to check for cached exemplars: $cache = SmartyBase::checkIfTemplateIsCached("nameOfTemplate");
i would hate it. ;o) A solution could be to delegate the responsability of creating the cache, compilation to another object. The idea behind is to hide/enpasulate as most as possible. The user shouldn't care, wheter the template is loaded from cache, is compiled, ... . I took a look on the source of Smarty.class.php and it's quiet hard to understand, even with phpdoc. Some functions (ie. Smarty->fetch with ~ 200 lines) seem to tangled to me. But actually i'm not a smarty code developer and such a core-redesign would cost a lot of time, manpower and testing. And i don't think the core-team is very interessted to redesign the hole in the near future. ;o) so ... g9 Thorsten Suckow-Homberg wrote:
Theoretically you could now split the big bunch of smarty code into two pieces. One lightweight caching module, and the other big, but flexible, smarty parser, compiler, ... . So only if no cached template is found, the parser would be loaded.
I personally think this is a good idea. Since the autoload-function is only declared once in a script and takes the classname as a param, multiple including of diferent classes is not that complcated: Simple put a switch-statement into the function like this: <?php function __autoload($className) { switch ($className) {
       case "smartyLight":
          include_once "smartyLight.class.php";
       break;
       case "smarty":
          include_once "smarty.class.php";
       break;
} } ?> But: how do you want to decide which class you want to instantiate (for example u want to check if a cached exemplar exists and want to load this)? Things should then get stripped down: A smarty base-class which holds only neccessary information for cached templates (fetching them etc.) and the main-class (which we all know as smarty right now) that extends from this base-class and puts more methods and functionality to it. You then would require in every script you want to check for cached templates smartyBase.class.php like this: <?php // get the lightweight-class of smarty require_once "smartyBase.class.php"; // call a static method to check for cached exemplars: $cache = SmartyBase::checkIfTemplateIsCached("nameOfTemplate"); // $cache will now hold the cached template as a string or false if not cached if ($cache !== false) { echo $cache; die(); } // cache was false, no cached template, start loading smarty and do usual stuff with it... $smarty = new Smarty; ... ?> Just my two cents on it, while refactoring maybe something one could think about... Regards Thorsten


« previous php.smarty.general (#11596) next »