[ Index ]

PHP Cross Reference of Web Application Component Toolkit

title

Body

[close]

/framework/template/compiler/common/ -> dictionary.inc.php (source)

   1  <?php
   2  //--------------------------------------------------------------------------------
   3  // Copyright 2003 Procata, Inc.
   4  // Released under the LGPL license (http://www.gnu.org/copyleft/lesser.html)
   5  //--------------------------------------------------------------------------------
   6  /**
   7  * @package WACT_TEMPLATE
   8  * @version $Id: dictionary.inc.php,v 1.3 2004/11/20 18:09:47 jeffmoore Exp $
   9  */
  10  
  11  // this is a dependency we should seek to remove
  12  // It is here because of our dependence on a particular file scheme, and the
  13  // TMPL_INCLUDE constant
  14  require_once WACT_ROOT . 'template/template.inc.php';
  15  
  16  /**
  17  * @access protected
  18  * @package WACT_TEMPLATE
  19  */
  20  class CompilerArtifactDictionary {
  21      /**
  22      * A Path used to search for compiler artifacts
  23      * @var array
  24      * @access private
  25      */
  26      var $SearchPath;
  27      
  28      function CompilerArtifactDictionary() {
  29          $this->SearchPath = ConfigManager::getOptionAsPath('compiler', 'tags', 'path');
  30      }    
  31  
  32      function scanDirectory($scandir, $extension) {
  33          $size = strlen($extension);
  34          if (is_dir($scandir)) {
  35              if ($dir = opendir($scandir)) {
  36                  while (($file = readdir($dir)) !== FALSE) {
  37                      if (substr($file, -$size, $size) == $extension) {
  38                          require_once $scandir . '/' . $file;
  39                      }
  40                  }
  41                  closedir($dir);
  42              }
  43          }
  44      
  45      }
  46  
  47  	function buildDictionary($extension) {
  48          foreach (explode(';', $this->SearchPath) as $tagpath) {
  49              $this->scanDirectory($tagpath, $extension);
  50          }
  51      }
  52  
  53      function &_getInstance($instance, $dictionaryClass, $type) {
  54          if (!isset($GLOBALS[$instance])) {
  55              $cachefile = ResolveTemplateCompiledFileName('/' . $type . '.cache', TMPL_INCLUDE);
  56              
  57              if (!ConfigManager::getOption('compiler', 'dictionary', 'forcescan')) {
  58                  if (file_exists($cachefile)) {
  59                      $GLOBALS[$instance] =& unserialize(readTemplateFile($cachefile));
  60                  }
  61              }
  62              
  63              if (!isset($GLOBALS[$instance]) || !is_object($GLOBALS[$instance])) {
  64                  $GLOBALS[$instance] =& new $dictionaryClass();
  65                  $GLOBALS[$instance]->buildDictionary('.' . $type . '.php');
  66  
  67                  $destfile = ResolveTemplateCompiledFileName('/' . $type . '.cache', TMPL_INCLUDE);
  68                  writeTemplateFile($destfile, serialize($GLOBALS[$instance]));
  69              }
  70          }
  71            return $GLOBALS[$instance];
  72      }
  73  
  74  }
  75  ?>


Generated: Sun Nov 28 19:36:09 2004 Cross-referenced by PHPXref 0.5