Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Config.php 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. /**
  3. * System Configuration Class
  4. *
  5. * @file include/Core/Config.php
  6. *
  7. * @brief Contains the class with methods for system configuration
  8. */
  9. namespace Friendica\Core;
  10. use Friendica\Core\Config\ConfigCache;
  11. use Friendica\Core\Config\IConfigAdapter;
  12. use Friendica\Core\Config\IConfigCache;
  13. /**
  14. * @brief Arbitrary system configuration storage
  15. *
  16. * Note:
  17. * If we ever would decide to return exactly the variable type as entered,
  18. * we will have fun with the additional features. :-)
  19. */
  20. class Config
  21. {
  22. /**
  23. * @var Config\Configuration
  24. */
  25. private static $config;
  26. /**
  27. * Initialize the config
  28. *
  29. * @param Config\Configuration $config
  30. */
  31. public static function init(Config\Configuration $config)
  32. {
  33. self::$config = $config;
  34. }
  35. /**
  36. * @brief Loads all configuration values of family into a cached storage.
  37. *
  38. * @param string $cat The category of the configuration value
  39. *
  40. * @return void
  41. */
  42. public static function load($cat = "config")
  43. {
  44. self::$config->load($cat);
  45. }
  46. /**
  47. * @brief Get a particular user's config variable given the category name
  48. * ($family) and a key.
  49. *
  50. * @param string $cat The category of the configuration value
  51. * @param string $key The configuration key to query
  52. * @param mixed $default_value optional, The value to return if key is not set (default: null)
  53. * @param boolean $refresh optional, If true the config is loaded from the db and not from the cache (default: false)
  54. *
  55. * @return mixed Stored value or null if it does not exist
  56. */
  57. public static function get($cat, $key, $default_value = null, $refresh = false)
  58. {
  59. return self::$config->get($cat, $key, $default_value, $refresh);
  60. }
  61. /**
  62. * @brief Sets a configuration value for system config
  63. *
  64. * Stores a config value ($value) in the category ($cat) under the key ($key)
  65. *
  66. * Note: Please do not store booleans - convert to 0/1 integer values!
  67. *
  68. * @param string $cat The category of the configuration value
  69. * @param string $key The configuration key to set
  70. * @param mixed $value The value to store
  71. *
  72. * @return bool Operation success
  73. */
  74. public static function set($cat, $key, $value)
  75. {
  76. return self::$config->set($cat, $key, $value);
  77. }
  78. /**
  79. * @brief Deletes the given key from the system configuration.
  80. *
  81. * @param string $cat The category of the configuration value
  82. * @param string $key The configuration key to delete
  83. *
  84. * @return bool
  85. */
  86. public static function delete($cat, $key)
  87. {
  88. return self::$config->delete($cat, $key);
  89. }
  90. }