Exemplo n.º 1
0
 /**
  * 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);
 }
Exemplo n.º 2
0
 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);
 }
Exemplo n.º 3
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);
 }
Exemplo n.º 4
0
 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);
 }
Exemplo n.º 5
0
 /**
  * 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());
 }
Exemplo n.º 6
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;
 }
Exemplo n.º 7
0
 /**
  * Configures a Module configuration object.
  *
  * @params \apf\core\project\module\Config	$config a module configuration to be edited (optional).
  * @params \apf\iface\Log							$log    a log object to display configuration messages.
  * @return \apf\core\project\Module				returns a configurated module.
  * @return boolean FALSE							if the user aborts the configuration process.
  */
 public static function configure(&$config = NULL, LogInterface &$log)
 {
     $isNew = $config === NULL;
     $config = new ModuleConfig($config);
     $project = $config->getProject();
     if (!$project) {
         throw new \LogicException("Given module configuration has no assigned project");
     }
     if (!$project->getConfig()) {
         throw new \LogicException("Passed project has not been properly configured");
     }
     $projectConfig = $project->getConfig();
     $module = new Module($config, $validate = 'none');
     do {
         Cmd::clear();
         $log->logArray(array("Project {$projectConfig->getName()}", "modules", $isNew ? 'create' : 'edit', $isNew ? '' : " > {$config->getName()}"), ' > ', 'light_purple');
         $log->repeat('-', 80, 'light_purple');
         $hasSubs = $config->hasSubs();
         $options = array('N' => array('value' => sprintf('%s module name (%s)', $config->getName() ? 'Change' : 'Set', $config->getName()), 'color' => $config->getName() ? 'light_purple' : 'light_cyan'), 'D' => "Configure module directories", 'S' => "Configure subs");
         if ($hasSubs) {
             $options['LS'] = 'List subs';
         }
         $options['B'] = 'Back';
         $opt = Cmd::selectWithKeys($options, '>', $log);
         switch (strtolower($opt)) {
             case 'n':
                 self::configureName($config, $log);
                 break;
             case 'd':
                 if (!$config->getName()) {
                     throw new \LogicException("You must configure the module name before configuring directories");
                 }
                 $directoriesConfig = $config->getDirectories() ? $config->getDirectories()->getConfig() : new DirectoriesConfig($noConfig = NULL);
                 $directoriesConfig->setModule($module);
                 $directoriesConfig = Directories::cliConfig($directoriesConfig, $log);
                 if ($directoriesConfig) {
                     $config->setDirectories($directoriesConfig);
                 }
                 break;
             case 's':
                 self::configureSubs($config, $log);
                 break;
             case 'b':
                 break 2;
                 break;
         }
     } while (TRUE);
     return new Module($config, $validate = 'soft');
 }
Exemplo n.º 8
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 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;
 }
Exemplo n.º 9
0
 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);
 }
Exemplo n.º 10
0
 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);
 }
Exemplo n.º 11
0
 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);
 }
Exemplo n.º 12
0
 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}");
         }
     }
 }