Refactor collection repositories: use one instance per databox

This commit is contained in:
Thibaud Fabre
2015-07-09 18:48:53 +02:00
parent 6b516618aa
commit 977e778b61
17 changed files with 407 additions and 214 deletions

View File

@@ -0,0 +1,50 @@
<?php
namespace Alchemy\Phrasea\Collection\Repository;
use Alchemy\Phrasea\Collection\CollectionRepository;
class ArrayCacheCollectionRepository implements CollectionRepository
{
/**
* @var CollectionRepository
*/
private $collectionRepository;
/**
* @var \collection[]
*/
private $collectionCache = null;
public function __construct(CollectionRepository $collectionRepository)
{
$this->collectionRepository = $collectionRepository;
}
/**
* @return \collection[]
*/
public function findAll()
{
if ($this->collectionCache === null) {
$this->collectionCache = $this->collectionRepository->findAll();
}
return $this->collectionCache;
}
/**
* @param int $collectionId
* @return \collection|null
*/
public function find($collectionId)
{
$collections = $this->findAll();
if (isset($collections[$collectionId])) {
return $collections[$collectionId];
}
return null;
}
}