Пример #1
0
 /**
  * Execute this command.
  *
  * @return  mixed  Executed result or exit code.
  *
  * @since  2.0
  */
 public function execute()
 {
     $this->prepareExecute();
     // Show help or not
     if (!count($this->children) && $this->app instanceof AbstractConsole && $this->app->get('show_help')) {
         $this->io->out($this->app->describeCommand($this));
         return $this->postExecute(true);
     }
     if (count($this->children) && count($this->io->getArguments())) {
         $name = $this->io->getArgument(0);
         try {
             return $this->executeSubCommand($name);
         } catch (CommandNotFoundException $e) {
             $e->getCommand()->renderAlternatives($e->getChild(), $e);
             return $e->getCode();
         } catch (\Exception $e) {
             throw $e;
         }
     }
     if ($this->handler) {
         if ($this->handler instanceof \Closure) {
             $code = $this->handler;
             return $code($this);
         } elseif (is_callable($this->handler)) {
             return call_user_func($this->handler, $this);
         }
     }
     $result = $this->doExecute();
     return $this->postExecute($result);
 }
 /**
  * Execute this command.
  *
  * @return mixed Executed result or exit code.
  *
  * @throws \Exception
  * @since  2.0
  */
 public function execute()
 {
     $this->prepareExecute();
     // Show help or not if command has no logic
     if (!count($this->children) && $this->console instanceof AbstractConsole && $this->console->get('show_help')) {
         $this->io->out($this->console->describeCommand($this));
         return $this->postExecute(true);
     }
     if (count($this->children) && count($this->io->getArguments())) {
         $name = $this->io->getArgument(0);
         // Show help if a command also has logic
         if ($this->console instanceof AbstractConsole && $this->console->get('show_help') && !isset($this->children[$name])) {
             $this->io->out($this->console->describeCommand($this));
             return $this->postExecute(true);
         }
         try {
             return $this->executeSubCommand($name);
         } catch (CommandNotFoundException $e) {
             $e->getCommand()->renderAlternatives($e->getChild(), $e);
             return $e->getCode();
         } catch (WrongArgumentException $e) {
             $command = $this->getChild($name);
             throw new \RuntimeException($e->getMessage() . "\n\n" . $command->getUsage(), $e->getCode(), $e);
         } catch (\Exception $e) {
             throw $e;
         }
     }
     if ($this->handler) {
         if ($this->handler instanceof \Closure) {
             $code = $this->handler;
             return $code($this);
         } elseif (is_callable($this->handler)) {
             return call_user_func($this->handler, $this);
         }
     }
     $result = $this->doExecute();
     return $this->postExecute($result);
 }