Created
May 7, 2019 00:52
-
-
Save maciejmiara/aec5a645014a1508af5a626d06efdc93 to your computer and use it in GitHub Desktop.
This file contains 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 | |
declare(strict_types = 1); | |
namespace Infrastructure\Doctrine\Transformer; | |
use Infrastructure\Framework\Entity\Runner as Entity; | |
use Domain\Model\Runner as Domain; | |
class RunnerTransformer | |
{ | |
private $runParticipationTransformer; | |
private $runResultTransformer; | |
public function __construct( | |
RunParticipationTransformer $runParticipationTransformer, | |
RunResultTransformer $runResultTransformer | |
) { | |
$this->runParticipationTransformer = $runParticipationTransformer; | |
$this->runResultTransformer = $runResultTransformer; | |
} | |
/** | |
* @throws \Common\Exception\InvalidIdException | |
* @throws \Domain\Exception\InvalidRunType | |
*/ | |
public function entityToDomain(Entity $entity): Domain | |
{ | |
$dbParticipations = $entity->getParticipations(); | |
$dbResults = $entity->getResults(); | |
$runnerId = \Common\Id::create($entity->getId()); | |
$participations = $this->runParticipationTransformer->entityToDomainMany($dbParticipations); | |
$results = $this->runResultTransformer->entityToDomainMany($dbResults); | |
return new Domain($runnerId, $entity->getEmail(), $entity->getPassword(), $participations, $results); | |
} | |
public function domainToEntity(Domain $domain): Entity | |
{ | |
$run = $domain->getRun(); | |
$entity = new Entity(); | |
$entity->run_id = (string)$run->getId(); | |
$entity->runnerId = (string)$domain->getRunnerId(); | |
$entity->time = $domain->getTime(); | |
return $entity; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment