Exemplo n.º 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));
 }
Exemplo n.º 2
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.º 3
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.º 4
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.º 5
0
 public static function configureProject(&$config, LogInterface &$log)
 {
     $title = $config ? sprintf('Edit project < %s >', $config->getName()) : 'New project';
     $config = new ProjectConfig($config);
     $project = new Project($config, $validate = 'none');
     do {
         Cmd::clear();
         $hasName = $config->getName();
         $directoriesConfigured = $config->getDirectories() && $config->getDirectories()->isValidated();
         $options = array('N' => array('value' => sprintf('Project name (%s)', $hasName ? $config->getName() : ''), 'color' => $hasName ? 'light_green' : 'yellow'), 'D' => array('value' => sprintf('Directories %s', $directoriesConfigured ? '(configured)' : $hasName ? '' : '(Set project name first)'), 'color' => $directoriesConfigured ? 'light_green' : ($hasName ? 'yellow' : 'gray')), 'C' => 'Connections', 'A' => 'Assets');
         $enableModulesEntry = $hasName && $config->getDirectories();
         $modulesColor = $enableModulesEntry ? 'yellow' : 'gray';
         $options['M'] = array('color' => $modulesColor, 'value' => $enableModulesEntry ? 'Modules' : 'Modules (configure name and directories first)');
         $options['S'] = 'Save';
         $options['B'] = 'Back';
         try {
             Cmd::clear();
             $log->success("[ {$title} ]");
             $log->repeat('-', '80', 'light_purple');
             $log->debug("Project {$config->getName()}>");
             $log->repeat('-', '80', 'light_purple');
             $option = Cmd::selectWithKeys($options, '>', $log);
             switch (strtolower($option)) {
                 //Configure project name
                 case 'n':
                     self::configureName($config, $log);
                     break;
                     //Configure Assets
                 //Configure Assets
                 case 'a':
                     $help = 'Add assets at a project level. This means that every asset you add here will be ';
                     $help = sprintf('%s present in each controller or action', $help);
                     AssetCli::assetConfiguration($config, 'Project assets', $help, $log);
                     break;
                     //Configure project directories
                 //Configure project directories
                 case 'd':
                     if (!$hasName) {
                         throw new \LogicException("You must configure the project name before configuring directories");
                     }
                     $projectDirectoriesConfig = $config->getDirectories() ? $config->getDirectories()->getConfig() : new ProjectDirectoriesConfig($noConfig = NULL);
                     $projectDirectoriesConfig->setProject($project);
                     $projectDirectoriesConfig = ProjectDirectories::cliConfig($projectDirectoriesConfig, $log);
                     if ($projectDirectoriesConfig) {
                         $config->setDirectories($projectDirectoriesConfig);
                     }
                     break;
                     //Configure connections
                 //Configure connections
                 case 'c':
                     self::configureConnections($config, $log);
                     break;
                     //Add modules to the project
                 //Add modules to the project
                 case 'm':
                     if (!$enableModulesEntry) {
                         throw new \LogicException("You must configure project name and directories before adding any modules");
                     }
                     self::configureModules($project, $log);
                     break;
                 case 'b':
                     break 2;
                     break;
                 default:
                     throw new \InvalidArgumentException("Invalid option selected");
                     break;
             }
         } catch (\Exception $e) {
             $log->error($e->getMessage());
             $log->debug($e->getTraceAsString());
             Cmd::readInput('Press enter to continue ...', $log);
         }
     } while (TRUE);
     return;
 }
Exemplo n.º 6
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}");
         }
     }
 }