84 lines
3.0 KiB
PHP
Executable File
84 lines
3.0 KiB
PHP
Executable File
#!/usr/bin/env php
|
|
<?php
|
|
|
|
if (!@include __DIR__.'/../vendor/.composer/autoload.php') {
|
|
die('You must set up the project dependencies, run the following commands:
|
|
wget http://getcomposer.org/composer.phar
|
|
php composer.phar install
|
|
');
|
|
}
|
|
|
|
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;
|
|
|
|
// load Composer configuration
|
|
$file = new JsonFile('composer.json');
|
|
if (!$file->exists()) {
|
|
echo 'Composer could not find a composer.json file in '.getcwd().PHP_EOL;
|
|
echo 'To initialize a project, please create a composer.json file as described on the http://packagist.org/ "Getting Started" section'.PHP_EOL;
|
|
exit(1);
|
|
}
|
|
|
|
// Configuration defaults
|
|
$composerConfig = array('vendor-dir' => 'vendor');
|
|
|
|
$packageConfig = $file->read();
|
|
|
|
if (isset($packageConfig['config']) && is_array($packageConfig['config'])) {
|
|
$packageConfig['config'] = array_merge($composerConfig, $packageConfig['config']);
|
|
} else {
|
|
$packageConfig['config'] = $composerConfig;
|
|
}
|
|
|
|
$vendorDir = $packageConfig['config']['vendor-dir'];
|
|
|
|
// initialize repository manager
|
|
$rm = new Repository\RepositoryManager();
|
|
$rm->setLocalRepository(new Repository\FilesystemRepository(new JsonFile($vendorDir.'/.composer/installed.json')));
|
|
$rm->setRepositoryClass('composer', 'Composer\Repository\ComposerRepository');
|
|
$rm->setRepositoryClass('vcs', 'Composer\Repository\VcsRepository');
|
|
$rm->setRepositoryClass('pear', 'Composer\Repository\PearRepository');
|
|
$rm->setRepositoryClass('package', 'Composer\Repository\PackageRepository');
|
|
|
|
// initialize download manager
|
|
$dm = new Downloader\DownloadManager();
|
|
$dm->setDownloader('git', new Downloader\GitDownloader());
|
|
$dm->setDownloader('svn', new Downloader\SvnDownloader());
|
|
$dm->setDownloader('hg', new Downloader\HgDownloader());
|
|
$dm->setDownloader('pear', new Downloader\PearDownloader());
|
|
$dm->setDownloader('zip', new Downloader\ZipDownloader());
|
|
|
|
// initialize installation manager
|
|
$im = new Installer\InstallationManager($vendorDir);
|
|
$im->addInstaller(new Installer\LibraryInstaller($vendorDir, $dm, $rm->getLocalRepository(), null));
|
|
$im->addInstaller(new Installer\InstallerInstaller($vendorDir, $dm, $rm->getLocalRepository(), $im));
|
|
|
|
// load package
|
|
$loader = new Package\Loader\ArrayLoader($rm);
|
|
$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();
|