sfConfig.class.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. /*
  3. * This file is part of the symfony package.
  4. * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
  5. *
  6. * For the full copyright and license information, please view the LICENSE
  7. * file that was distributed with this source code.
  8. */
  9. /**
  10. * sfConfig stores all configuration information for a symfony application.
  11. *
  12. * @package symfony
  13. * @subpackage config
  14. * @author Fabien Potencier <fabien.potencier@symfony-project.com>
  15. * @version SVN: $Id: sfConfig.class.php 9085 2008-05-20 01:53:23Z Carl.Vondrick $
  16. */
  17. class sfConfig
  18. {
  19. protected static
  20. $config = array();
  21. /**
  22. * Retrieves a config parameter.
  23. *
  24. * @param string $name A config parameter name
  25. * @param mixed $default A default config parameter value
  26. *
  27. * @return mixed A config parameter value, if the config parameter exists, otherwise null
  28. */
  29. public static function get($name, $default = null)
  30. {
  31. return isset(self::$config[$name]) ? self::$config[$name] : $default;
  32. }
  33. /**
  34. * Indicates whether or not a config parameter exists.
  35. *
  36. * @param string $name A config parameter name
  37. *
  38. * @return bool true, if the config parameter exists, otherwise false
  39. */
  40. public static function has($name)
  41. {
  42. return array_key_exists($name, self::$config);
  43. }
  44. /**
  45. * Sets a config parameter.
  46. *
  47. * If a config parameter with the name already exists the value will be overridden.
  48. *
  49. * @param string $name A config parameter name
  50. * @param mixed $value A config parameter value
  51. */
  52. public static function set($name, $value)
  53. {
  54. self::$config[$name] = $value;
  55. }
  56. /**
  57. * Sets an array of config parameters.
  58. *
  59. * If an existing config parameter name matches any of the keys in the supplied
  60. * array, the associated value will be overridden.
  61. *
  62. * @param array $parameters An associative array of config parameters and their associated values
  63. */
  64. public static function add($parameters = array())
  65. {
  66. self::$config = array_merge(self::$config, $parameters);
  67. }
  68. /**
  69. * Retrieves all configuration parameters.
  70. *
  71. * @return array An associative array of configuration parameters.
  72. */
  73. public static function getAll()
  74. {
  75. return self::$config;
  76. }
  77. /**
  78. * Clears all current config parameters.
  79. */
  80. public static function clear()
  81. {
  82. self::$config = array();
  83. }
  84. }