Skip to content

Instantly share code, notes, and snippets.

@carnage
Last active March 18, 2017 22:00
Show Gist options
  • Save carnage/4be645ade0d11f7134042df6999dc31b to your computer and use it in GitHub Desktop.
Save carnage/4be645ade0d11f7134042df6999dc31b to your computer and use it in GitHub Desktop.
<?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