PackageRepository.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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['package'];
  32. // make sure we have an array of package definitions
  33. if (!is_numeric(key($this->config))) {
  34. $this->config = array($this->config);
  35. }
  36. }
  37. /**
  38. * Initializes repository (reads file, or remote address).
  39. */
  40. protected function initialize()
  41. {
  42. parent::initialize();
  43. $loader = new ArrayLoader();
  44. foreach ($this->config as $package) {
  45. $package = $loader->load($package);
  46. $this->addPackage($package);
  47. }
  48. }
  49. }