lembadm/yii2-composer-helper Yii2 ComposerHelper helps to install, update or remove composer packages from PHP script

extensionhelpercomposer

ComposerHelper

ComposerHelper helps to install, update or remove composer packages from PHP script

Installation

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.

Usage

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
        ],
    ],
];

Install new package

Synchronously

try {
    $process = Yii::$app->composer->add('package/name');
    echo $process->getOutput();
} catch (ProcessFailedException $e) {
    echo $e->getMessage();
}

Async

$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;
});

Update package

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

Synchronously

try {
    $process = Yii::$app->composer->update(['package/name']);
    echo $process->getOutput();
} catch (ProcessFailedException $e) {
    echo $e->getMessage();
}

Async

$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;
});

Remove packege

Synchronously

try {
    $process = Yii::$app->composer->remove('package/name');
    echo $process->getOutput();
} catch (ProcessFailedException $e) {
    echo $e->getMessage();
}

Async

$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;
});

Statistics

Downloads
GitHub Stars
GitHub Forks

Releases

No stable releases.

Comments



No stable releases.



MIT license
Stats
1 github stars & 0 github forks
0 downloads in the last day
0 downloads in the last 30 days
0 total downloads