Exemplo n.º 1
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');
 }
Exemplo n.º 2
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;
 }
Exemplo n.º 3
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;
 }
Exemplo n.º 4
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.º 5
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.º 6
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;
 }
Exemplo n.º 7
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.º 8
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);
 }
Exemplo n.º 9
0
 /**
  *
  * List modules that belong to a project.
  *
  * This method allows the end user to view which modules does the project has assigned.
  *
  * @params \apf\core\project\Config	A project configuration object
  * @params \apf\iface\Log           A log interface so we can display messages and prompts in the command line.
  *
  */
 public static function listModules(ProjectConfig &$config, LogInterface $log)
 {
     $modules = $config->getModules();
     if (!sizeof($modules)) {
         $log->warning('Given project configuration has no modules assigned');
     }
     foreach ($modules as $module) {
         $log->info($module);
     }
 }