Ejemplo n.º 1
0
 public function configureDatabases($saveAs = NULL)
 {
     $flag = TRUE;
     do {
         $config = DatabaseConfig::consoleConfig($this->log);
         $log->success('[Database settings]');
         $log->info($config);
         if (Cmd::yesNo('Would you like to test this connection?')) {
             try {
                 $config->testConnection();
                 $log->success('Connection succesfully established!');
                 $config->save(new File(sprintf('%s%s%s%s', $dir, DIRECTORY_SEPARATOR, $config->getDatabase(), $config->isProduction() ? '_prod' : '_dev')));
                 $log->info(sprintf('Saving config file to %s ...', $dir));
             } catch (\Exception $e) {
                 $log->error('Connection Failed!');
                 $log->warning($e->getMessage());
                 $log->debug($e->getTraceAsString());
                 if (Cmd::yesNo('Would you like to try again and reconfigure?', $log)) {
                     continue;
                 }
             }
         }
         $flag = Cmd::yesNo('Configure another database?', $log);
     } while ($flag);
 }
Ejemplo n.º 2
0
 /**
  * Configure module directories.
  *
  * This interactive menu will allow the end user to configure several module directories.
  *
  * A) Configure the Module		directory, this is the base directory where the module will be located.
  * B) Configure the Subs		directory, this is the directory where modules will be in.
  * C) Configure the Templates directory, this is the directory where global templates will be stored.
  * D) Configure the Fragments directory, this is the directory where global fragments will be stored.
  *
  * @params \apf\core\project\module\directories\Config	A module directories configuration object.
  * @params \apf\iface\Log											A log interface to display messages and prompts in the command line.
  *	@return \apf\core\project\module\Directories				A configured module directories object.
  *	@return boolean	FALSE											If the user aborts the configuration process.
  *
  */
 public static function configure(&$config = NULL, LogInterface &$log)
 {
     $config = new ModuleDirectoriesConfig($config);
     do {
         try {
             $allConfigured = $config->getRootDirectory() && $config->getFragmentsDirectory() && $config->getTemplatesDirectory() && $config->getSubsDirectory();
             $menu = array('R' => array('value' => sprintf('Configure root directory (%s)', $config->getRootDirectory()), 'color' => $config->getRootDirectory() ? 'light_purple' : 'light_cyan'), 'T' => array('value' => sprintf('Configure templates directory (%s)', $config->getTemplatesDirectory()), 'color' => $config->getTemplatesDirectory() ? 'light_purple' : 'light_cyan'), 'F' => array('value' => sprintf('Configure fragments directory (%s)', $config->getFragmentsDirectory()), 'color' => $config->getFragmentsDirectory() ? 'light_purple' : 'light_cyan'), 'U' => array('value' => sprintf('Configure subs directory (%s)', $config->getSubsDirectory()), 'color' => $config->getSubsDirectory() ? 'light_purple' : 'light_cyan'), 'D' => array('value' => 'Set defaults', 'color' => $allConfigured ? 'yellow' : 'light_green'), 'S' => 'Save', 'B' => 'Back');
             Cmd::clear();
             $log->debug("[ Configure module directories ]");
             $log->repeat('-', 80, 'light_purple');
             $opt = Cmd::selectWithKeys($menu, 'directories>', $log);
             switch (trim(strtolower($opt))) {
                 case 'r':
                     self::configureRootdirectory($config, $log);
                     break;
                 case 't':
                     self::configureTemplateDirectories($config, $log);
                     break;
                 case 'f':
                     self::configureFragmentDirectories($config, $log);
                     break;
                 case 'u':
                     self::configureSubDirectories($config, $log);
                     break;
                 case 's':
                     try {
                         return new ModuleDirectories($config);
                     } catch (\Exception $e) {
                         $log->warning("There are errors in your configuration.");
                         $log->error($e->getMessage());
                         $log->debug("Please correct the error mentioned above and try saving again.");
                         Cmd::readInput('Press enter to continue ...', $log);
                     }
                     break;
                 case 'd':
                     if ($allConfigured) {
                         $log->warning('Everything seems to be configured, are you sure you want to set defaults?');
                         Cmd::yesNo('>', $log);
                     }
                     self::setDefaults($config);
                     break;
                 case 'b':
                     //No values, assume safe "back"
                     if (!$config->hasValues()) {
                         break 2;
                     }
                     $log->warning("You have unsaved changes in this configuration.");
                     if (Cmd::yesNo("Are you sure you want to go back without saving?", $log)) {
                         break 2;
                     }
                     break;
             }
         } catch (\Exception $e) {
             $log->error($e->getMessage());
             Cmd::readInput('There are errors in your configuration');
         }
     } while (TRUE);
 }
Ejemplo n.º 3
0
 public static function switchMenuOption($opt, &$config, $allConfigured = FALSE, LogInterface &$log)
 {
     switch (trim(strtolower($opt))) {
         case 'r':
             self::configureRootdirectory($config, $log);
             break;
         case 'e':
             if ($config->hasValues() && Cmd::yesNo('Are you sure you want to reset the entire configuration?', $log)) {
                 self::reset($config);
             }
             break;
         case 't':
             self::configureTemplateDirectories($config, $log);
             break;
         case 'f':
             self::configureFragmentDirectories($config, $log);
             break;
         case 'm':
             self::configureModuleDirectories($config, $log);
             break;
         case 'u':
             self::configureSubDirectories($config, $log);
             break;
         case 'b':
             //No values, assume safe "back"
             if (!$config->hasValuesExcept('project') || $allConfigured) {
                 return FALSE;
             }
             $log->warning("You have unsaved changes in this configuration.");
             if (Cmd::yesNo("Are you sure you want to go back without saving?", $log)) {
                 return FALSE;
             }
             break;
         case 'l':
             if (!$config->hasValues() || $allConfigured) {
                 $log->warning("You have configured some directories");
                 if (!Cmd::yesNo("Are you sure you want to load the default values?", $log)) {
                     return;
                 }
             }
             self::defaults($config);
             break;
     }
 }