Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Member Functions
Cli Class Reference
Inheritance diagram for Cli:
Application

Public Member Functions

 __construct ($name='UNKNOWN', $version='UNKNOWN')
 
 doRun (Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
 
- Public Member Functions inherited from Application
 bootstrap (array $configuration)
 

Data Fields

const INPUT_KEY_BOOTSTRAP = 'bootstrap'
 
const RETURN_SUCCESS = 0
 
const RETURN_FAILURE = 1
 

Protected Member Functions

 getDefaultCommands ()
 
 getVendorCommands ($objectManager)
 

Detailed Description

Magento 2 CLI Application. This is the hood for all command line tools supported by Magento.

{} @SuppressWarnings(PHPMD.CouplingBetweenObjects)

Definition at line 30 of file Cli.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $name = 'UNKNOWN',
  $version = 'UNKNOWN' 
)
Parameters
string$namethe application name
string$versionthe application version @SuppressWarnings(PHPMD.ExitExpression)

Definition at line 66 of file Cli.php.

67  {
68  try {
69  $configuration = require BP . '/setup/config/application.config.php';
70  $bootstrapApplication = new Application();
71  $application = $bootstrapApplication->bootstrap($configuration);
72  $this->serviceManager = $application->getServiceManager();
73 
74  $this->assertCompilerPreparation();
75  $this->initObjectManager();
76  } catch (\Exception $exception) {
77  $output = new \Symfony\Component\Console\Output\ConsoleOutput();
78  $output->writeln(
79  '<error>' . $exception->getMessage() . '</error>'
80  );
81 
82  exit(static::RETURN_FAILURE);
83  }
84 
85  if ($version == 'UNKNOWN') {
86  $directoryList = new DirectoryList(BP);
87  $composerJsonFinder = new ComposerJsonFinder($directoryList);
88  $productMetadata = new ProductMetadata($composerJsonFinder);
89  $version = $productMetadata->getVersion();
90  }
91 
92  parent::__construct($name, $version);
93  }
$configuration
Definition: index.php:33
$application
Definition: bootstrap.php:58
exit
Definition: redirect.phtml:12
const BP
Definition: autoload.php:14
if(!isset($_GET['name'])) $name
Definition: log.php:14

Member Function Documentation

◆ doRun()

doRun ( Console\Input\InputInterface  $input,
Console\Output\OutputInterface  $output 
)

{}

Exceptions

Definition at line 100 of file Cli.php.

101  {
102  $exitCode = parent::doRun($input, $output);
103 
104  if ($this->initException) {
105  throw $this->initException;
106  }
107 
108  return $exitCode;
109  }

◆ getDefaultCommands()

getDefaultCommands ( )
protected

{}

Definition at line 114 of file Cli.php.

115  {
116  return array_merge(parent::getDefaultCommands(), $this->getApplicationCommands());
117  }

◆ getVendorCommands()

getVendorCommands (   $objectManager)
protected

Retrieves vendor commands.

Parameters
ObjectManagerInterface$objectManagerthe object manager
Returns
array an array with external commands

Definition at line 204 of file Cli.php.

205  {
206  $commands = [];
207  foreach (CommandLocator::getCommands() as $commandListClass) {
208  if (class_exists($commandListClass)) {
209  $commands = array_merge(
210  $commands,
211  $objectManager->create($commandListClass)->getCommands()
212  );
213  }
214  }
215 
216  return $commands;
217  }

Field Documentation

◆ INPUT_KEY_BOOTSTRAP

const INPUT_KEY_BOOTSTRAP = 'bootstrap'

Name of input option.

Definition at line 35 of file Cli.php.

◆ RETURN_FAILURE

const RETURN_FAILURE = 1

Definition at line 41 of file Cli.php.

◆ RETURN_SUCCESS

const RETURN_SUCCESS = 0

#+ Cli exit codes.

Definition at line 40 of file Cli.php.


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