Skip to content

Instantly share code, notes, and snippets.

@Ahed91
Created March 30, 2017 16:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ahed91/d076624e244b0e0f381c771b9d475200 to your computer and use it in GitHub Desktop.
Save Ahed91/d076624e244b0e0f381c771b9d475200 to your computer and use it in GitHub Desktop.
<?php
# written by https://github.com/ducktype
# https://github.com/composer/composer/issues/1906#issuecomment-260348383
error_reporting(E_ALL & ~E_NOTICE & ~E_USER_NOTICE & ~E_DEPRECATED & ~E_USER_DEPRECATED
& ~E_WARNING & ~E_CORE_WARNING & ~E_USER_WARNING & ~E_STRICT);
$composer_data = array(
'url' => 'https://getcomposer.org/composer.phar',
'dir' => __DIR__.'/.code',
'bin' => __DIR__.'/.code/composer.phar',
'json' => __DIR__.'/.code/composer.json',
'conf' => array(
"autoload" => array(
"psr-4" => array(
"" => "local/"
)
),
"require"=> array(
"rmccue/requests" => "@stable"
)
)
);
mkdir($composer_data['dir'],0777,true);
mkdir("{$composer_data['dir']}/local",0777,true);
copy($composer_data['url'],$composer_data['bin']);
require_once "phar://{$composer_data['bin']}/src/bootstrap.php";
$conf_json = json_encode($composer_data['conf'],JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE);
file_put_contents($composer_data['json'],$conf_json);
chdir($composer_data['dir']);
putenv("COMPOSER_HOME={$composer_data['dir']}");
putenv("OSTYPE=OS400"); //force to use php://output instead of php://stdout
$app = new \Composer\Console\Application();
$factory = new \Composer\Factory();
$output = $factory->createOutput();
$input = new \Symfony\Component\Console\Input\ArrayInput(array(
'command' => 'update',
));
$input->setInteractive(false);
echo "<pre>";
$cmdret = $app->doRun($input,$output); //unfortunately ->run() call exit() so we use doRun()
echo "end!";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment