Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields
MagentoComposerApplication Class Reference

Public Member Functions

 __construct ( $pathToComposerHome, $pathToComposerJson, Application $consoleApplication=null, ConsoleArrayInputFactory $consoleArrayInputFactory=null, BufferedOutput $consoleOutput=null)
 
 createComposer ()
 
 runComposerCommand (array $commandParams, $workingDir=null)
 

Data Fields

const COMPOSER_WORKING_DIR = '--working-dir'
 

Detailed Description

Class MagentoComposerApplication

This class provides ability to set composer application settings and run any composer command. Also provides method to get Composer instance so you can have access composer properties lie Locker

Definition at line 20 of file MagentoComposerApplication.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $pathToComposerHome,
  $pathToComposerJson,
Application  $consoleApplication = null,
ConsoleArrayInputFactory  $consoleArrayInputFactory = null,
BufferedOutput  $consoleOutput = null 
)

Constructs class

Parameters
string$pathToComposerHome
string$pathToComposerJson
Application$consoleApplication
ConsoleArrayInputFactory$consoleArrayInputFactory
BufferedOutput$consoleOutput

Definition at line 65 of file MagentoComposerApplication.php.

71  {
72  $this->consoleApplication = $consoleApplication ? $consoleApplication : new Application();
73  $this->consoleArrayInputFactory = $consoleArrayInputFactory ? $consoleArrayInputFactory
74  : new ConsoleArrayInputFactory();
75  $this->consoleOutput = $consoleOutput ? $consoleOutput : new BufferedOutput();
76 
77  $this->composerJson = $pathToComposerJson;
78  $this->composerHome = $pathToComposerHome;
79 
80  putenv('COMPOSER_HOME=' . $pathToComposerHome);
81 
82  $this->consoleApplication->setAutoExit(false);
83  }

Member Function Documentation

◆ createComposer()

createComposer ( )

Creates composer object

Returns
\Composer\Composer
Exceptions

Definition at line 91 of file MagentoComposerApplication.php.

92  {
93  return ComposerFactory::create(new BufferIO(), $this->composerJson);
94  }

◆ runComposerCommand()

runComposerCommand ( array  $commandParams,
  $workingDir = null 
)

Runs composer command

Parameters
array$commandParams
string | null$workingDir
Returns
bool
Exceptions

Definition at line 104 of file MagentoComposerApplication.php.

105  {
106  $this->consoleApplication->resetComposer();
107 
108  if ($workingDir) {
109  $commandParams[self::COMPOSER_WORKING_DIR] = $workingDir;
110  } else {
111  $commandParams[self::COMPOSER_WORKING_DIR] = dirname($this->composerJson);
112  }
113 
114  $input = $this->consoleArrayInputFactory->create($commandParams);
115 
116  $exitCode = $this->consoleApplication->run($input, $this->consoleOutput);
117 
118  if ($exitCode) {
119  throw new \RuntimeException(
120  sprintf('Command "%s" failed: %s', $commandParams['command'], $this->consoleOutput->fetch())
121  );
122  }
123 
124  return $this->consoleOutput->fetch();
125  }

Field Documentation

◆ COMPOSER_WORKING_DIR

const COMPOSER_WORKING_DIR = '--working-dir'

Definition at line 23 of file MagentoComposerApplication.php.


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