Style and comment fixes

remotes/origin/stable6
Michael Gapczynski 12 years ago
parent 195f6143a3
commit d50d663928
  1. 38
      lib/config.php
  2. 4
      lib/hintexception.php
  3. 30
      lib/legacy/config.php

@ -38,7 +38,7 @@ namespace OC;
/** /**
* This class is responsible for reading and writing config.php, the very basic * This class is responsible for reading and writing config.php, the very basic
* configuration file of owncloud. * configuration file of ownCloud.
*/ */
class Config { class Config {
// associative array key => value // associative array key => value
@ -63,7 +63,7 @@ class Config {
* does not return the values. * does not return the values.
*/ */
public function getKeys() { public function getKeys() {
return array_keys( $this->cache ); return array_keys($this->cache);
} }
/** /**
@ -75,8 +75,8 @@ class Config {
* This function gets the value from config.php. If it does not exist, * This function gets the value from config.php. If it does not exist,
* $default will be returned. * $default will be returned.
*/ */
public function getValue( $key, $default = null ) { public function getValue($key, $default = null) {
if( array_key_exists( $key, $this->cache )) { if (isset($this->cache[$key])) {
return $this->cache[$key]; return $this->cache[$key];
} }
@ -88,10 +88,10 @@ class Config {
* @param string $key key * @param string $key key
* @param string $value value * @param string $value value
* *
* This function sets the value and writes the config.php. If the file can * This function sets the value and writes the config.php.
* not be written, false will be returned. *
*/ */
public function setValue( $key, $value ) { public function setValue($key, $value) {
// Add change // Add change
$this->cache[$key] = $value; $this->cache[$key] = $value;
@ -103,13 +103,13 @@ class Config {
* @brief Removes a key from the config * @brief Removes a key from the config
* @param string $key key * @param string $key key
* *
* This function removes a key from the config.php. If owncloud has no * This function removes a key from the config.php.
* write access to config.php, the function will return false. *
*/ */
public function deleteKey( $key ) { public function deleteKey($key) {
if( array_key_exists( $key, $this->cache )) { if (isset($this->cache[$key])) {
// Delete key from cache // Delete key from cache
unset( $this->cache[$key] ); unset($this->cache[$key]);
// Write changes // Write changes
$this->writeData(); $this->writeData();
@ -123,7 +123,7 @@ class Config {
*/ */
private function readData() { private function readData() {
// read all file in config dir ending by config.php // read all file in config dir ending by config.php
$configFiles = glob( $this->configDir.'*.config.php'); $configFiles = glob($this->configDir.'*.config.php');
//Filter only regular files //Filter only regular files
$configFiles = array_filter($configFiles, 'is_file'); $configFiles = array_filter($configFiles, 'is_file');
@ -135,13 +135,13 @@ class Config {
array_unshift($configFiles, $this->configFilename); array_unshift($configFiles, $this->configFilename);
//Include file and merge config //Include file and merge config
foreach($configFiles as $file) { foreach ($configFiles as $file) {
if( !file_exists( $file) ) { if (!file_exists($file)) {
continue; continue;
} }
unset($CONFIG); unset($CONFIG);
include $file; include $file;
if( isset( $CONFIG ) && is_array( $CONFIG )) { if (isset($CONFIG) && is_array($CONFIG)) {
$this->cache = array_merge($this->cache, $CONFIG); $this->cache = array_merge($this->cache, $CONFIG);
} }
} }
@ -164,12 +164,12 @@ class Config {
$content .= ";\n"; $content .= ";\n";
// Write the file // Write the file
$result=@file_put_contents( $this->configFilename, $content ); $result = @file_put_contents( $this->configFilename, $content);
if(!$result) { if (!$result) {
throw new HintException( throw new HintException(
"Can't write into config directory 'config'", "Can't write into config directory 'config'",
'You can usually fix this by giving the webserver user write access' 'You can usually fix this by giving the webserver user write access'
.' to the config directory in owncloud'); .' to the config directory in ownCloud');
} }
// Prevent others not to read the config // Prevent others not to read the config
@chmod($this->configFilename, 0640); @chmod($this->configFilename, 0640);

@ -8,8 +8,8 @@
namespace OC; namespace OC;
class HintException extends \Exception class HintException extends \Exception {
{
private $hint; private $hint;
public function __construct($message, $hint, $code = 0, Exception $previous = null) { public function __construct($message, $hint, $code = 0, Exception $previous = null) {

@ -36,11 +36,13 @@
/** /**
* This class is responsible for reading and writing config.php, the very basic * This class is responsible for reading and writing config.php, the very basic
* configuration file of owncloud. * configuration file of ownCloud.
*/ */
OC_Config::$object = new \OC\Config(OC::$SERVERROOT.'/config/', defined('DEBUG') && DEBUG); OC_Config::$object = new \OC\Config(OC::$SERVERROOT.'/config/', defined('DEBUG') && DEBUG);
class OC_Config{ class OC_Config {
public static $object; public static $object;
/** /**
* @brief Lists all available config keys * @brief Lists all available config keys
* @return array with key names * @return array with key names
@ -61,8 +63,8 @@ class OC_Config{
* This function gets the value from config.php. If it does not exist, * This function gets the value from config.php. If it does not exist,
* $default will be returned. * $default will be returned.
*/ */
public static function getValue( $key, $default = null ) { public static function getValue($key, $default = null) {
return self::$object->getValue( $key, $default ); return self::$object->getValue($key, $default);
} }
/** /**
@ -70,14 +72,14 @@ class OC_Config{
* @param string $key key * @param string $key key
* @param string $value value * @param string $value value
* *
* This function sets the value and writes the config.php. If the file can * This function sets the value and writes the config.php.
* not be written, false will be returned. *
*/ */
public static function setValue( $key, $value ) { public static function setValue($key, $value) {
try { try {
self::$object->setValue( $key, $value ); self::$object->setValue($key, $value);
} catch (\OC\HintException $e) { } catch (\OC\HintException $e) {
\OC_Template::printErrorPage( $e->getMessage(), $e->getHint() ); \OC_Template::printErrorPage($e->getMessage(), $e->getHint());
} }
} }
@ -85,14 +87,14 @@ class OC_Config{
* @brief Removes a key from the config * @brief Removes a key from the config
* @param string $key key * @param string $key key
* *
* This function removes a key from the config.php. If owncloud has no * This function removes a key from the config.php.
* write access to config.php, the function will return false. *
*/ */
public static function deleteKey( $key ) { public static function deleteKey($key) {
try { try {
self::$object->deleteKey( $key ); self::$object->deleteKey($key);
} catch (\OC\HintException $e) { } catch (\OC\HintException $e) {
\OC_Template::printErrorPage( $e->getMessage(), $e->getHint() ); \OC_Template::printErrorPage($e->getMessage(), $e->getHint());
} }
} }
} }

Loading…
Cancel
Save