Example #1
0
 protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
 {
     $application = $input->getArgument('application');
     // TODO: this should be USER or optionally GROUP/USER or ALL when generating everything
     $directories = $input->getArgument('directories');
     $files = array();
     foreach ($directories as $dir) {
         $filelist = FileOperation::getAllFilesByExtension(Paths::$db . Paths::$separator . Paths::$defaultGroup . Paths::$separator . $dir, 'yml');
         if ($filelist !== false) {
             $files = array_merge($files, $filelist);
         } else {
             user_error('No such site: ' . $dir, E_USER_WARNING);
             //return false;
         }
     }
     //ApplicationsDB::LoadAll();
     $configScopes = ApplicationsDB::LoadApplication($application);
     $settingsDB = new ConfigScopes\SettingsDB();
     // merging the defaults
     $settingsDB->mergeFromYAML(Paths::$db . Paths::$separator . Paths::$hypoconf . Paths::$separator . Paths::$defaultUser . Paths::$separator . 'config.yml', false, true, true);
     //true for compilation
     // merging the files
     $settingsDB->mergeFromYAMLs($files, 'nginx/server', true, true, false, true);
     //true for compilation
     //var_dump($settingsDB->DB);
     ApplicationsDB::LoadConfig($settingsDB->DB);
     $parsedFile = $configScopes->parseTemplateRecursively($application);
     //        echo PHP_EOL.$parsedFile;
     $output->writeln($parsedFile);
 }
Example #2
0
 protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
 {
     $application = $input->getArgument('application');
     //        $output->writeln('Hello World!');
     LogCLI::Message('Listing available settings: ', 0);
     $configScopesNginx = ApplicationsDB::LoadApplication($application);
     //        $settingsNginx = ApplicationsDB::GetSettingsList('nginx', 'server');
     $settingsNginx = ApplicationsDB::GetSettingsList($application);
     $settings = ArrayTools::GetMultiDimentionalElements($settingsNginx, true, true);
     //        $settings = ArrayTools::GetMultiDimentionalElementsWithChildren(&$settingsNginx);
     foreach ($settings as $setting) {
         LogCLI::MessageResult(LogCLI::BLUE . $setting, 0, LogCLI::INFO);
     }
     LogCLI::Result(LogCLI::OK);
 }
Example #3
0
 public static function GenerateParsed($arguments)
 {
     $configScopesNginx = ApplicationsDB::LoadApplication('nginx');
     foreach ($arguments['file'] as $dir) {
         $fileslist = FileOperation::getAllFilesByExtension(Paths::$db . Paths::$separator . Paths::$defaultGroup . Paths::$separator . $dir, 'yml');
         if (!isset($fileslist) || $fileslist !== false) {
             foreach ($fileslist as $file) {
                 $files[] = $file;
             }
         } else {
             //            user_error('No such site: '.$arguments['file'], E_USER_ERROR);
             user_error('No such site: ' . $dir, E_USER_WARNING);
             return false;
         }
     }
     $nginx = new ConfigScopes\SettingsDB();
     $nginx->mergeFromYAML(Paths::$db . Paths::$separator . Paths::$hypoconf . Paths::$separator . Paths::$defaultUser . Paths::$separator . 'config.yml', false, true, true);
     //true for compilation
     $nginx->mergeFromYAMLs($files, 'server', true, true);
     //true for compilation
     ApplicationsDB::LoadConfig(&$nginx->DB);
     $parsedFile = $configScopesNginx->parseTemplateRecursively('nginx');
     echo PHP_EOL . $parsedFile;
 }
Example #4
0
 protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
 {
     $name = $input->getArgument('name');
     $settingPath = $input->getArgument('path');
     $values = $input->getArgument('values');
     //        $multiline = $input->getOption('multiline');
     if (empty($values)) {
         // enable multiline input
         $dialog = $this->getHelperSet()->get('dialog');
         if (!$dialog->askConfirmation($output, '<question>Would you like to provide multiline input? Answering no, quits the command. (y/n) </question> ', false)) {
             return;
         } else {
             $input = array();
             $output->writeln('Type <info>EOT</info> in a new line when you finished inputting all the options.');
             while (1) {
                 $input[] = $dialog->ask($output, null, 'foo');
                 if (end($input) == 'EOT') {
                     array_pop($input);
                     break;
                 }
             }
             $values[] = implode(PHP_EOL, $input);
             //                $values = $input;
             //var_dump($values);
         }
     }
     ApplicationsDB::LoadAll();
     foreach (StringTools::TypeList($name) as $argument) {
         if ($argument['exclamation'] !== false) {
             // TODO: actually handle the exclamators
             LogCLI::MessageResult('Exclamation: ' . $argument['exclamation'], 4, LogCLI::INFO);
         } else {
             //siteYML
             $file = Paths::getFullPath($argument['text']);
             if ($file !== false) {
                 $application = 'nginx';
                 $basicScope = 'server';
                 $settings = ApplicationsDB::GetSettingsList($application, $basicScope);
                 $value = ArrayTools::dearraizeIfNotRequired($values);
                 //$chain = StringTools::Delimit($chain, '.');
                 //$settingPath = implode('/', $chain);
                 LogCLI::MessageResult('Path of the setting: ' . $settingPath, 4, LogCLI::INFO);
                 if ($path = SettingsDB::findPathForSetting($settings, $settingPath, $basicScope)) {
                     $settingsDB = new ConfigScopes\SettingsDB();
                     // load the original file first
                     $settingsDB->mergeFromYAML($file);
                     $currentSetting = $settingsDB->returnOneByPath($settingPath);
                     /**
                      * if there is a difference
                      * TODO: probably dearraize not required here
                      */
                     if (ArrayTools::dearraizeIfNotRequired($currentSetting) != $value) {
                         $formatter = $this->getHelperSet()->get('xformatter');
                         $displayValues = array();
                         foreach ($values as $valueLine) {
                             $displayValues = array_merge($displayValues, StringTools::multilineStringToArray($valueLine));
                         }
                         $displayCurrentSetting = array();
                         foreach ((array) $currentSetting as $valueLine) {
                             $displayCurrentSetting = array_merge($displayCurrentSetting, StringTools::multilineStringToArray($valueLine));
                         }
                         $toFormat = array(array('messages' => $displayCurrentSetting, 'style' => 'error'), array('messages' => array('> >'), 'style' => 'fg=yellow;bg=black;other=blink;other=bold', 'large' => false), array('messages' => $displayValues, 'style' => 'fg=black;bg=yellow;other=bold'));
                         //array_merge(array('With the following data:'), (array) $values)
                         $output->writeln($formatter->formatMultipleBlocks($toFormat, ' ', true));
                         $dialog = $this->getHelperSet()->get('dialog');
                         if (!$dialog->askConfirmation($output, 'Are you sure that you want to make this change? (type "y" to confirm) ', false)) {
                             return;
                         }
                         // make the tree
                         $setting = Tree::addToTreeAndSet(explode('/', $path), $value);
                         //var_dump($setting);
                         // add/replace the setting
                         $settingsDB->mergeFromArray($setting);
                         // save the file with the new setting
                         $settingsDB->returnYAML($file);
                     } else {
                         /**
                          * nothing to do, it's all the same
                          */
                         $output->writeln('<fg=yellow;other=bold>No need to change, the values are already identical!</fg=yellow;other=bold>');
                     }
                 } else {
                     // TODO
                 }
             } else {
                 LogCLI::Fail('Sorry, no site by name: ' . $argument['text']);
             }
         }
     }
 }