[ Index ]
 

Code source de Symfony 1.0.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/lib/config/ -> sfCompileConfigHandler.class.php (source)

   1  <?php
   2  
   3  /*
   4   * This file is part of the symfony package.
   5   * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
   6   * (c) 2004-2006 Sean Kerr.
   7   *
   8   * For the full copyright and license information, please view the LICENSE
   9   * file that was distributed with this source code.
  10   */
  11  
  12  /**
  13   * sfCompileConfigHandler gathers multiple files and puts them into a single file.
  14   * Upon creation of the new file, all comments and blank lines are removed.
  15   *
  16   * @package    symfony
  17   * @subpackage config
  18   * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
  19   * @author     Sean Kerr <skerr@mojavi.org>
  20   * @version    SVN: $Id: sfCompileConfigHandler.class.php 3203 2007-01-09 18:32:54Z fabien $
  21   */
  22  class sfCompileConfigHandler extends sfYamlConfigHandler
  23  {
  24    /**
  25     * Executes this configuration handler.
  26     *
  27     * @param array An array of absolute filesystem path to a configuration file
  28     *
  29     * @return string Data to be written to a cache file
  30     *
  31     * @throws sfConfigurationException If a requested configuration file does not exist or is not readable
  32     * @throws sfParseException If a requested configuration file is improperly formatted
  33     */
  34    public function execute($configFiles)
  35    {
  36      // parse the yaml
  37      $config = array();
  38      foreach ($configFiles as $configFile)
  39      {
  40        $config = array_merge($config, $this->parseYaml($configFile));
  41      }
  42  
  43      // init our data
  44      $data = '';
  45  
  46      // let's do our fancy work
  47      foreach ($config as $file)
  48      {
  49        $file = $this->replaceConstants($file);
  50        $file = $this->replacePath($file);
  51  
  52        if (!is_readable($file))
  53        {
  54          // file doesn't exist
  55          $error = sprintf('Configuration file "%s" specifies nonexistent or unreadable file "%s"', $configFiles[0], $file);
  56          throw new sfParseException($error);
  57        }
  58  
  59        $contents = file_get_contents($file);
  60  
  61        // append file data
  62        $data .= "\n".$contents;
  63      }
  64  
  65      // insert configuration files
  66      $data = preg_replace_callback(array('#(require|include)(_once)?\((sfConfigCache::getInstance\(\)|\$configCache)->checkConfig\([^_]+sf_app_config_dir_name[^\.]*\.\'/([^\']+)\'\)\);#m',
  67                                          '#()()(sfConfigCache::getInstance\(\)|\$configCache)->import\(.sf_app_config_dir_name\.\'/([^\']+)\'(, false)?\);#m'),
  68                                    array($this, 'insertConfigFileCallback'), $data);
  69  
  70      // strip comments (not in debug mode)
  71      if (!sfConfig::get('sf_debug'))
  72      {
  73        $data = sfToolkit::stripComments($data);
  74      }
  75  
  76      // strip php tags
  77      $data = sfToolkit::pregtr($data, array('/^\s*<\?(php)?/m' => '',
  78                                             '/^\s*\?>/m'       => ''));
  79  
  80      // replace windows and mac format with unix format
  81      $data = str_replace("\r",  "\n", $data);
  82  
  83      // replace multiple new lines with a single newline
  84      $data = preg_replace(array('/\s+$/Sm', '/\n+/S'), "\n", $data);
  85  
  86      // compile data
  87      $retval = sprintf("<?php\n".
  88                        "// auto-generated by sfCompileConfigHandler\n".
  89                        "// date: %s\n%s\n",
  90                        date('Y/m/d H:i:s'), $data);
  91  
  92      // save current symfony release
  93      file_put_contents(sfConfig::get('sf_config_cache_dir').'/VERSION', file_get_contents(sfConfig::get('sf_symfony_lib_dir').'/VERSION'));
  94  
  95      return $retval;
  96    }
  97  
  98    /**
  99     * Callback for configuration file insertion in the cache.
 100     *
 101     */
 102    protected function insertConfigFileCallback($matches)
 103    {
 104      $configFile = sfConfig::get('sf_app_config_dir_name').'/'.$matches[4];
 105  
 106      sfConfigCache::getInstance()->checkConfig($configFile);
 107  
 108      $config = "// '$configFile' config file\n".
 109                file_get_contents(sfConfigCache::getInstance()->getCacheName($configFile));
 110  
 111      return $config;
 112    }
 113  }


Généré le : Fri Mar 16 22:42:14 2007 par Balluche grâce à PHPXref 0.7