Пример #1
0
 /**
  * Parse from path
  *
  * Parses a given file according to the specified options
  *
  * @param string $path    Path to file
  * @param array  $options Parsing options
  * @return array
  */
 public function parseFromPath($path, array $options = [])
 {
     $result = [];
     $this->validatePath($path);
     // Overwrite defaults
     if (!empty($options)) {
         $this->options = $options;
     }
     $reader = new IniReader();
     $result = $reader->readFile($path);
     return $result;
 }
Пример #2
0
 public function getConfigValuesFromFiles()
 {
     $ini = $this->settings->getIniFileChain();
     $descriptions = $this->iniReader->readComments($this->settings->getPathGlobal());
     $copy = array();
     foreach ($ini->getAll() as $category => $values) {
         if ($this->shouldSkipCategory($category)) {
             continue;
         }
         $local = $this->getFromLocalConfig($category);
         if (empty($local)) {
             $local = array();
         }
         $global = $this->getFromGlobalConfig($category);
         if (empty($global)) {
             $global = array();
         }
         $copy[$category] = array();
         foreach ($values as $key => $value) {
             $newValue = $value;
             if ($this->isKeyAPassword($key)) {
                 $newValue = $this->getMaskedPassword();
             }
             $defaultValue = null;
             if (array_key_exists($key, $global)) {
                 $defaultValue = $global[$key];
             }
             $description = '';
             if (!empty($descriptions[$category][$key])) {
                 $description = trim($descriptions[$category][$key]);
             }
             $copy[$category][$key] = array('value' => $newValue, 'description' => $description, 'isCustomValue' => array_key_exists($key, $local), 'defaultValue' => $defaultValue);
         }
     }
     return $copy;
 }
Пример #3
0
 /**
  * Merge provided config with config from file
  *
  * @throws IniReadingException
  */
 public function getConfig(InputInterface $input)
 {
     if (!$this->config) {
         $iniReader = new IniReader();
         try {
             $config = $iniReader->readFile($this->getAppConfigPath());
             $this->config = $config['default'];
             foreach ($input->getOptions() as $option => $value) {
                 if ($value) {
                     $this->config[$option] = $value;
                 }
             }
         } catch (IniReadingException $e) {
             $this->getOutput()->writeln('<error>Unable to read config. Try running `configure` again.</error>');
         }
     }
     return $this->config;
 }
Пример #4
0
 public function dropDatabase($dbName = null)
 {
     $dbName = $dbName ?: $this->dbName ?: self::getConfig()->database_tests['dbname'];
     $this->log("Dropping database '{$dbName}'...");
     $iniReader = new IniReader();
     $config = $iniReader->readFile(PIWIK_INCLUDE_PATH . '/config/config.ini.php');
     $originalDbName = $config['database']['dbname'];
     if ($dbName == $originalDbName && $dbName != 'piwik_tests') {
         // santity check
         throw new \Exception("Trying to drop original database '{$originalDbName}'. Something's wrong w/ the tests.");
     }
     try {
         DbHelper::dropDatabase($dbName);
     } catch (Exception $e) {
         printf("Dropping database %s failed: %s\n", $dbName, $e->getMessage());
     }
 }
Пример #5
0
 /**
  * Reloads settings from disk.
  */
 public function reload($defaultSettingsFiles = array(), $userSettingsFile = null)
 {
     if (!empty($defaultSettingsFiles) || !empty($userSettingsFile)) {
         $this->resetSettingsChain($defaultSettingsFiles, $userSettingsFile);
     }
     $reader = new IniReader();
     foreach ($this->settingsChain as $file => $ignore) {
         if (is_readable($file)) {
             try {
                 $contents = $reader->readFile($file);
                 $this->settingsChain[$file] = $this->decodeValues($contents);
             } catch (IniReadingException $ex) {
                 throw new IniReadingException('Unable to read INI file {' . $file . '}: ' . $ex->getMessage() . "\n Your host may have disabled parse_ini_file().");
             }
             $this->decodeValues($this->settingsChain[$file]);
         }
     }
     $this->mergedSettings = $this->mergeFileSettings();
 }
Пример #6
0
 /**
  * Reloads settings from disk.
  */
 public function reload($defaultSettingsFiles = array(), $userSettingsFile = null)
 {
     if (!empty($defaultSettingsFiles) || !empty($userSettingsFile)) {
         $this->resetSettingsChain($defaultSettingsFiles, $userSettingsFile);
     }
     $reader = new IniReader();
     foreach ($this->settingsChain as $file => $ignore) {
         if (is_readable($file)) {
             try {
                 $contents = $reader->readFile($file);
                 $this->settingsChain[$file] = $this->decodeValues($contents);
             } catch (IniReadingException $ex) {
                 $message = Piwik::translate('General_ExceptionUnreadableFileDisabledMethod', array($file, "parse_ini_file()"));
                 throw new IniReadingException($message, $code = 0, $ex);
             }
         }
     }
     $this->mergedSettings = $this->mergeFileSettings();
 }
Пример #7
0
 public function setUp()
 {
     $iniReader = new IniReader();
     $this->globalConfig = $iniReader->readFile(PIWIK_PATH_TEST_TO_ROOT . '/config/global.ini.php');
     parent::setUp();
 }
Пример #8
0
 /**
  * Reloads settings from disk.
  */
 public function reload($defaultSettingsFiles = array(), $userSettingsFile = null)
 {
     if (!empty($defaultSettingsFiles) || !empty($userSettingsFile)) {
         $this->resetSettingsChain($defaultSettingsFiles, $userSettingsFile);
     }
     $reader = new IniReader();
     foreach ($this->settingsChain as $file => $ignore) {
         if (is_readable($file)) {
             try {
                 $contents = $reader->readFile($file);
                 $this->settingsChain[$file] = $this->decodeValues($contents);
             } catch (IniReadingException $ex) {
                 throw new IniReadingException('Unable to read INI file {' . $file . '}: ' . $ex->getMessage() . "\n Your host may have disabled parse_ini_file().");
             }
             $this->decodeValues($this->settingsChain[$file]);
         }
     }
     $merged = $this->mergeFileSettings();
     // remove reference to $this->settingsChain... otherwise dump() or compareElements() will never notice a difference
     // on PHP 7+ as they would be always equal
     $this->mergedSettings = $this->copy($merged);
 }
 public function readConfig()
 {
     $reader = new IniReader();
     $this->config = $reader->readFile($this->configFilename);
 }