Skip to content

Instantly share code, notes, and snippets.

@maciejmiara
Created May 7, 2019 06:11
Show Gist options
  • Save maciejmiara/0cff4eee8e684da044f3a3d535b10387 to your computer and use it in GitHub Desktop.
Save maciejmiara/0cff4eee8e684da044f3a3d535b10387 to your computer and use it in GitHub Desktop.
<?php
declare(strict_types = 1);
namespace Infrastructure\Framework\Repository;
use Common\Id;
use Doctrine\ORM\EntityManagerInterface;
use Domain\Exception\RunnerNotFound;
use Domain\Model\Runner;
use Infrastructure\Doctrine\Transformer\RunnerTransformer;
class RunnerRepository implements \Domain\Repository\RunnerRepository
{
private $entityManager;
private $entityRepository;
private $runnerTransformer;
public function __construct(EntityManagerInterface $entityManager, RunnerTransformer $runnerTransformer)
{
$this->entityManager = $entityManager;
$this->entityRepository = $entityManager->getRepository(\Infrastructure\Framework\Entity\Runner::class);
$this->runnerTransformer = $runnerTransformer;
}
/**
* {@inheritdoc}
*/
public function getById(Id $runnerId): Runner
{
$runner = $this->entityRepository->find((string)$runnerId);
if (null === $runner) {
throw RunnerNotFound::forId($runnerId);
}
return $this->runnerTransformer->entityToDomain($runner);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment