|
Apache/2.4.41 (Ubuntu) Linux vmi616275.contaboserver.net 5.4.0-84-generic #94-Ubuntu SMP Thu Aug 26 20:27:37 UTC 2021 x86_64 uid=33(www-data) gid=33(www-data) groups=33(www-data) server ip : 62.171.164.128 | your ip : 127.0.0.1 safemode OFF > / home / a / home / dev2.destoffenstraat.com / vendor / magento / composer / src / |
Filename | /home/a/home/dev2.destoffenstraat.com/vendor/magento/composer/src/MagentoComposerApplication.php |
Size | 3.31 kb |
Permission | rw-rw-rw- |
Owner | root : root |
Create time | 21-Aug-2025 12:26 |
Last modified | 15-Jun-2020 17:52 |
Last accessed | 22-Aug-2025 21:34 |
Actions | edit | rename | delete | download (gzip) |
View | text | code | image |
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Composer;
use Composer\Console\Application;
use Composer\IO\BufferIO;
use Composer\Factory as ComposerFactory;
use Symfony\Component\Console\Output\BufferedOutput;
/**
* 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
*/
class MagentoComposerApplication
{
const COMPOSER_WORKING_DIR = '--working-dir';
/**
* Path to Composer home directory
*
* @var string
*/
private $composerHome;
/**
* Path to composer.json file
*
* @var string
*/
private $composerJson;
/**
* Buffered output
*
* @var BufferedOutput
*/
private $consoleOutput;
/**
* @var ConsoleArrayInputFactory
*/
private $consoleArrayInputFactory;
/**
* @var Application
*/
private $consoleApplication;
/**
* Constructs class
*
* @param string $pathToComposerHome
* @param string $pathToComposerJson
* @param Application $consoleApplication
* @param ConsoleArrayInputFactory $consoleArrayInputFactory
* @param BufferedOutput $consoleOutput
*/
public function __construct(
$pathToComposerHome,
$pathToComposerJson,
Application $consoleApplication = null,
ConsoleArrayInputFactory $consoleArrayInputFactory = null,
BufferedOutput $consoleOutput = null
) {
$this->consoleApplication = $consoleApplication ? $consoleApplication : new Application();
$this->consoleArrayInputFactory = $consoleArrayInputFactory ? $consoleArrayInputFactory
: new ConsoleArrayInputFactory();
$this->consoleOutput = $consoleOutput ? $consoleOutput : new BufferedOutput();
$this->composerJson = $pathToComposerJson;
$this->composerHome = $pathToComposerHome;
putenv('COMPOSER_HOME=' . $pathToComposerHome);
$this->consoleApplication->setAutoExit(false);
}
/**
* Creates composer object
*
* @return \Composer\Composer
* @throws \Exception
*/
public function createComposer()
{
return ComposerFactory::create(new BufferIO(), $this->composerJson);
}
/**
* Runs composer command
*
* @param array $commandParams
* @param string|null $workingDir
* @return bool
* @throws \RuntimeException
*/
public function runComposerCommand(array $commandParams, $workingDir = null)
{
$this->consoleApplication->resetComposer();
if ($workingDir) {
$commandParams[self::COMPOSER_WORKING_DIR] = $workingDir;
} else {
$commandParams[self::COMPOSER_WORKING_DIR] = dirname($this->composerJson);
}
$input = $this->consoleArrayInputFactory->create($commandParams);
$exitCode = $this->consoleApplication->run($input, $this->consoleOutput);
if ($exitCode) {
throw new \RuntimeException(
sprintf('Command "%s" failed: %s', $commandParams['command'], $this->consoleOutput->fetch())
);
}
return $this->consoleOutput->fetch();
}
}
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Composer;
use Composer\Console\Application;
use Composer\IO\BufferIO;
use Composer\Factory as ComposerFactory;
use Symfony\Component\Console\Output\BufferedOutput;
/**
* 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
*/
class MagentoComposerApplication
{
const COMPOSER_WORKING_DIR = '--working-dir';
/**
* Path to Composer home directory
*
* @var string
*/
private $composerHome;
/**
* Path to composer.json file
*
* @var string
*/
private $composerJson;
/**
* Buffered output
*
* @var BufferedOutput
*/
private $consoleOutput;
/**
* @var ConsoleArrayInputFactory
*/
private $consoleArrayInputFactory;
/**
* @var Application
*/
private $consoleApplication;
/**
* Constructs class
*
* @param string $pathToComposerHome
* @param string $pathToComposerJson
* @param Application $consoleApplication
* @param ConsoleArrayInputFactory $consoleArrayInputFactory
* @param BufferedOutput $consoleOutput
*/
public function __construct(
$pathToComposerHome,
$pathToComposerJson,
Application $consoleApplication = null,
ConsoleArrayInputFactory $consoleArrayInputFactory = null,
BufferedOutput $consoleOutput = null
) {
$this->consoleApplication = $consoleApplication ? $consoleApplication : new Application();
$this->consoleArrayInputFactory = $consoleArrayInputFactory ? $consoleArrayInputFactory
: new ConsoleArrayInputFactory();
$this->consoleOutput = $consoleOutput ? $consoleOutput : new BufferedOutput();
$this->composerJson = $pathToComposerJson;
$this->composerHome = $pathToComposerHome;
putenv('COMPOSER_HOME=' . $pathToComposerHome);
$this->consoleApplication->setAutoExit(false);
}
/**
* Creates composer object
*
* @return \Composer\Composer
* @throws \Exception
*/
public function createComposer()
{
return ComposerFactory::create(new BufferIO(), $this->composerJson);
}
/**
* Runs composer command
*
* @param array $commandParams
* @param string|null $workingDir
* @return bool
* @throws \RuntimeException
*/
public function runComposerCommand(array $commandParams, $workingDir = null)
{
$this->consoleApplication->resetComposer();
if ($workingDir) {
$commandParams[self::COMPOSER_WORKING_DIR] = $workingDir;
} else {
$commandParams[self::COMPOSER_WORKING_DIR] = dirname($this->composerJson);
}
$input = $this->consoleArrayInputFactory->create($commandParams);
$exitCode = $this->consoleApplication->run($input, $this->consoleOutput);
if ($exitCode) {
throw new \RuntimeException(
sprintf('Command "%s" failed: %s', $commandParams['command'], $this->consoleOutput->fetch())
);
}
return $this->consoleOutput->fetch();
}
}