[ Index ]

PHP Cross Reference of Limb3

title

Body

[close]

/wact/src/ -> WactTemplate.class.php (source)

   1  <?php
   2  /*
   3   * Limb PHP Framework
   4   *
   5   * @link http://limb-project.com 
   6   * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
   7   * @license    LGPL http://www.gnu.org/copyleft/lesser.html 
   8   */
   9  
  10  require_once('limb/wact/src/components/components.inc.php');
  11  
  12  /**

  13   * class WactTemplate.

  14   *

  15   * @package wact

  16   * @version $Id: WactTemplate.class.php 5945 2007-06-06 08:31:43Z pachanga $

  17   */
  18  class WactTemplate extends WactDatasourceRuntimeComponent
  19  {
  20    protected $template_path;
  21  
  22    protected $render_function;
  23  
  24    protected $config;
  25  
  26    protected $locator;
  27  
  28    protected $components;
  29  
  30    function __construct($template_path, $config = null, $locator = null)
  31    {
  32      parent :: __construct('root');
  33  
  34      if(!is_object($config))
  35      {
  36        require_once('limb/wact/src/WactDefaultTemplateConfig.class.php');
  37        $config = new WactDefaultTemplateConfig();
  38      }
  39  
  40      if(!is_object($locator))
  41      {
  42        require_once('limb/wact/src/locator/WactDefaultTemplateLocator.class.php');
  43        $locator = new WactDefaultTemplateLocator($config);
  44      }
  45  
  46      $this->config = $config;
  47      $this->locator = $locator;
  48  
  49      $this->template_path = $template_path;
  50  
  51      $compiled_template_path = $this->locator->locateCompiledTemplate($this->template_path);
  52  
  53      if(!isset($GLOBALS['TemplateRender'][$compiled_template_path]))
  54      {
  55        if(($this->config->isForceCompile()) || !file_exists($compiled_template_path))
  56        {
  57          $compiler = $this->createCompiler();
  58          $compiler->compile($this->template_path);
  59        }
  60  
  61        include_once($compiled_template_path);
  62      }
  63  
  64      $this->render_function = $GLOBALS['TemplateRender'][$compiled_template_path];
  65      $func = $GLOBALS['TemplateConstruct'][$compiled_template_path];
  66      $this->components = array();
  67      $func($this, $this->components);
  68    }
  69  
  70    function createCompiler()
  71    {
  72      require_once 'limb/wact/src/compiler/templatecompiler.inc.php';
  73      return new WactCompiler($this->config, $this->locator);
  74    }
  75  
  76    /**

  77    * @return WactArrayObject

  78    **/
  79    static function makeObject($value)
  80    {
  81      if (is_object($value) && method_exists($value, 'get'))
  82        return $value;
  83      elseif(is_object($value) || is_array($value))
  84        return new WactArrayObject($value);
  85  
  86      return new WactArrayObject(array());
  87    }
  88  
  89    /**

  90    * @return WactArrayIterator/Iterator

  91    **/
  92    static function castToIterator($value)
  93    {
  94      if(!$value || is_scalar($value))
  95        return new WactArrayIterator(array());
  96  
  97      if(is_array($value))
  98        return new WactArrayIterator($value);
  99  
 100      if($value instanceof IteratorAggregate)
 101        return $value->getIterator();
 102  
 103      return $value;
 104    }
 105  
 106    function display()
 107    {
 108      $func = $this->render_function;
 109      $func($this, $this->components);
 110    }
 111  
 112    function capture()
 113    {
 114      ob_start();
 115      try
 116      {
 117        $this->display();
 118      }
 119      catch(WactException $e)
 120      {
 121        ob_end_flush();
 122        throw $e;
 123      }
 124      return ob_get_clean();
 125    }
 126  
 127    function getTemplatePath()
 128    {
 129      return $this->locator->locateSourceTemplate($this->template_path);
 130    }
 131  
 132    function toStudlyCaps($str)
 133    {
 134      return preg_replace('~([a-zA-Z])?_([a-zA-Z])~e', "'\\1'.strtoupper('\\2')", $str);
 135    }
 136  
 137    static function isFileReadable($file)
 138    {
 139      $fh = @fopen($file, 'r', true);
 140      if(!is_resource($fh))
 141        return false;
 142  
 143      fclose($fh);
 144      return true;
 145    }
 146  }
 147  
 148  
 149  ?>


Generated: Tue Oct 14 04:47:40 2008 Cross-referenced by PHPXref 0.7