Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions
Shell Class Reference
Inheritance diagram for Shell:
ShellInterface

Public Member Functions

 __construct (Driver $driver, LoggerInterface $logger)
 
 execute ($command, array $arguments=[])
 

Detailed Description

Class is separate from \Magento|Framework\Shell because logging behavior is different, and relies on ObjectManager being available.

Definition at line 19 of file Shell.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( Driver  $driver,
LoggerInterface  $logger 
)
Parameters
Driver$driver
CommandRendererInterface$commandRenderer
LoggerInterface$logger

Definition at line 36 of file Shell.php.

39  {
40  $this->driver = $driver;
41  $this->logger = $logger;
42  }

Member Function Documentation

◆ execute()

execute (   $command,
array  $arguments = [] 
)

Execute a command through the command line, passing properly escaped arguments

Parameters
string$commandCommand with optional argument markers 's'
string[]$arguments Argument values to substitute markers with
Exceptions

Implements ShellInterface.

Definition at line 52 of file Shell.php.

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  }
$response
Definition: 404.php:11
$arguments

The documentation for this class was generated from the following file: