Skip to content

Instantly share code, notes, and snippets.

@MekDrop
Last active October 1, 2018 11:34
Show Gist options
  • Save MekDrop/15b1b90ca7179f450f86481dde42bb8f to your computer and use it in GitHub Desktop.
Save MekDrop/15b1b90ca7179f450f86481dde42bb8f to your computer and use it in GitHub Desktop.
Run composer from PHP code example
<?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