ArrayRepository.php 1.2 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\Package\PackageInterface;
  13. /**
  14. * A repository implementation that simply stores packages in an array
  15. *
  16. * @author Nils Adermann <naderman@naderman.de>
  17. */
  18. class ArrayRepository implements RepositoryInterface
  19. {
  20. protected $packages = array();
  21. /**
  22. * Adds a new package to the repository
  23. *
  24. * @param PackageInterface $package
  25. */
  26. public function addPackage(PackageInterface $package)
  27. {
  28. $package->setRepository($this);
  29. $this->packages[] = $package;
  30. }
  31. /**
  32. * Returns all contained packages
  33. *
  34. * @return array All packages
  35. */
  36. public function getPackages()
  37. {
  38. return $this->packages;
  39. }
  40. /**
  41. * Returns the number of packages in this repository
  42. *
  43. * @return int Number of packages
  44. */
  45. public function count()
  46. {
  47. return count($this->packages);
  48. }
  49. }