config.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. /**
  3. * ownCloud
  4. *
  5. * @author Frank Karlitschek
  6. * @author Jakob Sack
  7. * @copyright 2012 Frank Karlitschek frank@owncloud.org
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  11. * License as published by the Free Software Foundation; either
  12. * version 3 of the License, or any later version.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public
  20. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. */
  23. /*
  24. *
  25. * An example of config.php
  26. *
  27. * <?php
  28. * $CONFIG = array(
  29. * "database" => "mysql",
  30. * "firstrun" => false,
  31. * "pi" => 3.14
  32. * );
  33. * ?>
  34. *
  35. */
  36. /**
  37. * This class is responsible for reading and writing config.php, the very basic
  38. * configuration file of ownCloud.
  39. */
  40. OC_Config::$object = new \OC\Config(OC::$SERVERROOT.'/config/');
  41. class OC_Config {
  42. /**
  43. * @var \OC\Config
  44. */
  45. public static $object;
  46. public static function getObject() {
  47. return self::$object;
  48. }
  49. /**
  50. * @brief Lists all available config keys
  51. * @return array with key names
  52. *
  53. * This function returns all keys saved in config.php. Please note that it
  54. * does not return the values.
  55. */
  56. public static function getKeys() {
  57. return self::$object->getKeys();
  58. }
  59. /**
  60. * @brief Gets a value from config.php
  61. * @param string $key key
  62. * @param string $default = null default value
  63. * @return string the value or $default
  64. *
  65. * This function gets the value from config.php. If it does not exist,
  66. * $default will be returned.
  67. */
  68. public static function getValue($key, $default = null) {
  69. return self::$object->getValue($key, $default);
  70. }
  71. /**
  72. * @brief Sets a value
  73. * @param string $key key
  74. * @param string $value value
  75. *
  76. * This function sets the value and writes the config.php.
  77. *
  78. */
  79. public static function setValue($key, $value) {
  80. try {
  81. self::$object->setValue($key, $value);
  82. } catch (\OC\HintException $e) {
  83. \OC_Template::printErrorPage($e->getMessage(), $e->getHint());
  84. }
  85. }
  86. /**
  87. * @brief Removes a key from the config
  88. * @param string $key key
  89. *
  90. * This function removes a key from the config.php.
  91. *
  92. */
  93. public static function deleteKey($key) {
  94. try {
  95. self::$object->deleteKey($key);
  96. } catch (\OC\HintException $e) {
  97. \OC_Template::printErrorPage($e->getMessage(), $e->getHint());
  98. }
  99. }
  100. }