Example #1
0
 /**
  * Get configuration by key
  */
 public function getAction()
 {
     // check for help mode
     if ($this->requestOptions->getFlagHelp()) {
         return $this->getHelp();
     }
     // output header
     $this->consoleHeader('Fetching requested configuration');
     // get needed options to shorten code
     $path = realpath($this->requestOptions->getPath());
     $configName = $this->requestOptions->getConfigName();
     $flagLocal = $this->requestOptions->getFlagLocal();
     // check for config name
     if (!$configName) {
         return $this->sendError('config get <configName> was not provided');
     }
     // check for local file
     if ($flagLocal) {
         $configFile = $path . '/config/autoload/local.php';
         // check if local config file exists
         if (!file_exists($configFile)) {
             return $this->sendError('Local config file ' . $configFile . ' does not exist.');
         }
     } else {
         $configFile = $path . '/config/application.config.php';
     }
     // fetch config data
     $configData = (include $configFile);
     // check if local config file exists
     if (empty($configData)) {
         return $this->sendError('Config file ' . $configFile . ' is empty.');
     }
     // start output
     $this->console->write('       => Reading configuration file ');
     $this->console->writeLine($configFile, Color::GREEN);
     $this->console->writeLine();
     // find value in array
     $configValue = ModuleConfig::findValueInArray($configName, $configData);
     // start output
     $this->console->write(' Done ', Color::NORMAL, Color::CYAN);
     $this->console->write(' ');
     $this->console->write('Configuration data for key ');
     $this->console->writeLine($configName, Color::GREEN);
     $this->console->writeLine();
     // check config value
     if (is_array($configValue)) {
         $iniWriter = new IniWriter();
         $this->console->writeLine(str_pad('', $this->console->getWidth() - 1, '=', STR_PAD_RIGHT));
         $this->console->writeLine(trim($iniWriter->toString($configValue)));
         $this->console->writeLine(str_pad('', $this->console->getWidth() - 1, '=', STR_PAD_RIGHT));
     } elseif (is_null($configValue)) {
         $this->console->writeLine('       => NULL');
     } else {
         $this->console->writeLine('       => ' . $configValue);
     }
     // output footer
     $this->consoleFooter('requested configuration was successfully displayed');
 }