1
0
Fork 0

Prevent CompositeRepository instances from being nested

pull/1186/merge
Jordi Boggiano 2012-10-22 14:29:34 +02:00
parent fef3dacdfb
commit 1760b1e093
1 changed files with 11 additions and 2 deletions

View File

@ -33,7 +33,10 @@ class CompositeRepository implements RepositoryInterface
*/
public function __construct(array $repositories)
{
$this->repositories = $repositories;
$this->repositories = array();
foreach ($repositories as $repo) {
$this->addRepository($repo);
}
}
/**
@ -150,6 +153,12 @@ class CompositeRepository implements RepositoryInterface
*/
public function addRepository(RepositoryInterface $repository)
{
$this->repositories[] = $repository;
if ($repository instanceof self) {
foreach ($repository->getRepositories() as $repo) {
$this->addRepository($repo);
}
} else {
$this->repositories[] = $repository;
}
}
}