1. sfConfigHandler.class.php
  2. /** * sfConfigHandler allows a developer to create a custom formatted configuration * file pertaining to any information they like and still have it auto-generate * PHP code. * * @package symfony * @subpackage config * @author Fabien Potencier * @author Sean Kerr * @version SVN: $Id: sfConfigHandler.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $ */
  3. abstract class sfConfigHandler
  4. {
  5. protected
  6. $parameterHolder = null;
  7. /**
  8. * Class constructor.
  9. *
  10. * @see initialize()
  11. */
  12. public function __construct($parameters = null)
  13. {
  14. $this->initialize($parameters);
  15. }
  16. /**
  17. * Initializes this configuration handler.
  18. *
  19. * @param array $parameters An associative array of initialization parameters
  20. *
  21. * @return bool true, if initialization completes successfully, otherwise false
  22. *
  23. * @throws <b>sfInitializationException</b> If an error occurs while initializing this ConfigHandler
  24. */
  25. public function initialize($parameters = null)
  26. {
  27. $this->parameterHolder = new sfParameterHolder();
  28. $this->parameterHolder->add($parameters);
  29. }
  30. /**
  31. * Executes this configuration handler
  32. *
  33. * @param array $configFiles An array of filesystem path to a configuration file
  34. *
  35. * @return string Data to be written to a cache file
  36. *
  37. * @throws <b>sfConfigurationException</b> If a requested configuration file does not exist or is not readable
  38. * @throws <b>sfParseException</b> If a requested configuration file is improperly formatted
  39. */
  40. abstract public function execute($configFiles);
  41. /**
  42. * Replaces constant identifiers in a value.
  43. *
  44. * If the value is an array replacements are made recursively.
  45. *
  46. * @param mixed $value The value on which to run the replacement procedure
  47. *
  48. * @return string The new value
  49. */
  50. static public function replaceConstants($value)
  51. {
  52. if (is_array($value))
  53. {
  54. array_walk_recursive($value, create_function('&$value', '$value = sfToolkit::replaceConstants($value);'));
  55. }
  56. else
  57. {
  58. $value = sfToolkit::replaceConstants($value);
  59. }
  60. return $value;
  61. }
  62. /**
  63. * Replaces a relative filesystem path with an absolute one.
  64. *
  65. * @param string $path A relative filesystem path
  66. *
  67. * @return string The new path
  68. */
  69. static public function replacePath($path)
  70. {
  71. if (is_array($path))
  72. {
  73. array_walk_recursive($path, create_function('&$path', '$path = sfConfigHandler::replacePath($path);'));
  74. }
  75. else
  76. {
  77. if (!sfToolkit::isPathAbsolute($path))
  78. {
  79. // not an absolute path so we'll prepend to it
  80. $path = sfConfig::get('sf_app_dir').'/'.$path;
  81. }
  82. }
  83. return $path;
  84. }
  85. /**
  86. * Gets the parameter holder for this configuration handler.
  87. *
  88. * @return sfParameterHolder A sfParameterHolder instance
  89. */
  90. public function getParameterHolder()
  91. {
  92. return $this->parameterHolder;
  93. }
  94. /**
  95. * Returns the configuration for the current config handler.
  96. *
  97. * @param array $configFiles An array of ordered configuration files
  98. * @throws LogicException no matter what
  99. */
  100. static public function getConfiguration(array $configFiles)
  101. {
  102. throw new LogicException('You must call the ::getConfiguration() method on a concrete config handler class');
  103. }
  104. }

Debug toolbar