Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace MyApp\Infrastructure;
- use Doctrine\Common\Persistence\ObjectRepository;
- use Doctrine\ORM\AbstractQuery;
- use Doctrine\ORM\EntityManager;
- use MyApp\Domain\FooEntities\Foo;
- use MyAp\Domain\FooEntities\FooRepository;
- class DoctrineFooRepository implements FooRepository
- {
- /**
- * @var ObjectRepository
- */
- private $repository;
- /**
- * @var EntityManager
- */
- private $entityManager;
- public function __construct(ObjectRepository $repository, EntityManager $entityManager)
- {
- $this->repository = $repository;
- $this->entityManager = $entityManager;
- }
- /**
- * Retrieves all Foo entities
- *
- * @return Foo[]
- */
- public function all()
- {
- return $this->repository->findAll();
- }
- /**
- * Finds a Foo Entity by ID if it exists
- *
- * @param int $FooId
- * @return Foo|null
- */
- public function findById($FooId)
- {
- return $this->repository->find($FooId);
- }
- /**
- * Stores a Foo Entity
- *
- * @param Foo $Foo
- */
- public function update(Foo $Foo)
- {
- $this->entityManager->persist($Foo);
- $this->entityManager->flush($Foo);
- }
- /**
- * Returns an associative array of Foo entity addresses with the ID as the key and address string as the value
- *
- * @return string[]
- */
- public function allAddresses()
- {
- $results = $this->repository->findAll();
- $resultsByFooId = [];
- foreach($results as $result) {
- $address = $result->getFullAddress();
- $resultsByFooId[ $result->getId() ] = $address;
- }
- return $resultsByFooId;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement