HTML_Template_Flexy
[ class tree: HTML_Template_Flexy ] [ index: HTML_Template_Flexy ] [ all elements ]

Source for file Compiler.php

Documentation is available at Compiler.php

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. // +----------------------------------------------------------------------+
  4. // | PHP Version 4                                                        |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2002 The PHP Group                                |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 2.02 of the PHP license,      |
  9. // | that is bundled with this package in the file LICENSE, and is        |
  10. // | available at through the world-wide-web at                           |
  11. // | http://www.php.net/license/2_02.txt.                                 |
  12. // | If you did not receive a copy of the PHP license and are unable to   |
  13. // | obtain it through the world-wide-web, please send a note to          |
  14. // | license@php.net so we can mail you a copy immediately.               |
  15. // +----------------------------------------------------------------------+
  16. // | Authors: Alan Knowles <alan@akbkhome.com>                            |
  17. // +----------------------------------------------------------------------+
  18. //
  19. // $Id: Compiler.php 315533 2011-08-26 02:39:02Z alan_k $
  20. //
  21. //  Base Compiler Class (Interface)
  22. //
  23.  
  24. /**
  25. * Compiler Globals go here..
  26. * public (to it's children)
  27. *
  28. @var array 
  29. @access public (to it's children)
  30. */
  31.  
  32. $GLOBAL['_HTML_TEMPLATE_FLEXY_COMPILER'= array();
  33.  
  34.  
  35. class HTML_Template_Flexy_Compiler {
  36.  
  37.         
  38.     /**
  39.     * Options
  40.     *
  41.     * @var array 
  42.     * @access public
  43.     */
  44.     var $options;
  45.     
  46.     /**
  47.     * Factory constructor
  48.     * 
  49.     * @param   array    options     only ['compiler']  is used directly
  50.     *
  51.     * @return   object    The Compiler Object
  52.     * @access   public
  53.     */
  54.     static function factory($options
  55.     {
  56.         if (empty($options['compiler'])) {
  57.             $options['compiler''Flexy';
  58.         }
  59.         if is_object($options['compiler']&&  $this->is_a($options['compiler']'HTML_Template_Flexy_Compiler')) {
  60.             $options['compiler']->options = $options;
  61.             return $options['compiler'];
  62.         }
  63.        
  64.         require_once 'HTML/Template/Flexy/Compiler/'.ucfirst$options['compiler'.'.php';
  65.         $class 'HTML_Template_Flexy_Compiler_'.$options['compiler'];
  66.         $ret = new $class;
  67.         $ret->options = $options;
  68.         return $ret;
  69.     }
  70.     /**
  71.      * Php4 is_a compat !
  72.      */
  73.     function is_a($obj$class)  // which f***wit depreciated is_a....
  74.     {
  75.         if (version_compare(phpversion(),"5","<")) {
  76.            return is_object($obj&& is_a($obj$class);
  77.            
  78.         
  79.         $test=false; 
  80.         @eval("\$test = \$obj instanceof ".$class.";");
  81.         return $test;
  82.  
  83.     }
  84.     
  85.     /**
  86.     * The compile method.
  87.     *
  88.     * @param object HTML_Template_Flexy that is requesting the compile
  89.     * @return   object  HTML_Template_Flexy 
  90.     * @return   string   to compile (if not using a file as the source)
  91.     * @access   public
  92.     */
  93.     function compile(&$flexy,$string = false
  94.     {
  95.         echo "No compiler implemented!";
  96.     }
  97.      
  98.     /**
  99.     * Append HTML to compiled ouput
  100.     * These are hooks for passing data to other processes
  101.     *
  102.     * @param   string to append to compiled
  103.     * 
  104.     * @return   string to be output
  105.     * @access   public
  106.     */
  107.     function appendHtml($string
  108.     {
  109.       
  110.         return $string;
  111.     }
  112.     /**
  113.     * Append PHP Code to compiled ouput
  114.     * These are hooks for passing data to other processes
  115.     *
  116.     * @param   string PHP code to append to compiled
  117.     *
  118.     * @return   string to be output
  119.     * @access   public
  120.     */
  121.     
  122.     function appendPhp($string
  123.     {
  124.         
  125.         return '<?php '.$string.'?>';
  126.     }
  127.     /**
  128.     * Compile All templates in the
  129.     * These are hooks for passing data to other processes
  130.     *
  131.     * @param   string PHP code to append to compiled
  132.     *
  133.     * @return   string to be output
  134.     * @access   public
  135.     */
  136.     
  137.     function compileAll(&$flexy$dir '',$regex='/.html$/')
  138.     {
  139.         $this->flexy &$flexy;
  140.         $this->compileDir($dir,$regex);
  141.     }
  142.     
  143.     
  144.     function compileDir($dir '',$regex='/.html$/')
  145.     {
  146.         
  147.         
  148.         foreach ($this->flexy->options['templateDir'as $base{
  149.             if (!file_exists($base . DIRECTORY_SEPARATOR  . $dir)) {
  150.                 continue;
  151.             }
  152.             $dh opendir($base . DIRECTORY_SEPARATOR  . $dir);
  153.             while (($name readdir($dh)) !== false{
  154.                 if (!$name{  // empty!?
  155.                     continue;
  156.                 }
  157.                 if ($name{0== '.'{
  158.                     continue;
  159.                 }
  160.                  
  161.                 if (is_dir($base . DIRECTORY_SEPARATOR  . $dir . DIRECTORY_SEPARATOR  . $name)) {
  162.                     $this->compileDir($dir . DIRECTORY_SEPARATOR  . $name,$regex);
  163.                     continue;
  164.                 }
  165.                 
  166.                 if (!preg_match($regex,$name)) {
  167.                     continue;
  168.                 }
  169.                 //echo "Compiling $dir". DIRECTORY_SEPARATOR  . "$name \n";
  170.                 $this->flexy->compile($dir . DIRECTORY_SEPARATOR  . $name);
  171.             }
  172.         }
  173.         
  174.     }
  175.     
  176.  
  177. }

Documentation generated on Mon, 11 Mar 2019 15:59:55 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.