Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
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.

94 lines
2.4KB

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