1
0
Fork 0
composer/src/Composer/Repository/ArrayRepository.php

68 lines
1.4 KiB
PHP
Raw Normal View History

<?php
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
2011-04-16 12:42:35 +00:00
* Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
2011-04-17 21:32:53 +00:00
namespace Composer\Repository;
use Composer\Package\PackageInterface;
/**
* A repository implementation that simply stores packages in an array
*
* @author Nils Adermann <naderman@naderman.de>
*/
class ArrayRepository implements RepositoryInterface
{
2011-04-17 22:12:40 +00:00
protected $packages;
/**
* Adds a new package to the repository
*
* @param PackageInterface $package
*/
public function addPackage(PackageInterface $package)
{
$package->setRepository($this);
$this->packages[] = $package;
}
/**
* Returns all contained packages
*
* @return array All packages
*/
public function getPackages()
{
2011-04-17 22:12:40 +00:00
if (null === $this->packages) {
$this->initialize();
}
return $this->packages;
}
/**
* Returns the number of packages in this repository
*
* @return int Number of packages
*/
public function count()
{
return count($this->packages);
}
2011-04-17 22:12:40 +00:00
/**
* Initializes the packages array. Mostly meant as an extension point.
*/
protected function initialize()
{
$this->packages = array();
}
}