[ Index ]
 

Code source de Symfony 1.0.0

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

title

Body

[fermer]

/lib/config/ -> sfGeneratorConfigHandler.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   *
   7   * For the full copyright and license information, please view the LICENSE
   8   * file that was distributed with this source code.
   9   */
  10  
  11  /**
  12   * sfGeneratorConfigHandler.
  13   *
  14   * @package    symfony
  15   * @subpackage config
  16   * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
  17   * @version    SVN: $Id: sfGeneratorConfigHandler.class.php 3203 2007-01-09 18:32:54Z fabien $
  18   */
  19  class sfGeneratorConfigHandler extends sfYamlConfigHandler
  20  {
  21    /**
  22     * Executes this configuration handler.
  23     *
  24     * @param array An array of absolute filesystem path to a configuration file
  25     *
  26     * @return string Data to be written to a cache file
  27     *
  28     * @throws sfConfigurationException If a requested configuration file does not exist or is not readable
  29     * @throws sfParseException If a requested configuration file is improperly formatted
  30     * @throws sfInitializationException If a generator.yml key check fails
  31     */
  32    public function execute($configFiles)
  33    {
  34      // parse the yaml
  35      $config = $this->parseYamls($configFiles);
  36      if (!$config)
  37      {
  38        return '';
  39      }
  40  
  41      if (!isset($config['generator']))
  42      {
  43        throw new sfParseException(sprintf('Configuration file "%s" must specify a generator section', $configFiles[1] ? $configFiles[1] : $configFiles[0]));
  44      }
  45  
  46      $config = $config['generator'];
  47  
  48      if (!isset($config['class']))
  49      {
  50        throw new sfParseException(sprintf('Configuration file "%s" must specify a generator class section under the generator section', $configFiles[1] ? $configFiles[1] : $configFiles[0]));
  51      }
  52  
  53      foreach (array('fields', 'list', 'edit') as $section)
  54      {
  55        if (isset($config[$section]))
  56        {
  57          throw new sfParseException(sprintf('Configuration file "%s" can specify a "%s" section but only under the param section', $configFiles[1] ? $configFiles[1] : $configFiles[0], $section));
  58        }
  59      }
  60  
  61      // generate class and add a reference to it
  62      $generatorManager = new sfGeneratorManager();
  63      $generatorManager->initialize();
  64  
  65      // generator parameters
  66      $generatorParam = (isset($config['param']) ? $config['param'] : array());
  67  
  68      // hack to find the module name
  69      preg_match('#'.sfConfig::get('sf_app_module_dir_name').'/([^/]+)/#', $configFiles[1], $match);
  70      $generatorParam['moduleName'] = $match[1];
  71  
  72      $data = $generatorManager->generate($config['class'], $generatorParam);
  73  
  74      // compile data
  75      $retval = "<?php\n".
  76                "// auto-generated by sfGeneratorConfigHandler\n".
  77                "// date: %s\n%s\n";
  78      $retval = sprintf($retval, date('Y/m/d H:i:s'), $data);
  79  
  80      return $retval;
  81    }
  82  }


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