123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- <?php
- /*
- * This file is part of the symfony package.
- * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
- /**
- * sfRootConfigHandler allows you to specify configuration handlers for the
- * application or on a module level.
- *
- * @package symfony
- * @subpackage config
- * @author Fabien Potencier <fabien.potencier@symfony-project.com>
- * @version SVN: $Id: sfRootConfigHandler.class.php 13547 2008-11-30 14:05:44Z Kris.Wallsmith $
- */
- class sfRootConfigHandler extends sfYamlConfigHandler
- {
- /**
- * Executes this configuration handler
- *
- * @param array $configFiles An array of absolute filesystem path to a configuration file
- *
- * @return string Data to be written to a cache file
- *
- * @throws sfConfigurationException If a requested configuration file does not exist or is not readable
- * @throws sfParseException If a requested configuration file is improperly formatted
- */
- public function execute($configFiles)
- {
- // parse the yaml
- $config = self::getConfiguration($configFiles);
- // determine if we're loading the system config_handlers.yml or a module config_handlers.yml
- $moduleLevel = ($this->getParameterHolder()->get('module_level') === true) ? true : false;
- if ($moduleLevel)
- {
- // get the current module name
- $moduleName = $this->getParameterHolder()->get('module_name');
- }
- // init our data and includes arrays
- $data = array();
- $includes = array();
- // let's do our fancy work
- foreach ($config as $category => $keys)
- {
- if ($moduleLevel)
- {
- // module-level registration, so we must prepend the module
- // root to the category
- $category = 'modules/'.$moduleName.'/'.$category;
- }
- if (!isset($keys['class']))
- {
- // missing class key
- throw new sfParseException(sprintf('Configuration file "%s" specifies category "%s" with missing class key.', $configFiles[0], $category));
- }
- $class = $keys['class'];
- if (isset($keys['file']))
- {
- if (!is_readable($keys['file']))
- {
- // handler file doesn't exist
- throw new sfParseException(sprintf('Configuration file "%s" specifies class "%s" with nonexistent or unreadable file "%s".', $configFiles[0], $class, $keys['file']));
- }
- // append our data
- $includes[] = sprintf("require_once('%s');", $keys['file']);
- }
- // parse parameters
- $parameters = (isset($keys['param']) ? var_export($keys['param'], true) : null);
- // append new data
- $data[] = sprintf("\$this->handlers['%s'] = new %s(%s);", $category, $class, $parameters);
- }
- // compile data
- $retval = sprintf("<?php\n" .
- "// auto-generated by sfRootConfigHandler\n".
- "// date: %s\n%s\n%s\n",
- date('Y/m/d H:i:s'), implode("\n", $includes), implode("\n", $data));
- return $retval;
- }
- /**
- * @see sfConfigHandler
- */
- static public function getConfiguration(array $configFiles)
- {
- $config = self::replaceConstants(self::parseYamls($configFiles));
- foreach ($config as $category => $keys)
- {
- if (isset($keys['file']))
- {
- $config[$category]['file'] = self::replacePath($keys['file']);
- }
- }
- return $config;
- }
- }
|