1
0
Fork 0
composer/bin/composer

57 lines
2.1 KiB
PHP
Executable File

#!/usr/bin/env php
<?php
require __DIR__.'/../tests/bootstrap.php';
use Composer\Composer;
use Composer\Installer;
use Composer\Downloader;
use Composer\Repository;
use Composer\Package;
use Composer\Json\JsonFile;
use Composer\Console\Application as ComposerApplication;
// initialize repository manager
$rm = new Repository\RepositoryManager();
$rm->setLocalRepository(new Repository\FilesystemRepository(new JsonFile('.composer/installed.json')));
$rm->setRepositoryClass('composer', 'Composer\Repository\ComposerRepository');
$rm->setRepositoryClass('pear', 'Composer\Repository\PearRepository');
$rm->setRepositoryClass('package', 'Composer\Repository\PackageRepository');
// initialize download manager
$dm = new Downloader\DownloadManager($preferSource = false);
$dm->setDownloader('git', new Downloader\GitDownloader());
$dm->setDownloader('pear', new Downloader\PearDownloader());
$dm->setDownloader('zip', new Downloader\ZipDownloader());
// initialize installation manager
$im = new Installer\InstallationManager();
$im->addInstaller(new Installer\LibraryInstaller('vendor', $dm, $rm->getLocalRepository()));
$im->addInstaller(new Installer\LibraryInstaller('vendor/bundles', $dm, $rm->getLocalRepository(), 'symfony-bundle'));
// load package
$loader = new Package\Loader\ArrayLoader($rm);
$file = new JsonFile('composer.json');
$packageConfig = $file->read();
$package = $loader->load($packageConfig);
// load default repository unless it's explicitly disabled
if (!isset($packageConfig['repositories']['packagist']) || $packageConfig['repositories']['packagist'] !== false) {
$rm->addRepository(new Repository\ComposerRepository('http://packagist.org'));
}
// init locker
$locker = new Package\Locker(new JsonFile('composer.lock'), $rm);
// initialize composer
$composer = new Composer();
$composer->setPackage($package);
$composer->setLocker($locker);
$composer->setRepositoryManager($rm);
$composer->setDownloadManager($dm);
$composer->setInstallationManager($im);
// run the command application
$application = new ComposerApplication($composer);
$application->run();