Re: [SMARTY] Smarty-Light
| From: | Thorsten Suckow-Homberg | Date: | Wed, 14 Jul 2004 23:16:15 +0000 |
| Subject: | Re: [SMARTY] Smarty-Light | ||
| References: | 1 2 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-11594@lists.php.net to get a copy of this message | ||
>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