Optimized RequestedRight to load Source via RequestedEntity

This commit is contained in:
Kevin Frantz 2019-01-26 18:03:55 +01:00
parent edda341d59
commit a96c1b396e
2 changed files with 32 additions and 15 deletions

View File

@ -102,4 +102,18 @@ class RequestedEntity extends AbstractEntity implements RequestedEntityInterface
return $repository->find($this->id);
}
/**
* Overriding is neccessary to declare the correct relation
* {@inheritdoc}
*
* @see \App\Attribut\RequestedRightAttributInterface::setRequestedRight()
*/
public function setRequestedRight($requestedRight): void
{
$this->requestedRight = $requestedRight;
if ($this->requestedRight !== $this) {
$this->requestedRight->setRequestedEntity($this);
}
}
}

View File

@ -8,9 +8,10 @@ use App\Attribut\LayerAttribut;
use App\Attribut\RecieverAttribut;
use App\Exception\PreconditionFailedException;
use App\Exception\NotSetException;
use App\Repository\Source\SourceRepositoryInterface;
use App\Domain\RequestManagement\Entity\RequestedEntityInterface;
use App\Attribut\RequestedEntityAttribut;
use App\Entity\Meta\MetaInterface;
use App\Exception\NotCorrectInstanceException;
/**
* @author kevinfrantz
@ -21,11 +22,6 @@ class RequestedRight implements RequestedRightInterface
{
use CrudAttribut, LayerAttribut, RecieverAttribut, RequestedEntityAttribut;
/**
* @var SourceRepositoryInterface
*/
private $sourceRepository;
/**
* @var SourceInterface
*/
@ -37,16 +33,18 @@ class RequestedRight implements RequestedRightInterface
private $requestedEntity;
/**
* @param SourceRepositoryInterface $sourceRepository
* @throws NotCorrectInstanceException
*/
public function __construct(SourceRepositoryInterface $sourceRepository)
{
$this->sourceRepository = $sourceRepository;
}
private function loadSource(): void
{
$this->source = $this->sourceRepository->findOneByIdOrSlug($this->requestedEntity);
$entity = $this->requestedEntity->getEntity();
if ($entity instanceof SourceInterface) {
$this->source = $entity;
}
if ($entity instanceof MetaInterface) {
$this->source = $entity->getSource();
}
throw new NotCorrectInstanceException('The entity instance can\'t be processed');
}
/**
@ -85,12 +83,17 @@ class RequestedRight implements RequestedRightInterface
}
/**
* Overriding is neccessary to declare the correct relation.
*
* {@inheritdoc}
*
* @see \App\Domain\RequestManagement\Right\RequestedRightInterface::setRequestedEntity()
*/
final public function setRequestedEntity(RequestedEntityInterface $requestedSource): void
final public function setRequestedEntity(RequestedEntityInterface $requestedEntity): void
{
$this->requestedEntity = $requestedSource;
$this->requestedEntity = $requestedEntity;
if ($requestedEntity->getRequestedRight() !== $this) {
$this->requestedEntity->setRequestedRight($this);
}
}
}