PackageRepository.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /*
  3. * This file is part of Composer.
  4. *
  5. * (c) Nils Adermann <naderman@naderman.de>
  6. * Jordi Boggiano <j.boggiano@seld.be>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Composer\Repository;
  12. use Composer\Json\JsonFile;
  13. use Composer\Package\PackageInterface;
  14. use Composer\Package\Loader\ArrayLoader;
  15. use Composer\Package\Dumper\ArrayDumper;
  16. /**
  17. * Package repository.
  18. *
  19. * @author Jordi Boggiano <j.boggiano@seld.be>
  20. */
  21. class PackageRepository extends ArrayRepository
  22. {
  23. private $config;
  24. /**
  25. * Initializes filesystem repository.
  26. *
  27. * @param array $config package definition
  28. */
  29. public function __construct(array $config)
  30. {
  31. $this->config = $config;
  32. }
  33. /**
  34. * Initializes repository (reads file, or remote address).
  35. */
  36. protected function initialize()
  37. {
  38. parent::initialize();
  39. if (!is_numeric(key($this->config))) {
  40. $this->config = array($this->config);
  41. }
  42. foreach ($this->config as $package) {
  43. $loader = new ArrayLoader($this->repositoryManager);
  44. $package = $loader->load($package);
  45. $this->addPackage($package);
  46. }
  47. }
  48. }