Config.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Bart Visscher <bartv@thisnet.nl>
  6. * @author Frank Karlitschek <frank@karlitschek.de>
  7. * @author Georg Ehrke <oc.list@georgehrke.com>
  8. * @author Jörn Friedrich Dreyer <jfd@butonic.de>
  9. * @author Lukas Reschke <lukas@statuscode.ch>
  10. * @author Morris Jobke <hey@morrisjobke.de>
  11. * @author Robin Appelman <robin@icewind.nl>
  12. * @author Thomas Müller <thomas.mueller@tmit.eu>
  13. *
  14. * @license AGPL-3.0
  15. *
  16. * This code is free software: you can redistribute it and/or modify
  17. * it under the terms of the GNU Affero General Public License, version 3,
  18. * as published by the Free Software Foundation.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU Affero General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU Affero General Public License, version 3,
  26. * along with this program. If not, see <http://www.gnu.org/licenses/>
  27. *
  28. */
  29. /**
  30. * Public interface of ownCloud for apps to use.
  31. * Config Class
  32. *
  33. */
  34. /**
  35. * Use OCP namespace for all classes that are considered public.
  36. *
  37. * Classes that use this namespace are for use by apps, and not for use by internal
  38. * OC classes
  39. */
  40. namespace OCP;
  41. /**
  42. * This class provides functions to read and write configuration data.
  43. * configuration can be on a system, application or user level
  44. * @deprecated 8.0.0 use methods of \OCP\IConfig
  45. */
  46. class Config {
  47. /**
  48. * Gets a value from config.php
  49. * @param string $key key
  50. * @param mixed $default = null default value
  51. * @return mixed the value or $default
  52. * @deprecated 8.0.0 use method getSystemValue of \OCP\IConfig
  53. *
  54. * This function gets the value from config.php. If it does not exist,
  55. * $default will be returned.
  56. */
  57. public static function getSystemValue( $key, $default = null ) {
  58. return \OC::$server->getConfig()->getSystemValue( $key, $default );
  59. }
  60. /**
  61. * Sets a value
  62. * @param string $key key
  63. * @param mixed $value value
  64. * @return bool
  65. * @deprecated 8.0.0 use method setSystemValue of \OCP\IConfig
  66. *
  67. * This function sets the value and writes the config.php. If the file can
  68. * not be written, false will be returned.
  69. */
  70. public static function setSystemValue( $key, $value ) {
  71. try {
  72. \OC::$server->getConfig()->setSystemValue( $key, $value );
  73. } catch (\Exception $e) {
  74. return false;
  75. }
  76. return true;
  77. }
  78. /**
  79. * Deletes a value from config.php
  80. * @param string $key key
  81. * @deprecated 8.0.0 use method deleteSystemValue of \OCP\IConfig
  82. *
  83. * This function deletes the value from config.php.
  84. */
  85. public static function deleteSystemValue( $key ) {
  86. \OC::$server->getConfig()->deleteSystemValue( $key );
  87. }
  88. /**
  89. * Gets the config value
  90. * @param string $app app
  91. * @param string $key key
  92. * @param string $default = null, default value if the key does not exist
  93. * @return string the value or $default
  94. * @deprecated 8.0.0 use method getAppValue of \OCP\IConfig
  95. *
  96. * This function gets a value from the appconfig table. If the key does
  97. * not exist the default value will be returned
  98. */
  99. public static function getAppValue( $app, $key, $default = null ) {
  100. return \OC::$server->getConfig()->getAppValue( $app, $key, $default );
  101. }
  102. /**
  103. * Sets a value in the appconfig
  104. * @param string $app app
  105. * @param string $key key
  106. * @param string $value value
  107. * @return boolean true/false
  108. * @deprecated 8.0.0 use method setAppValue of \OCP\IConfig
  109. *
  110. * Sets a value. If the key did not exist before it will be created.
  111. */
  112. public static function setAppValue( $app, $key, $value ) {
  113. try {
  114. \OC::$server->getConfig()->setAppValue( $app, $key, $value );
  115. } catch (\Exception $e) {
  116. return false;
  117. }
  118. return true;
  119. }
  120. /**
  121. * Gets the preference
  122. * @param string $user user
  123. * @param string $app app
  124. * @param string $key key
  125. * @param string $default = null, default value if the key does not exist
  126. * @return string the value or $default
  127. * @deprecated 8.0.0 use method getUserValue of \OCP\IConfig
  128. *
  129. * This function gets a value from the preferences table. If the key does
  130. * not exist the default value will be returned
  131. */
  132. public static function getUserValue( $user, $app, $key, $default = null ) {
  133. return \OC::$server->getConfig()->getUserValue( $user, $app, $key, $default );
  134. }
  135. /**
  136. * Sets a value in the preferences
  137. * @param string $user user
  138. * @param string $app app
  139. * @param string $key key
  140. * @param string $value value
  141. * @return bool
  142. * @deprecated 8.0.0 use method setUserValue of \OCP\IConfig
  143. *
  144. * Adds a value to the preferences. If the key did not exist before, it
  145. * will be added automagically.
  146. */
  147. public static function setUserValue( $user, $app, $key, $value ) {
  148. try {
  149. \OC::$server->getConfig()->setUserValue( $user, $app, $key, $value );
  150. } catch (\Exception $e) {
  151. return false;
  152. }
  153. return true;
  154. }
  155. }