Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Shell.php
Go to the documentation of this file.
1 <?php
6 namespace Magento\Framework\App;
7 
13 use Psr\Log\LoggerInterface;
14 
19 class Shell implements ShellInterface
20 {
24  private $driver;
25 
29  private $logger;
30 
36  public function __construct(
37  Driver $driver,
38  LoggerInterface $logger
39  ) {
40  $this->driver = $driver;
41  $this->logger = $logger;
42  }
43 
52  public function execute($command, array $arguments = [])
53  {
54  try {
55  $response = $this->driver->execute($command, $arguments);
56  } catch (LocalizedException $e) {
57  $this->logger->error($e->getLogMessage());
58  throw $e;
59  }
60  $escapedCommand = $response->getEscapedCommand();
61  $output = $response->getOutput();
62  $exitCode = $response->getExitCode();
63  $logEntry = $escapedCommand . PHP_EOL . $output;
64  if ($exitCode) {
65  $this->logger->error($logEntry);
66  $commandError = new \Exception($output, $exitCode);
67  throw new LocalizedException(
68  new Phrase("Command returned non-zero exit code:\n`%1`", [$command]),
69  $commandError
70  );
71  }
72  $this->logger->info($logEntry);
73  return $output;
74  }
75 }
$response
Definition: 404.php:11
$logger
__construct(Driver $driver, LoggerInterface $logger)
Definition: Shell.php:36
execute($command, array $arguments=[])
Definition: Shell.php:52
$arguments