PackageRepository.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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\Package\Loader\ArrayLoader;
  13. /**
  14. * Package repository.
  15. *
  16. * @author Jordi Boggiano <j.boggiano@seld.be>
  17. */
  18. class PackageRepository extends ArrayRepository
  19. {
  20. private $config;
  21. /**
  22. * Initializes filesystem repository.
  23. *
  24. * @param array $config package definition
  25. */
  26. public function __construct(array $config)
  27. {
  28. $this->config = $config['package'];
  29. // make sure we have an array of package definitions
  30. if (!is_numeric(key($this->config))) {
  31. $this->config = array($this->config);
  32. }
  33. }
  34. /**
  35. * Initializes repository (reads file, or remote address).
  36. */
  37. protected function initialize()
  38. {
  39. parent::initialize();
  40. $loader = new ArrayLoader();
  41. foreach ($this->config as $package) {
  42. $package = $loader->load($package);
  43. $this->addPackage($package);
  44. }
  45. }
  46. }