/**
  * Compile all config files
  *
  * @param  string $extension     config file name extension
  * @param  bool   $force_compile force all to recompile
  * @param  int    $time_limit    set maximum execution time
  * @param  int    $max_errors    set maximum allowed errors
  * @param  hiweb_tpl $smurty        hiweb_tpl instance
  *
  * @return integer number of config files compiled
  */
 public static function compileAllConfig($extension, $force_compile, $time_limit, $max_errors, hiweb_tpl $smurty)
 {
     // switch off time limit
     if (function_exists('set_time_limit')) {
         @set_time_limit($time_limit);
     }
     $smurty->force_compile = $force_compile;
     $_count = 0;
     $_error_count = 0;
     // loop over array of template directories
     foreach ($smurty->getConfigDir() as $_dir) {
         $_compileDirs = new RecursiveDirectoryIterator($_dir);
         $_compile = new RecursiveIteratorIterator($_compileDirs);
         foreach ($_compile as $_fileinfo) {
             $_file = $_fileinfo->getFilename();
             if (substr(basename($_fileinfo->getPathname()), 0, 1) == '.' || strpos($_file, '.svn') !== false) {
                 continue;
             }
             if (!substr_compare($_file, $extension, -strlen($extension)) == 0) {
                 continue;
             }
             if ($_fileinfo->getPath() == substr($_dir, 0, -1)) {
                 $_config_file = $_file;
             } else {
                 $_config_file = substr($_fileinfo->getPath(), strlen($_dir)) . DIR_SEPARATOR . $_file;
             }
             echo '<br>', $_dir, '---', $_config_file;
             flush();
             $_start_time = microtime(true);
             try {
                 $_config = new Smurty_Internal_Config($_config_file, $smurty);
                 if ($_config->mustCompile()) {
                     $_config->compileConfigSource();
                     $_count++;
                     echo ' compiled in  ', microtime(true) - $_start_time, ' seconds';
                     flush();
                 } else {
                     echo ' is up to date';
                     flush();
                 }
             } catch (Exception $e) {
                 echo 'Error: ', $e->getMessage(), "<br><br>";
                 $_error_count++;
             }
             if ($max_errors !== null && $_error_count == $max_errors) {
                 echo '<br><br>too many errors';
                 exit;
             }
         }
     }
     return $_count;
 }
Exemplo n.º 2
0
 /**
  * load a config file, optionally load just selected sections
  *
  * @param  string $config_file filename
  * @param  mixed  $sections    array of section names, single section or null
  *
  * @return Smurty_Internal_Data current Smurty_Internal_Data (or hiweb_tpl or Smurty_Internal_Template) instance for chaining
  */
 public function configLoad($config_file, $sections = null)
 {
     // load Config class
     $config = new Smurty_Internal_Config($config_file, $this->smurty, $this);
     $config->loadConfigVars($sections);
     return $this;
 }