コード例 #1
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));
 }
コード例 #2
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);
 }
コード例 #3
0
ファイル: Cli.class.php プロジェクト: pthreat/apf-dev
 public static function configure(&$config = NULL, LogInterface &$log)
 {
     $config = new ControllerConfig($config);
     $log->info('[ Controller configuration ]');
     do {
         try {
             $config->setName(Cmd::readInput('name>', $log));
         } catch (\Exception $e) {
             $log->error($e->getMessage());
         }
     } while (!$config->getName());
     $controller = new Controller($config, $validate = 'soft');
     AssetCli::addAssetsToObject($config, 'Add project assets', 'Add assets at a controller level. This means that every asset you add here will be present in each acton of this controller', $log);
     do {
         $log->info('Add actions to your controller.');
         $opt = Cmd::selectWithKeys(array('N' => 'New Action', 'E' => 'End adding actions'), '>', $log);
         if (strtolower($opt) == 'e') {
             break;
         }
         $actionConfig = new ActionConfig();
         $actionConfig->setController($controller);
         $config->addAction(Action::cliConfig($actionConfig, $log));
     } while (TRUE);
     return $controller;
 }
コード例 #4
0
ファイル: Cli.class.php プロジェクト: pthreat/apf-dev
 public static function configure(&$config = NULL, LogInterface &$log)
 {
     $config = new RouteConfig($config);
     $log->info('[ Route configuration ]');
     do {
         try {
             $config->setName(Cmd::readInput('name>', $log));
         } catch (\Exception $e) {
             $log->error($e->getMessage());
         }
     } while (!$config->getName());
     $log->info('Add a nice description to this route, in this way, debugging will be a lot easier for you!');
     do {
         try {
             $config->setDescription(Cmd::readInput('description>', $log));
         } catch (\Exception $e) {
             $log->error($e->getMessage());
         }
     } while (!$config->getDescription());
     $log->info(sprintf('Enter the route path, for instance: %s', $config->getPath() ? $config->getPath() : '/users/:id/profile'));
     do {
         try {
             $config->setPath(Cmd::readInput('path>', $log));
         } catch (\Exception $e) {
             $log->error($e->getMessage());
         }
     } while (!$config->getPath());
     $route = new Route($config, $validate = 'soft');
     return $route;
 }
コード例 #5
0
ファイル: Nameable.trait.php プロジェクト: pthreat/apf-dev
 /**
  * Configure a Nameable object's name
  * Any Nameable configuration must have a configured name for it to make sense. 
  *
  * @params \apf\iface\config\Nameable	An object implementing the nameable interface
  * @params \apf\iface\Log					A log interface so we can display messages and prompts in the command line.
  * 
  */
 public static function configureName(NameableInterface &$config, LogInterface &$log)
 {
     do {
         Cmd::clear();
         $log->info('Configure name');
         $log->repeat('-', 80, 'light_purple');
         try {
             $config->setName(Cmd::readWithDefault('name>', $config->getName(), $log));
         } catch (\Exception $e) {
             $log->error($e->getMessage());
             Cmd::readInput('Press enter to continue ...');
         }
     } while (!$config->getName());
 }
コード例 #6
0
ファイル: Cli.class.php プロジェクト: pthreat/apf-dev
 public static function configure(&$config = NULL, LogInterface &$log)
 {
     $config = new ActionConfig($config);
     $log->info('[ Action configuration ]');
     do {
         try {
             $config->setName(Cmd::readInput('name>', $log));
         } catch (\Exception $e) {
             $log->error($e->getMessage());
         }
     } while (!$config->getName());
     $action = new Action($config, $validate = 'soft');
     $help = 'Add routes at an action level. Though is not recommended, an action can have many routes.';
     RouteCli::addRoutesToObject($config, $log, 'Add routes to action', $help);
     return $action;
 }
コード例 #7
0
ファイル: Cli.class.php プロジェクト: pthreat/apf-dev
 public static function assetConfiguration(AssetableInterface &$object, $title, $help, $log)
 {
     do {
         Cmd::clear();
         $options = array('AC' => 'Add CSS Asset', 'AJ' => 'Add Javascript Asset');
         $currentAssets = $object->getAssetsOrderedByType();
         if (sizeof($currentAssets)) {
             $options['EA'] = 'Edit assets';
             $options['DA'] = 'Delete assets';
             $options['LA'] = 'List assets';
         }
         $options['H'] = 'Help';
         $options['B'] = 'Back';
         $log->warning($title);
         $opt = Cmd::selectWithKeys($options, 'asset>', $log);
         switch (strtolower($opt)) {
             case 'ac':
                 $cssAssetConfig = new CssAssetConfig();
                 $object->addAsset(CSSAsset::cliConfig($cssAssetConfig, $log));
                 break;
             case 'aj':
                 $jsAssetConfig = new JSAssetConfig();
                 $object->addAsset(JSAsset::cliConfig($jsAssetConfig, $log));
                 break;
             case 'ea':
                 $log->debug('Edit assets');
                 break;
             case 'da':
                 $log->debug('Delete assets');
                 break;
             case 'la':
                 self::listAssets($object, $log);
                 Cmd::readInput('Press enter to continue ...', $log);
                 break;
             case 'b':
                 break 2;
                 break;
             case 'h':
                 $log->debug($help);
                 Cmd::readInput('Press enter to continue ...', $log);
                 break;
         }
     } while (TRUE);
 }
コード例 #8
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);
 }
コード例 #9
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);
 }
コード例 #10
0
 /**
  *
  * Configure the root directory for an object implementing the RootDirectory interface.
  *
  * @params \apf\iface\RootDirectoryInterface	An object implementing the root directory interface.
  * @params \apf\iface\Log							An object implementing the log interface.
  *
  */
 public static function configureRootDirectory(RootDirectoryInterface &$config, LogInterface &$log)
 {
     do {
         try {
             Cmd::clear();
             $log->info('[ Please specify the root directory ]');
             $log->repeat('-', 80, 'light_purple');
             $dir = $config->getRootDirectory();
             $hasDir = (bool) $dir;
             if ($hasDir) {
                 $log->success("Current value: {$config->getRootDirectory()}");
                 $log->repeat('-', 80, 'light_purple');
             }
             $options = array('C' => array('value' => sprintf('%s directory (%s)', $hasDir ? 'Change' : 'Set', $dir), 'color' => $hasDir ? 'light_purple' : 'light_cyan'));
             if ($hasDir) {
                 $options['R'] = array('value' => 'Reset value', 'color' => 'yellow');
             }
             $options['B'] = 'Back';
             $opt = Cmd::selectWithKeys($options, '>', $log);
             switch (strtolower($opt)) {
                 case 'r':
                     $config->unsetRootDirectory();
                     break;
                 case 'c':
                     $config->setRootDirectory(new Dir(Cmd::readWithDefault('>', $config->getRootDirectory(), $log)));
                     break;
                 case 'b':
                     break 2;
                     break;
             }
         } catch (\Exception $e) {
             $log->error($e->getMessage());
             Cmd::readInput('Press enter to continue ...');
         }
     } while (TRUE);
     return TRUE;
 }
コード例 #11
0
ファイル: Directories.trait.php プロジェクト: pthreat/apf-dev
 /**
  *
  * Configure the root directory for an object implementing the RootDirectory interface.
  *
  * @params \apf\iface\RootDirectoryInterface	An object implementing the root directory interface.
  * @params \apf\iface\Log							An object implementing the log interface.
  *
  */
 public static function configureModuleDirectories(ModuleDirectoriesInterface &$config, LogInterface &$log)
 {
     do {
         try {
             Cmd::clear();
             $log->info('[ Please specify the modules directory ]');
             $log->repeat('-', 80, 'light_purple');
             $log->info('Press \'<\' to go back | Press \'!\' to reset this option');
             $log->repeat('-', 80, 'light_purple');
             $dir = $config->getModulesDirectory();
             if ($dir) {
                 $log->success("Current value: {$config->getModulesDirectory()}");
                 $log->repeat('-', 80, 'light_purple');
             }
             if (!$dir) {
                 $dir = new Dir(realpath(getcwd()));
                 if ($config instanceof NameableInterface) {
                     $dir->addPath($config->getName());
                 }
             }
             $opt = trim(Cmd::readWithDefault('>', $dir, $log));
             if ($opt == '<') {
                 return;
             }
             if ($opt == '!') {
                 $config->unsetModulesDirectory();
                 continue;
             }
             $config->setModulesDirectory(new Dir($opt));
         } catch (\Exception $e) {
             $log->error($e->getMessage());
             Cmd::readInput('Press enter to continue ...');
         }
     } while (!$config->getModulesDirectory());
     return TRUE;
 }
コード例 #12
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);
 }
コード例 #13
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);
 }