appconfig.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. /**
  3. * @author Bart Visscher <bartv@thisnet.nl>
  4. * @author Morris Jobke <hey@morrisjobke.de>
  5. * @author Robin Appelman <icewind@owncloud.com>
  6. * @author Robin McCorkell <rmccorkell@karoshi.org.uk>
  7. * @author Scrutinizer Auto-Fixer <auto-fixer@scrutinizer-ci.com>
  8. *
  9. * @copyright Copyright (c) 2015, ownCloud, Inc.
  10. * @license AGPL-3.0
  11. *
  12. * This code is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License, version 3,
  14. * as published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License, version 3,
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>
  23. *
  24. */
  25. /**
  26. * This class provides an easy way for apps to store config values in the
  27. * database.
  28. *
  29. * @deprecated use \OC::$server->getAppConfig() to get an \OCP\IAppConfig instance
  30. */
  31. class OC_Appconfig {
  32. /**
  33. * @return \OCP\IAppConfig
  34. */
  35. private static function getAppConfig() {
  36. return \OC::$server->getAppConfig();
  37. }
  38. /**
  39. * Get all apps using the config
  40. * @return array an array of app ids
  41. *
  42. * This function returns a list of all apps that have at least one
  43. * entry in the appconfig table.
  44. */
  45. public static function getApps() {
  46. return self::getAppConfig()->getApps();
  47. }
  48. /**
  49. * Get the available keys for an app
  50. * @param string $app the app we are looking for
  51. * @return array an array of key names
  52. *
  53. * This function gets all keys of an app. Please note that the values are
  54. * not returned.
  55. */
  56. public static function getKeys($app) {
  57. return self::getAppConfig()->getKeys($app);
  58. }
  59. /**
  60. * Gets the config value
  61. * @param string $app app
  62. * @param string $key key
  63. * @param string $default = null, default value if the key does not exist
  64. * @return string the value or $default
  65. *
  66. * This function gets a value from the appconfig table. If the key does
  67. * not exist the default value will be returned
  68. */
  69. public static function getValue($app, $key, $default = null) {
  70. return self::getAppConfig()->getValue($app, $key, $default);
  71. }
  72. /**
  73. * check if a key is set in the appconfig
  74. * @param string $app
  75. * @param string $key
  76. * @return bool
  77. */
  78. public static function hasKey($app, $key) {
  79. return self::getAppConfig()->hasKey($app, $key);
  80. }
  81. /**
  82. * sets a value in the appconfig
  83. * @param string $app app
  84. * @param string $key key
  85. * @param string $value value
  86. *
  87. * Sets a value. If the key did not exist before it will be created.
  88. */
  89. public static function setValue($app, $key, $value) {
  90. self::getAppConfig()->setValue($app, $key, $value);
  91. }
  92. /**
  93. * Deletes a key
  94. * @param string $app app
  95. * @param string $key key
  96. *
  97. * Deletes a key.
  98. */
  99. public static function deleteKey($app, $key) {
  100. self::getAppConfig()->deleteKey($app, $key);
  101. }
  102. /**
  103. * Remove app from appconfig
  104. * @param string $app app
  105. *
  106. * Removes all keys in appconfig belonging to the app.
  107. */
  108. public static function deleteApp($app) {
  109. self::getAppConfig()->deleteApp($app);
  110. }
  111. /**
  112. * get multiply values, either the app or key can be used as wildcard by setting it to false
  113. *
  114. * @param string|false $app
  115. * @param string|false $key
  116. * @return array
  117. */
  118. public static function getValues($app, $key) {
  119. return self::getAppConfig()->getValues($app, $key);
  120. }
  121. }