ComposerHelper helps to install, update or remove composer packages from PHP script
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist lembadm/composer-helper "*"
or add
"lembadm/composer-helper": "*"
to the require section of your composer.json
file.
To use this extension, simply add the following code in your application configuration:
return [
//....
'components' => [
'composer' => [
'class' => 'lembadm\composer\ComposerHelper',
'composerHomeDirectory' => '<pathToComposerDirectory>', // default: './.composer/'
'idleTimeout' => '<idleTimeout>', // default: 60
'timeout' => '<timeout>', // default: 3600
],
],
];
try {
$process = Yii::$app->composer->add('package/name');
echo $process->getOutput();
} catch (ProcessFailedException $e) {
echo $e->getMessage();
}
$process = Yii::$app->composer->addAsync('package/name');
while ($process->isRunning()) {
// waiting for process to finish
}
or
$process = Yii::$app->composer->addAsync('package/name');
// ... do other things
$process->wait(function ($type, $buffer) {
echo (Process::ERR === $type)
? 'ERR > '.$buffer
: 'OUT > '.$buffer;
});
if param $packages
is null
composer dependencies using base composer.json
located in application
if param $packages
is array
of packages names - only them will be updated
try {
$process = Yii::$app->composer->update(['package/name']);
echo $process->getOutput();
} catch (ProcessFailedException $e) {
echo $e->getMessage();
}
$process = Yii::$app->composer->updateAsync(['package/name']);
while ($process->isRunning()) {
// waiting for process to finish
}
or
$process = Yii::$app->composer->updateAsync(['package/name']);
// ... do other things
$process->wait(function ($type, $buffer) {
echo (Process::ERR === $type)
? 'ERR > '.$buffer
: 'OUT > '.$buffer;
});
try {
$process = Yii::$app->composer->remove('package/name');
echo $process->getOutput();
} catch (ProcessFailedException $e) {
echo $e->getMessage();
}
$process = Yii::$app->composer->removeAsync('package/name');
while ($process->isRunning()) {
// waiting for process to finish
}
or
$process = Yii::$app->composer->removeAsync('package/name');
// ... do other things
$process->wait(function ($type, $buffer) {
echo (Process::ERR === $type)
? 'ERR > '.$buffer
: 'OUT > '.$buffer;
});
No stable releases.
Comments