mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-12 04:23:19 +00:00
Refactor collection repositories: use one instance per databox
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user