Last active
March 18, 2017 22:00
-
-
Save carnage/4be645ade0d11f7134042df6999dc31b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Repository | |
{ | |
private $collection; | |
public function __construct(Collection $collection) | |
{ | |
$this->collection = $collection; | |
} | |
public function findOneById($id) | |
{ | |
$criteria = Criteria::create(); | |
$exp = \Doctrine\Common\Collections\Criteria::expr(); | |
$exp->eq('id', $id); | |
$criteria->where($exp); | |
return $collection->matching($criteria)->current(); | |
} | |
public function findAll() | |
{ | |
return $this->collection; | |
} | |
//other methods for save, findByCriteria etc? | |
} | |
$dbCollection = new \Doctrine\ORM\LazyCriteriaCollection( | |
$em->getUnitOfWork()->getEntityPersister(Entity::class), | |
new \Doctrine\Common\Collections\Criteria() | |
); | |
$dbRepository = new Repository($dbCollection); | |
$inMemoryCollection = new ArrayCollection(); | |
$inMemoryRepository = new Repository($inMemoryCollection); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment