Re: [SMARTY] Smarty-Light

From: Date: Thu, 15 Jul 2004 01:25: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-11598@lists.php.net to get a copy of this message
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;
} } ?>
somebody pointed out the problem with multiple __autoload() definitions (not possible.) so that is basically ruled out. although Smarty already has a fileloading functionality for the modifiers, I don't see why that can't be used in the first instance for classes.
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; ... ?>
I would suggest object aggregation, to avoid te above: <? class Smarty {
    private $compiler;
    public function display($tpl)
    {
        if (SmartyBase::checkIfTemplateIsCached($tpl)) {
            $this->compiler = new SmartyCompiler( $this );
            $this->compiler->doMagic($tpl);
            // unset( $this->compiler ); // ?
        }
        // forgive me the internal of smarty
        // escape me right now.
        $this->_showEmWhatYaGot();
    }
} ?> things like security, 'advanced' syntax (e.g. php, section tags) could be aggregated also and possibly included.
Just my two cents on it, while refactoring maybe something one could think about... Regards Thorsten


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