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.

PConfig.php 2.6KB

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