コード例 #1
0
ファイル: Cli.class.php プロジェクト: pthreat/apf-dev
 /**
  * Configure project directories.
  *
  * This interactive menu will allow the end user to configure several project directories.
  *
  * A) Configure the Project	directory, this is the base directory where the project will be located.
  * B) Configure the Modules	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\Config			A project configuration object
  * @params \apf\iface\Log						A log interface to display messages and prompts in the command line.
  *	@return \apf\core\project\Directories	A configured project directories object.
  *
  */
 public static function configure(&$config = NULL, LogInterface &$log)
 {
     $config = new ProjectDirectoriesConfig($config);
     $extraMenus = array('back', 'save', 'defaults', 'reset');
     do {
         try {
             $menu = DirectoriesHelper::getMenu($config, $valuesExcept = array('project'), $extraMenus);
             $allConfigured = $config->hasValuesExcept(array('project'));
             Cmd::clear();
             $log->debug("[ Configure project directories ]");
             $log->repeat('-', 80, 'light_purple');
             $opt = Cmd::selectWithKeys($menu, 'directories>', $log);
             switch (trim(strtolower($opt))) {
                 case 's':
                     try {
                         return new ProjectDirectories($config, $validate = 'soft');
                     } 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;
                 default:
                     if (DirectoriesHelper::switchMenuOption($opt, $config, $allConfigured, $log) === FALSE) {
                         return FALSE;
                     }
                     break;
             }
         } catch (\Exception $e) {
             $log->error($e->getMessage());
             Cmd::readInput('There are errors in your configuration');
         }
     } while (TRUE);
 }
コード例 #2
0
ファイル: Cli.class.php プロジェクト: pthreat/apf-dev
 public static function configure(&$config = NULL, LogInterface &$log)
 {
     $config = new Mysql5ConnectionConfig($config);
     do {
         Cmd::clear();
         $log->debug('[ Configure Mysql5 database connection ]');
         $log->repeat('-', 80, 'light_purple');
         $options = array('E' => array('color' => $config->getCharset() ? 'light_purple' : 'light_cyan', 'value' => sprintf('%s charset %s', $config->getCharset() ? 'Change' : 'Set', $config->getCharset() ? "({$config->getCharset()})" : "")), 'T' => array('color' => $config->getSocket() ? 'light_purple' : 'light_cyan', 'value' => sprintf('%s connection socket %s', $config->getSocket() ? 'Change' : 'Set', $config->getSocket() ? "({$config->getSocket()})" : "")), 'B' => 'Back');
         $options = NetConnectionCliConfig::getConfigurationMenu($config, $options);
         $opt = Cmd::selectWithKeys($options, '>', $log);
         switch (strtolower($opt)) {
             case 'e':
                 self::configureCharset($config, $log);
                 break;
             case 't':
                 self::configureSocket($config, $log);
                 break;
             case 'b':
                 $connection = new Mysql5Connection($config);
                 return $connection;
                 break;
             default:
                 NetConnectionCliConfig::configureConnection($opt, $config, $log);
                 break;
         }
     } while (TRUE);
 }
コード例 #3
0
ファイル: Cli.class.php プロジェクト: pthreat/apf-dev
 public static function configureMode(NetConfig &$config, LogInterface &$log)
 {
     $log->debug('[ Specify connection mode ]');
     $log->success('1 = Production');
     $log->warning('0 = Development');
     $config->setIsProduction(Cmd::readInput('mode>', $log));
 }
コード例 #4
0
ファイル: Cli.class.php プロジェクト: pthreat/apf-dev
 /**
  * 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);
 }
コード例 #5
0
ファイル: Cli.class.php プロジェクト: pthreat/apf-dev
 public static function addRoutesToObject(RouteableInterface &$object, LogInterface $log, $title = NULL, $help = NULL)
 {
     do {
         $currentRoutes = $object->getRoutes();
         $options = array('N' => 'New route');
         if (sizeof($currentRoutes)) {
             $log->repeat('-', 80, 'white');
             $log->debug('Current routes');
             $log->repeat('-', 80, 'white');
             foreach ($currentRoutes as $type => $routes) {
                 $log->debug("[ Routes ]");
                 foreach ($routes as $route) {
                     $log->success("> {$route}");
                 }
             }
             $options['E'] = 'Edit routes';
             $options['D'] = 'Delete routes';
         }
         $options['F'] = 'Finish adding routes';
         $options['H'] = 'Help';
         $log->warning($title);
         $opt = Cmd::selectWithKeys($options, 'route>', $log);
         switch (strtolower($opt)) {
             case 'n':
                 $eouteConfig = new RouteConfig();
                 $object->addRoute(Route::cliConfig($routeConfig, $log));
                 break;
             case 'e':
                 $log->debug('Edit routes');
                 break;
             case 'd':
                 $log->debug('Delete routes');
                 break;
             case 'f':
                 break 2;
                 break;
             case 'h':
                 $log->debug($help);
                 break;
         }
     } while (TRUE);
 }
コード例 #6
0
ファイル: Cli.class.php プロジェクト: pthreat/apf-dev
 public static function configure(&$config = NULL, LogInterface &$log)
 {
     $connectionConfig = new Mysql5ConnectionConfig();
     do {
         Cmd::clear();
         $log->debug('[ Configure MySQL 5 database adapter ]');
         $log->repeat('-', 80, 'light_purple');
         $options = array('S' => array('color' => $config->getAdapter() ? 'light_green' : 'light_cyan', 'value' => sprintf('%s connection parameters', $config->getAdapter() ? 'Change' : 'Set')));
         if ($config->getConnection()) {
             $options['T'] = 'Test connection';
         }
         $options['B'] = 'Back';
         $opt = Cmd::selectWithKeys($options, '>', $log);
         if ($config->getConnection()) {
             $connectionConfig = $config->getConnection()->getConfig();
         }
         switch (strtolower($opt)) {
             case 'c':
                 do {
                     try {
                         $config->setConnection(Mysql5ConnectionCliConfig::configure($connectionConfig, $log));
                         break;
                     } catch (\Exception $e) {
                         $log->debug('[You have errors in your connection configuration]');
                         $log->error($e->getMessage());
                         $opt = Cmd::selectWithKeys(array('A' => 'Abort connection configuration', 'C' => 'Correct errors'), '>', $log);
                         if (strtolower($opt) == 'a') {
                             break;
                         }
                     }
                 } while (TRUE);
                 break;
             case 'p':
                 echo $config->getConnection()->getConfig();
                 Cmd::readInput('Press enter to continue ...');
                 break;
             case 'b':
                 return new Adapter($config);
                 break 2;
                 break;
         }
     } while (TRUE);
 }
コード例 #7
0
ファイル: Cli.class.php プロジェクト: pthreat/apf-dev
 public static function configure(&$config = NULL, LogInterface &$log)
 {
     do {
         Cmd::clear();
         $log->debug('[ Select database connection type ]');
         if (!$config) {
             $options = Adapter::listAvailable();
             $options['B'] = 'Back';
             $opt = Cmd::selectWithKeys($options, '>', $log);
         }
         switch (strtolower($opt)) {
             case 'b':
                 break 2;
                 break;
             default:
                 $opt = $options[$opt];
                 $adapterClass = "\\apf\\db\\adapter\\{$opt}\\Adapter";
                 $adapterConfigClass = "\\apf\\db\\adapter\\{$opt}\\adapter\\Config";
                 $connectionClass = "\\apf\\db\\adapter\\{$opt}\\Connection";
                 $connectionConfigClass = "\\apf\\db\\adapter\\{$opt}\\connection\\Config";
                 $cliConfigClass = "\\apf\\db\\adapter\\{$opt}\\connection\\config\\Cli";
                 $connectionConfig = new $connectionConfigClass();
                 do {
                     try {
                         $connection = $cliConfigClass::configure($connectionConfig, $log);
                         $adapterConfig = new $adapterConfigClass();
                         $adapterConfig->setConnection($connection);
                         $adapter = new $adapterClass($adapterConfig);
                         $connectionConfig->setAdapter($adapter);
                         return $connection;
                     } catch (\Exception $e) {
                         $log->error($e->getMessage());
                         $opt = Cmd::selectWithKeys(array('A' => 'Abort', 'C' => 'Correct errors'), '>', $log);
                         if (strtolower($opt) == 'a') {
                             break 2;
                         }
                     }
                 } while (TRUE);
                 break;
         }
     } while (TRUE);
 }
コード例 #8
0
ファイル: Cli.class.php プロジェクト: pthreat/apf-dev
 public static function configure(&$config = NULL, LogInterface &$log)
 {
     $config = new ProjectConfig($config);
     $options = array('S' => 'Select database adapter', 'H' => 'Help', 'B' => 'Back');
     do {
         Cmd::clear();
         $log->debug('[Database adapter configuration]');
         $log->repeat('-', 80, 'light_purple');
         try {
             $option = Cmd::selectWithKeys($options, '>', $log);
             switch (strtolower($option)) {
                 case 's':
                     $adapter = self::configureAdapter($config, $log);
                     if ($adapter) {
                     }
                     break;
                 case 'h':
                     $log->debug('This menu will allow you to select an available database adapter for further configuration');
                     $log->debug('If your project already has configured adapters, an edit menu will appear which will enable ');
                     $log->debug('you to edit the selected adapter.');
                     $log->debug('Press C to configure a new adapter for your project.');
                     $log->debug('Press E to edit a pre existent adapter in your project.');
                     Cmd::readInput('Press any key to continue ...');
                     break;
                 case 'q':
                     break 2;
                     break;
                 default:
                     throw new \InvalidArgumentException("Invalid option selected: {$option}");
                     break;
             }
         } catch (\Exception $e) {
             $log->error($e->getMessage());
             Cmd::readInput('Press enter to continue ...', $log);
         }
     } while (TRUE);
 }
コード例 #9
0
ファイル: Cli.class.php プロジェクト: pthreat/apf-dev
 public static function configure(&$config = NULL, LogInterface &$log)
 {
     $projectOptions = array('C' => 'Create project', 'E' => 'Edit project', 'H' => 'Help', 'Q' => 'Quit');
     do {
         Cmd::clear();
         $log->debug('-[Apollo Framework interactive configuration]-');
         $log->repeat('-', 80, 'light_purple');
         try {
             $option = Cmd::selectWithKeys($projectOptions, 'apf>', $log);
             switch (strtolower($option)) {
                 case 'c':
                     self::configureProject($config, $log);
                     break;
                 case 'e':
                     $log->debug('Edit project, select project path and then load given project configuration');
                     Cmd::readInput('press enter ...');
                     break;
                 case 'h':
                     $log->debug('Given configuration interface will allow you to create or edit a new project.');
                     $log->debug('Press N to create a new project');
                     $log->debug('Press E to edit a project, in this case you will have to enter the path where the project is located');
                     Cmd::readInput('Press any key to continue ...');
                     break;
                 case 'q':
                     break 2;
                     break;
                 default:
                     throw new \InvalidArgumentException("Invalid option selected: {$option}");
                     break;
             }
         } catch (\Exception $e) {
             $log->error($e->getMessage());
             Cmd::readInput('Press enter to continue ...', $log);
         }
     } while (TRUE);
 }
コード例 #10
0
ファイル: Cli.class.php プロジェクト: pthreat/apf-dev
 public static function listAssets(AssetableInterface &$config, LogInterface $log)
 {
     $assets = $config->getAssetsOrderedByType();
     if (!$assets) {
         $log->warning('No assets available');
     }
     $log->repeat('-', 80, 'white');
     $log->debug('Current assets');
     $log->repeat('-', 80, 'white');
     foreach ($assets as $type => $assets) {
         $log->debug("[ {$type} Assets ]");
         foreach ($assets as $asset) {
             $log->success("> {$asset}");
         }
     }
 }