shellProcess = $shellProcess; parent::__construct(); } /** * {@inheritdoc} */ protected function configure() { $this ->setName('exec') ->setDescription($this->trans('commands.exec.description')) ->addArgument( 'bin', InputArgument::REQUIRED, $this->trans('commands.exec.arguments.bin') )->addOption( 'working-directory', null, InputOption::VALUE_OPTIONAL, $this->trans('commands.exec.options.working-directory') ); } /** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $bin = $input->getArgument('bin'); $workingDirectory = $input->getOption('working-directory'); if (!$bin) { $this->getIo()->error( $this->trans('commands.exec.messages.missing-bin') ); return 1; } $name = $bin; if ($index = stripos($name, " ")) { $name = substr($name, 0, $index); } $finder = new ExecutableFinder(); if (!$finder->find($name)) { $this->getIo()->error( sprintf( $this->trans('commands.exec.messages.binary-not-found'), $name ) ); return 1; } if (!$this->shellProcess->exec($bin, $workingDirectory)) { $this->getIo()->error( sprintf( $this->trans('commands.exec.messages.invalid-bin') ) ); $this->getIo()->writeln($this->shellProcess->getOutput()); return 1; } $this->getIo()->success( sprintf( $this->trans('commands.exec.messages.success'), $bin ) ); return 0; } }