Re: Play nice! Re: Savant/Flexy/Foo template engines

From: Date: Thu, 10 Jun 2004 15:11:47 +0000
Subject: Re: Play nice! Re: Savant/Flexy/Foo template engines
References: 1 2 3 4 5 6 7 8 9  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-30399@lists.php.net to get a copy of this message
Hi, guys, Not to be an ass (again) and I know Alan says he's continuing to strip it down. However, this attempt ...
http://devel.akbkhome.com/svn/index.php/akpear/HTML_Template/Template.php
... is still very, very Flexy in my eyes; I don't think it's sufficiently minimalist to act as a base for different systems, not even with the nods to the Jausions interface names. I only got so far in my attempt to strip it down before I realized I couldn't do it. Here's my abortive attempt (sorry, Alan; I think it was Greg who asked me to try this?): /** * Universal Template Provider * * Example to be added.. * */ class HTML_Template { // no options by default var $options = array(); // no files, we're minimal! :-) // no HTML elements, we're minimal! :-)
    /**
    *   Constructor
    *
    *   Initializes the Template engine, for each instance, accepts options or
    *   configuration overlay:
    *   defaults (in here), GLOBALS[HTML_Template][options], then the options you send it..
    *
    *   @access public
    *   @param    array    $options (Optional)
    */
    function HTML_Template( $options=array() )
    {
        $this->options = $this->options + $GLOBALS['HTML_Template']['options'] + $options ; // huh?  maybe array_merge() instead.
        // no other manipulations, leave this to the extended classes, we're minimal! :-)
    }
    /**
    *   open (and optionally compile a template )
    *
    *   @access     public
    *   @param      string  $file   relative to the 'templateDir' which you set when calling the constructor
    *   @return     boolean true on success. (or string, if compileToString) PEAR_Error on failure..
    */
    function openTemplate( $file )
    {
        // This whole method is very Flexy-specific, to be extensible it needs to
        // be significantly stripped down (esp. the multi-lang)
        // ...
        // the following assumes the need or desire for a compiler,
        // not necessarily the case.
        /*  minimalize!  maybe no compiler at all!  :-)
        require_once 'HTML/Template/Compiler.php';
        // factory - check if we need to compile!
        $compiler = HTML_Template_Compiler::factory($this);
        if (!is_a($compiler,'HTML_Template_Compiler')) {
            return $compiler;
        }
        return $compiler->compile();
        */
        // PMJ says:  the base class should just return a pointer to the template.
        // extended classes can do whatever necessary maipulations to find
        // the template.
        return $file;
    }
    /**
    *   Outputs the template..
    *
    *   @access     public
    *   @author     Alan Knowles
    *   @return     none
    */
    function output()
    {
    	    /* $data not passed in here, where's it coming from? probably just a typo in the params */
    	
        // validate our data..
        if (!is_array($data['elements'])) {
            return $this->raiseError(
                'second Argument to HTML_Template_Flexy::outputObject() was an '.gettype($elements) . ', not an array',
                HTML_TEMPLATE_FLEXY_ERROR_INVALIDARGS ,HTML_TEMPLATE_FLEXY_ERROR_DIE);
        }
        $this->debug( "output $this->compiledTemplate<BR>");
        /* very Flexy, this should be in an extended class:
        if ($this->options['output.element_merge'] !== false) {
            // loads elements into data['elementsOriginal']
            if ($this->getElement()) {
                // elements' loaded preumably... as we have some!
                HTML_Template_Element::mergeAllElements($this);
            }
        }
        */
        // we use PHP's error handler to hide errors in the template.
        // use $options['strict'] - if you want to force declaration of
        // all variables in the template
        /*  This should probably be part of OpenTemplate(), which does the
        find/filter/compile/filter bit for preparing the template:
        $_error_reporting = false;
        if (!$this->options['strict']) {
            $_error_reporting = error_reporting(E_ALL ^ E_NOTICE);
        }
        if (!is_readable($this->files['compiledTemplate'])) {
              return $this->raiseError( "Could not open the template: <b>'{$this->compiledTemplate}'</b><BR>".
                            "Please check the file permisons on the directory and file ",
                            HTML_TEMPLATE_FLEXY_ERROR_FILE, HTML_TEMPLATE_FLEXY_ERROR_DIE);
        }
        */
/me gives up at this point -- Paul M. Jones Savant: the simple alternative to Smarty for PHP. http://phpsavant.com/ DB_Table: build RDBMS tables and XHTML forms in one PHP class. http://wiki.ciaweb.net/yawiki/index.php?area=DB_Table Yawiki: your collaborative online documentation system. http://yawiki.com/ Yawp: a single-file foundation for PHP applications. http://phpyawp.com/

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