Re: template module

From: Date: Fri, 03 Aug 2001 05:23:30 +0000
Subject: Re: template module
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-1260@lists.php.net to get a copy of this message
Nice idea. But this also means that the common template functionality needs a common API. Is that doable (I'm not familiar enough with IT[X] and Smarty to tell)? - Stig mailling@bigfoot.com wrote: > > I propose to use a template manager, like there is a log manager. I already > realized something, but we could add some methods in the abstract class. > What do you think? > > It should already work with IT and ITX, but that would allow other template > system to be plugged in > > <?php > // $Id: Template.php,v 1.2 2001/07/04 15:56:05 shuther Exp $ > > /** > * The Template:: class implements both an abstraction for various template > * mechanisms. > * > * @author Jon Parise <jon@csh.rit.edu> > * @author Stephane Huther <shuther@bigfoot.com> > * @version $Revision: 1.0 $ > */ > class Template { > > // {{{ factory() > /** > * Attempts to return a concrete Template instance of $template_type. > * > * @param $template_type The type of concrete Template subclass to return. > * Attempt to dynamically include the code for this > * subclass. Currently, valid values are 'it' and > * 'itx'. > * > * @param string @root File root directory, prefix for all filenames > * given to the object. > * > * @return The newly created concrete Log instance, or an > * false on an error. > */ > function &factory ($template_type, $root = '') { > $template_type = strtolower($template_type); > $classfile = 'HTML/' . $template_type . '.php'; > > @include_once $classfile; > switch($template_type) > { > case 'it': > $class='IntegratedTemplate'; > break; > case 'itx': > $class='IntegratedTemplateExtension'; > break; > default: > $class = 'HTML_' . $template_type; > } > > if (class_exists($class)) { > return new $class($root); > } else { > return false; > } > } > // }}} > > // {{{ singleton() > /** > * Attempts to return a reference to a concrete Template instance of > * $template_type, only creating a new instance if no template instance > * with the same parameters currently exists. > * > * You should use this if there are multiple places you might > * create a tepmlate instance, you don't want to create multiple templates > * systems, and you don't want to check for the existance of one each > time. > * The singleton pattern does all the checking work for you. > * > * <b>You MUST call this method with the $var = &Template::singleton() > * syntax. Without the ampersand (&) in front of the method name, > * you will not get a reference, you will get a copy.</b> > * > * @param string $template_type The type of concrete Template subclass > * to return. Attempt to dynamically include the > * code for this subclass. Currently, valid values are > * 'it' and 'itx'. > * > * @param string @root File root directory, prefix for all filenames > * given to the object. > * @return The concrete Template reference, or false on an error. > */ > function &singleton ($template_type, $root = '') { > static $instances; > if (!isset($instances)) $instances = array(); > > $signature = md5($template_type . '][' . $root); > if (!isset($instances[$signature])) { > $instances[$signature] = Template::factory($template_type, $root); > } > return $instances[$signature]; > } > > } > > ?> > > -- > PEAR Development Mailing List (http://pear.php.net/) > To unsubscribe, e-mail: pear-dev-unsubscribe@lists.php.net > For additional commands, e-mail: pear-dev-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.pear.dev (#1260) next »