1
0
Fork 0

Add WrapperRepository class

pull/20/merge
Jordi Boggiano 2011-09-25 23:05:14 +02:00
parent c7af918caa
commit 4fe80d7abb
1 changed files with 64 additions and 0 deletions

View File

@ -0,0 +1,64 @@
<?php
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
* 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.
*/
namespace Composer\Repository;
use Composer\Package\PackageInterface;
/**
* @author Jordi Boggiano <j.boggiano@seld.be>
*/
class WrapperRepository extends ArrayRepository implements WritableRepositoryInterface
{
private $repositories;
public function __construct(array $repositories)
{
$this->repositories = $repositories;
}
protected function initialize()
{
parent::initialize();
foreach ($this->repositories as $repo) {
foreach ($repo->getPackages() as $package) {
$this->packages[] = $package;
}
}
}
/**
* {@inheritDoc}
*/
public function addPackage(PackageInterface $package)
{
throw new \LogicException('Can not add packages to a wrapper repository');
}
/**
* {@inheritDoc}
*/
public function removePackage(PackageInterface $package)
{
throw new \LogicException('Can not remove packages to a wrapper repository');
}
public function write()
{
foreach ($this->repositories as $repo) {
if ($repo instanceof WritableRepositoryInterface) {
$repo->write();
}
}
}
}