1. sfRootConfigHandler.class.php
  2. /** * sfRootConfigHandler allows you to specify configuration handlers for the * application or on a module level. * * @package symfony * @subpackage config * @author Fabien Potencier * @version SVN: $Id: sfRootConfigHandler.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $ */
  3. class sfRootConfigHandler extends sfYamlConfigHandler
  4. {
  5. /**
  6. * Executes this configuration handler
  7. *
  8. * @param array $configFiles An array of absolute filesystem path to a configuration file
  9. *
  10. * @return string Data to be written to a cache file
  11. *
  12. * @throws sfConfigurationException If a requested configuration file does not exist or is not readable
  13. * @throws sfParseException If a requested configuration file is improperly formatted
  14. */
  15. public function execute($configFiles)
  16. {
  17. // parse the yaml
  18. $config = self::getConfiguration($configFiles);
  19. // determine if we're loading the system config_handlers.yml or a module config_handlers.yml
  20. $moduleLevel = ($this->getParameterHolder()->get('module_level') === true) ? true : false;
  21. if ($moduleLevel)
  22. {
  23. // get the current module name
  24. $moduleName = $this->getParameterHolder()->get('module_name');
  25. }
  26. // init our data and includes arrays
  27. $data = array();
  28. $includes = array();
  29. // let's do our fancy work
  30. foreach ($config as $category => $keys)
  31. {
  32. if ($moduleLevel)
  33. {
  34. // module-level registration, so we must prepend the module
  35. // root to the category
  36. $category = 'modules/'.$moduleName.'/'.$category;
  37. }
  38. if (!isset($keys['class']))
  39. {
  40. // missing class key
  41. throw new sfParseException(sprintf('Configuration file "%s" specifies category "%s" with missing class key.', $configFiles[0], $category));
  42. }
  43. $class = $keys['class'];
  44. if (isset($keys['file']))
  45. {
  46. if (!is_readable($keys['file']))
  47. {
  48. // handler file doesn't exist
  49. throw new sfParseException(sprintf('Configuration file "%s" specifies class "%s" with nonexistent or unreadable file "%s".', $configFiles[0], $class, $keys['file']));
  50. }
  51. // append our data
  52. $includes[] = sprintf("require_once('%s');", $keys['file']);
  53. }
  54. // parse parameters
  55. $parameters = (isset($keys['param']) ? var_export($keys['param'], true) : null);
  56. // append new data
  57. $data[] = sprintf("\$this->handlers['%s'] = new %s(%s);", $category, $class, $parameters);
  58. }
  59. // compile data
  60. $retval = sprintf("<?php\n" .
  61. "// auto-generated by sfRootConfigHandler\n".
  62. "// date: %s\n%s\n%s\n",
  63. date('Y/m/d H:i:s'), implode("\n", $includes), implode("\n", $data));
  64. return $retval;
  65. }
  66. /**
  67. * @see sfConfigHandler
  68. */
  69. static public function getConfiguration(array $configFiles)
  70. {
  71. $config = self::replaceConstants(self::parseYamls($configFiles));
  72. foreach ($config as $category => $keys)
  73. {
  74. if (isset($keys['file']))
  75. {
  76. $config[$category]['file'] = self::replacePath($keys['file']);
  77. }
  78. }
  79. return $config;
  80. }
  81. }

Debug toolbar