Пример #1
0
 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
 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
 /**
  * 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);
 }
Пример #4
0
 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
 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;
 }
Пример #6
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);
 }
Пример #7
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());
 }
Пример #8
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');
 }
Пример #9
0
 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;
 }
Пример #10
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);
 }
Пример #11
0
 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);
 }
Пример #12
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);
 }
Пример #13
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}");
         }
     }
 }
Пример #14
0
 public function create(LogInterface $log)
 {
     $log->info("Creating project {$config->getName()}");
     $log->info('Creating project directory ...');
     $this->config->getDirectory()->create();
     $log->info('Creating modules directory ...');
     $this->config->getModulesDirectory()->create();
     $log->info('Creating modules ...');
     foreach ($this->config->getModules() as $module) {
         $module->create($log);
     }
     $log->success('Done creating project');
 }
Пример #15
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;
 }
Пример #16
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;
 }
Пример #17
0
 public function setLog(LogInterface $log)
 {
     $log->setPrepend('[' . __CLASS__ . ']');
     $this->logObj = $log;
     return $this;
 }
Пример #18
0
 public static function setLog(LogInterface &$log)
 {
     $log->setPrepend('[' . __CLASS__ . ']');
     self::$logObj = $log;
 }
Пример #19
0
 public function setLog(\apf\iface\Log &$logger)
 {
     $logger->setPrepend('[' . __CLASS__ . ']');
     $this->logger = $logger;
 }
Пример #20
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);
 }
Пример #21
0
 public static function input($prompt = NULL, LogInterface $log)
 {
     if (!is_null($prompt)) {
         $log->setNoLf();
         $log->setNoPrefix();
         $log->info($prompt);
     }
     $fp = fopen("php://stdin", 'r');
     $ret = fgets($fp, 1024);
     fclose($fp);
     if (!is_null($log)) {
         $log->usePrefix();
         $log->setLf();
     }
     return trim($ret);
 }