Last active
October 1, 2018 11:34
-
-
Save MekDrop/15b1b90ca7179f450f86481dde42bb8f to your computer and use it in GitHub Desktop.
Run composer from PHP code example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This is simple PHP script that shows how to use composer directly from your PHP code | |
* | |
* First thing what you need is to include composer/composer in your composer.json | |
* and than you can use such code. | |
*/ | |
use Composer\Console\Application; | |
use Composer\Factory; | |
use Symfony\Component\Console\Input\ArrayInput; | |
$input = new ArrayInput( | |
array( | |
'command' => 'install', | |
'--working-dir' => './', | |
'--no-interaction' => true, | |
'--no-dev' => true, | |
'--no-suggest' => true, | |
'--optimize-autoloader' => true, | |
'-v' => true | |
) | |
); | |
$application = new Application(); | |
$application->setAutoExit(false); | |
// if you don't want to see any output you can remove Factory::createOutput() | |
$exit_code = $application->doRun($input, Factory::createOutput()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment