composer 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/usr/bin/env php
  2. <?php
  3. require __DIR__.'/../tests/bootstrap.php';
  4. use Composer\Composer;
  5. use Composer\Installer;
  6. use Composer\Downloader;
  7. use Composer\Repository;
  8. use Composer\Package;
  9. use Composer\Json\JsonFile;
  10. use Composer\Console\Application as ComposerApplication;
  11. // initialize repository manager
  12. $rm = new Repository\RepositoryManager();
  13. $rm->setLocalRepository(new Repository\FilesystemRepository(new JsonFile('.composer/installed.json')));
  14. $rm->addRepository(new Repository\ComposerRepository('http://packagist.org'));
  15. $rm->setRepositoryClass('composer', 'Composer\Repository\ComposerRepository');
  16. $rm->setRepositoryClass('pear', 'Composer\Repository\PearRepository');
  17. $rm->setRepositoryClass('package', 'Composer\Repository\PackageRepository');
  18. // initialize download manager
  19. $dm = new Downloader\DownloadManager($preferSource = false);
  20. $dm->setDownloader('git', new Downloader\GitDownloader());
  21. $dm->setDownloader('pear', new Downloader\PearDownloader());
  22. $dm->setDownloader('zip', new Downloader\ZipDownloader());
  23. // initialize installation manager
  24. $im = new Installer\InstallationManager();
  25. $im->addInstaller(new Installer\LibraryInstaller('vendor', $dm, $rm->getLocalRepository()));
  26. $im->addInstaller(new Installer\LibraryInstaller('vendor/bundles', $dm, $rm->getLocalRepository(), 'symfony-bundle'));
  27. // load package
  28. $loader = new Package\Loader\JsonLoader();
  29. $package = $loader->load(new JsonFile('composer.json'));
  30. // init locker
  31. $locker = new Package\Locker(new JsonFile('composer.lock'), $rm);
  32. // initialize composer
  33. $composer = new Composer();
  34. $composer->setPackage($package);
  35. $composer->setLocker($locker);
  36. $composer->setRepositoryManager($rm);
  37. $composer->setDownloadManager($dm);
  38. $composer->setInstallationManager($im);
  39. // run the command application
  40. $application = new ComposerApplication($composer);
  41. $application->run();