Ejemplo n.º 1
0
 public function __construct(array $config = [])
 {
     $this->climate = new CLImate();
     self::$CI =& get_instance();
     $this->climate->setArgumentManager(new Console\Arguments\Manager());
     $this->climate->extend(Console\Extensions\Tab::class, 'tab');
     $this->climate->arguments->description('Yet another Codeigniter Starter Application');
     $this->add_global_commands($this);
     if (!empty($config['available_commands']) && is_array($config['available_commands'])) {
         $this->addCommands($config['available_commands']);
     }
 }
Ejemplo n.º 2
0
 public function __construct(array $config = [])
 {
     $this->climate = new CLImate();
     self::$CI =& get_instance();
     $this->climate->addArt($config['art_directory']);
     $this->climate->setArgumentManager(new Arguments\Manager());
     $this->climate->extend(Extensions\Tab::class, 'tab');
     $this->climate->arguments->description('Yet another Codeigniter Starter Application');
     $this->climate->arguments->add(['help' => ['prefix' => 'h', 'longPrefix' => 'help', 'description' => static::lang('console_display_help'), 'noValue' => true]]);
     if (!empty($config['available_commands']) && is_array($config['available_commands'])) {
         $this->addCommands($config['available_commands']);
     }
 }
Ejemplo n.º 3
0
 /**
  * Call cli
  *
  * @param array $argv
  *
  * @throws BaseException
  * @throws MissingMethodException
  */
 private function callCli(array $argv)
 {
     if ($this->getRouter()->isMatched()) {
         $cliMethod = 'cliMethod';
         $cliConfig = 'cliConfig';
         $actionNamespace = $this->getRouter()->getActionNamespace();
         $reflection = new ReflectionClass($actionNamespace);
         if (!$reflection->implementsInterface('App\\Action\\AppAction')) {
             throw new BaseException(sprintf('"%s" action must extend "App\\Action\\AppAction"', $actionNamespace));
         }
         // Check Action::cliMethod exist or callable
         if (method_exists($actionNamespace, $cliMethod) && is_callable([$actionNamespace, $cliMethod])) {
             $responderNamespace = $this->getRouter()->getResponderNamespace();
             $responder = null;
             $reflection = new ReflectionClass($responderNamespace);
             if (class_exists($responderNamespace) && $reflection->implementsInterface('App\\Responder\\AppResponder')) {
                 $responder = new $responderNamespace();
             }
             /** @var ContainerAwareInterface|EventSubscriberInterface $actionInstance */
             $actionInstance = new $actionNamespace($responder);
             $actionInstance->setContainer($this->container);
             $this->getEventManager()->addSubscriber($actionInstance);
             $climate = new CLImate();
             if (method_exists($actionNamespace, $cliConfig) && is_callable([$actionNamespace, $cliConfig])) {
                 $argumentManager = new Manager();
                 $climate->setArgumentManager($argumentManager);
                 $this->getEventManager()->dispatch(Action::EVENT_BEFORE_CLI_CONFIG);
                 call_user_func([$actionInstance, 'cliConfig'], $argumentManager);
                 $this->getEventManager()->dispatch(Action::EVENT_AFTER_CLI_CONFIG);
                 try {
                     $argumentManager->parse($argv);
                 } catch (\Exception $e) {
                     $climate->error($e->getMessage());
                     $climate->usage();
                 }
             }
             $this->getEventManager()->dispatch(Action::EVENT_BEFORE_CLI_METHOD);
             call_user_func([$actionInstance, $cliMethod], $climate);
             $this->getEventManager()->dispatch(Action::EVENT_AFTER_CLI_METHOD);
             // Check Responder::cliMethod exist or callable
             if (method_exists($responder, $cliMethod) && is_callable([$responder, $cliMethod])) {
                 $this->getEventManager()->dispatch(self::EVENT_BEFORE_RESPONDER);
                 call_user_func([$responder, $cliMethod]);
                 $this->getEventManager()->dispatch(self::EVENT_AFTER_RESPONDER);
             }
         } else {
             throw new MissingMethodException(sprintf('Method %s::%s() could not be found, or is not accessible.', $actionNamespace, $cliMethod));
         }
     } else {
         throw new BaseException(sprintf('Route "%s" does not found', $argv[0]));
     }
 }