Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'core/Config.php')
-rw-r--r--core/Config.php90
1 files changed, 84 insertions, 6 deletions
diff --git a/core/Config.php b/core/Config.php
index 84851053ea..4801875131 100644
--- a/core/Config.php
+++ b/core/Config.php
@@ -20,6 +20,7 @@
* will read the value minimumMemoryLimit under the [General] section of the config file
*
* @package Piwik
+ * @subpackage Piwik_Config
*/
class Piwik_Config
{
@@ -37,7 +38,8 @@ class Piwik_Config
protected $pathIniFileDefaultConfig = null;
protected $configFileUpdated = false;
protected $doWriteFileWhenUpdated = true;
- protected $cachedConfigArray = array();
+ protected $cachedConfigArray = array();
+ protected $isTestEnvironment = false;
/**
* Storing the correct cwd() because the value is not correct in the destructor
@@ -104,12 +106,25 @@ class Piwik_Config
public function init()
{
- $this->defaultConfig = new Zend_Config_Ini($this->pathIniFileDefaultConfig, null, true);
- if(!Zend_Loader::isReadable($this->pathIniFileUserConfig))
+ if(!is_readable($this->pathIniFileDefaultConfig))
{
- throw new Exception("The configuration file {$this->pathIniFileUserConfig} has not been found.");
+ Piwik_ExitWithMessage(Piwik_TranslateException('General_ExceptionConfigurationFileNotFound', array($this->pathIniFileDefaultConfig)));
+ }
+ $this->defaultConfig = new Piwik_Config_Ini($this->pathIniFileDefaultConfig, null, true);
+ if(is_null($this->defaultConfig) || count($this->defaultConfig->toArray()) == 0)
+ {
+ Piwik_ExitWithMessage(Piwik_TranslateException('General_ExceptionUnreadableFileDisabledMethod', array($this->pathIniFileDefaultConfig, "parse_ini_file()")));
+ }
+
+ if(!is_readable($this->pathIniFileUserConfig))
+ {
+ throw new Exception(Piwik_TranslateException('General_ExceptionConfigurationFileNotFound', array($this->pathIniFileUserConfig)));
+ }
+ $this->userConfig = new Piwik_Config_Ini($this->pathIniFileUserConfig, null, true);
+ if(is_null($this->userConfig) || count($this->userConfig->toArray()) == 0)
+ {
+ Piwik_ExitWithMessage(Piwik_TranslateException('General_ExceptionUnreadableFileDisabledMethod', array($this->pathIniFileUserConfig, "parse_ini_file()")));
}
- $this->userConfig = new Zend_Config_Ini($this->pathIniFileUserConfig, null, true);
}
/**
@@ -154,16 +169,35 @@ class Piwik_Config
$configFile .= "\n";
}
chdir($this->correctCwd);
- file_put_contents($this->pathIniFileUserConfig, $configFile );
+ @file_put_contents($this->pathIniFileUserConfig, $configFile );
}
}
+ public function isFileWritable()
+ {
+ return is_writable($this->pathIniFileUserConfig);
+ }
+
/**
* If called, we use the database_tests credentials
*/
public function setTestEnvironment()
{
+ $this->isTestEnvironment = true;
$this->database = $this->database_tests->toArray();
+ // for unit tests, we set that no plugin is installed. This will force
+ // the test initialization to create the plugins tables, execute ALTER queries, etc.
+ $this->PluginsInstalled = array();
+ $this->disableSavingConfigurationFileUpdates();
+ }
+
+ /**
+ * Is the config file set to use the test values?
+ * @return bool
+ */
+ public function isTestEnvironment()
+ {
+ return $this->isTestEnvironment;
}
/**
@@ -294,3 +328,47 @@ class Piwik_Config
return $this->cachedConfigArray[$name];
}
}
+
+/**
+ * Subclasses Zend_Config_Ini so we can use our own parse_ini_file() wrapper.
+ *
+ * @package Piwik
+ * @subpackage Piwik_Config
+ */
+class Piwik_Config_Ini extends Zend_Config_Ini
+{
+ /**
+ * Handle any errors from parse_ini_file
+ *
+ * @param integer $errno
+ * @param string $errstr
+ * @param string $errfile
+ * @param integer $errline
+ */
+ public function _parseFileErrorHandler($errno, $errstr, $errfile, $errline)
+ {
+ $this->_loadFileErrorHandler($errno, $errstr, $errfile, $errline);
+ }
+
+ /**
+ * Load ini file configuration
+ *
+ * Derived from Zend_Config_Ini->_loadIniFile() and Zend_Config_Ini->_parseIniFile()
+ * @license New BSD License
+ *
+ * @param string $filename
+ * @return array
+ */
+ protected function _loadIniFile($filename)
+ {
+ set_error_handler(array($this, '_parseFileErrorHandler'));
+ $iniArray = _parse_ini_file($filename, true);
+ restore_error_handler();
+ // Check if there was an error while loading the file
+ if ($this->_loadFileErrorStr !== null) {
+ throw new Zend_Config_Exception($this->_loadFileErrorStr);
+ }
+
+ return $iniArray;
+ }
+}