/RunnerTransformer.php Secret
Created
March 11, 2019 09:43
-
-
Save tsh-code/d78287898fdc919f7246129a9a829d4d to your computer and use it in GitHub Desktop.
Runner model transformer
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\Eloquent\Transformer; | |
use Infrastructure\Eloquent\Model\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->participations()->get(); | |
$dbResults = $entity->results()->get(); | |
$runnerId = \Common\Id::create($entity->id); | |
$participations = $this->runParticipationTransformer->entityToDomainMany($dbParticipations); | |
$results = $this->runResultTransformer->entityToDomainMany($dbResults); | |
return new Domain($runnerId, $entity->email, $entity->password, $participations, $results); | |
} | |
public function domainToEntity(Domain $domain): Entity | |
{ | |
$entity = new Entity(); | |
$entity->id = (string)$domain->getId(); | |
$entity->email = $domain->getEmail(); | |
$entity->password = $domain->getPassword(); | |
return $entity; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment