/**
  * Executes the current command.
  *
  * This method is not abstract because you can use this class
  * as a concrete class. In this case, instead of defining the
  * execute() method, you set the code to execute by passing
  * a Closure to the setCode() method.
  *
  * @param InputInterface $input An InputInterface instance
  * @param OutputInterface $output An OutputInterface instance
  *
  * @return null|int null or 0 if everything went fine, or an error code
  *
  * @throws \LogicException When this abstract method is not implemented
  *
  * @see setCode()
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     /** @var DefinitionChecker $checker */
     $checker = $this->getContainer()->get('babymarkt_ext_cron.service.definitionchecker');
     $checker->setApplication($this->getApplication());
     /** @var Definition[] $definitions */
     $definitions = $this->getContainer()->getParameter('babymarkt_ext_cron.definitions');
     $errorFound = false;
     if (count($definitions)) {
         $resultList = [];
         foreach ($definitions as $alias => $definition) {
             $definition = new Definition($definition);
             if ($definition->isDisabled()) {
                 $resultList[] = ['alias' => $alias, 'command' => $definition->getCommand(), 'result' => '<comment>Disabled</comment>'];
             } else {
                 if (!$checker->check($definition)) {
                     $resultList[] = ['alias' => $alias, 'command' => $definition->getCommand(), 'result' => '<error>' . $checker->getResult() . '</error>'];
                     $errorFound = true;
                 } else {
                     $resultList[] = ['alias' => $alias, 'command' => $definition->getCommand(), 'result' => '<info>OK</info>'];
                 }
             }
         }
         $table = new Table($output);
         $table->setHeaders(['Alias', 'Command', 'Result']);
         $table->setRows($resultList);
         $table->render();
     } else {
         $output->writeln('<comment>No cron job definitions found.</comment>');
     }
     return (int) $errorFound;
 }
 /**
  * Checks a single definition.
  *
  * @param Definition $definition
  * @return bool
  */
 public function check(Definition $definition)
 {
     try {
         $this->application->find($definition->getCommand());
     } catch (\InvalidArgumentException $e) {
         $this->result = self::RESULT_INCORRECT_COMMAND;
         return false;
     }
     return true;
 }
 /**
  * Returns the command part.
  * @param Definition $def
  * @return string
  */
 protected function getCommandString(Definition $def)
 {
     if (empty($def->getCommand())) {
         throw new \InvalidArgumentException('Cron command is required.');
     }
     return vsprintf('cd %s; php console --env=%s %s', [$this->basedir, $this->environment, $def->getCommand()]);
 }