mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-09-13 13:57:10 +02:00
Optimized RequestManagement
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\RequestManagement;
|
||||
|
||||
use App\Entity\Source\SourceInterface;
|
||||
use App\Entity\Attribut\TypeAttribut;
|
||||
use App\Entity\Attribut\LayerAttribut;
|
||||
use App\Entity\Attribut\RecieverAttribut;
|
||||
use App\Exception\PreconditionFailedException;
|
||||
use App\Exception\NotSetException;
|
||||
use App\Repository\Source\SourceRepositoryInterface;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*
|
||||
* @todo Check out if the performance of this class can be optimized!
|
||||
*/
|
||||
class RequestedRight implements RequestedRightInterface
|
||||
{
|
||||
use TypeAttribut, LayerAttribut, RecieverAttribut;
|
||||
|
||||
/**
|
||||
* @var SourceRepositoryInterface
|
||||
*/
|
||||
private $sourceRepository;
|
||||
|
||||
/**
|
||||
* @var SourceInterface
|
||||
*/
|
||||
private $source;
|
||||
|
||||
/**
|
||||
* @var RequestedSourceInterface
|
||||
*/
|
||||
private $requestedSource;
|
||||
|
||||
/**
|
||||
* @param SourceRepositoryInterface $sourceRepository
|
||||
*/
|
||||
public function __construct(SourceRepositoryInterface $sourceRepository)
|
||||
{
|
||||
$this->sourceRepository = $sourceRepository;
|
||||
}
|
||||
|
||||
private function loadSource(): void
|
||||
{
|
||||
$this->source = $this->sourceRepository->findOneByIdOrSlug($this->requestedSource);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws PreconditionFailedException If the source has no id or slug
|
||||
*/
|
||||
private function validateRequestedSource(): void
|
||||
{
|
||||
if ($this->requestedSource->hasSlug() || $this->requestedSource->hasId()) {
|
||||
return;
|
||||
}
|
||||
throw new PreconditionFailedException(get_class($this->requestedSource).' needs to have a defined attribut id or slug!');
|
||||
}
|
||||
|
||||
/**
|
||||
* Uses some kind of Lazy loading.
|
||||
*
|
||||
* @see https://en.wikipedia.org/wiki/Lazy_loading
|
||||
* {@inheritdoc}
|
||||
* @see \App\Domain\RequestManagement\RequestedRightInterface::getSource()
|
||||
*/
|
||||
final public function getSource(): SourceInterface
|
||||
{
|
||||
$this->validateRequestedSource();
|
||||
$this->loadSource();
|
||||
$this->validateLoad();
|
||||
|
||||
return $this->source;
|
||||
}
|
||||
|
||||
private function validateLoad(): void
|
||||
{
|
||||
if ($this->source) {
|
||||
return;
|
||||
}
|
||||
throw new NotSetException('The Requested Source couldn\'t be found!');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \App\Domain\RequestManagement\RequestedRightInterface::setRequestedSource()
|
||||
*/
|
||||
final public function setRequestedSource(RequestedSourceInterface $requestedSource)
|
||||
{
|
||||
$this->requestedSource = $requestedSource;
|
||||
}
|
||||
}
|
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\RequestManagement;
|
||||
|
||||
use App\Entity\Attribut\TypeAttributInterface;
|
||||
use App\Entity\Attribut\RecieverAttributInterface;
|
||||
use App\Entity\Attribut\LayerAttributInterface;
|
||||
use App\Entity\Source\SourceInterface;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
interface RequestedRightInterface extends TypeAttributInterface, RecieverAttributInterface, LayerAttributInterface
|
||||
{
|
||||
/**
|
||||
* @param RequestedSourceInterface $requestedSource
|
||||
*/
|
||||
public function setRequestedSource(RequestedSourceInterface $requestedSource);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \App\Entity\Attribut\SourceAttributInterface::getSource()
|
||||
*/
|
||||
public function getSource(): SourceInterface;
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\RequestManagement;
|
||||
|
||||
/**
|
||||
* Allows to use a right as a Service.
|
||||
*
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
final class RequestedRightService extends RequestedRight
|
||||
{
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\RequestManagement;
|
||||
|
||||
/**
|
||||
* Allows to use a right as a Service.
|
||||
*
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
interface RequestedRightServiceInterface extends RequestedRightInterface
|
||||
{
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\RequestManagement;
|
||||
|
||||
use App\Entity\Source\AbstractSource;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
class RequestedSource extends AbstractSource implements RequestedSourceInterface
|
||||
{
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\RequestManagement;
|
||||
|
||||
use App\Entity\Source\SourceInterface;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
interface RequestedSourceInterface extends SourceInterface
|
||||
{
|
||||
}
|
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\RequestManagement;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
final class RequestedSourceService extends RequestedSource implements RequestedSourceServiceInterface
|
||||
{
|
||||
}
|
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\RequestManagement;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
interface RequestedSourceServiceInterface
|
||||
{
|
||||
}
|
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\RequestManagement;
|
||||
|
||||
use App\Entity\Source\SourceInterface;
|
||||
use App\Domain\UserManagement\UserSourceDirectorInterface;
|
||||
use App\Exception\SetNotPossibleException;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
final class RequestedUserRightFacade implements RequestedUserRightFacadeInterface
|
||||
{
|
||||
/**
|
||||
* @var UserSourceDirectorInterface
|
||||
*/
|
||||
private $userSourceDirector;
|
||||
|
||||
/**
|
||||
* @var RequestedRightInterface
|
||||
*/
|
||||
private $requestedRight;
|
||||
|
||||
/**
|
||||
* @param UserSourceDirectorInterface $userSourceDirector
|
||||
*/
|
||||
public function __construct(UserSourceDirectorInterface $userSourceDirector, RequestedRightInterface $requestedRight)
|
||||
{
|
||||
$this->userSourceDirector = $userSourceDirector;
|
||||
$this->requestedRight = $requestedRight;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \App\Entity\Attribut\RecieverAttributInterface::setReciever()
|
||||
*/
|
||||
public function setReciever(SourceInterface $reciever): void
|
||||
{
|
||||
throw new SetNotPossibleException('It\'s not possible to set the reciever!');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \App\Entity\Attribut\RecieverAttributInterface::getReciever()
|
||||
*/
|
||||
public function getReciever(): SourceInterface
|
||||
{
|
||||
return $this->userSourceDirector->getUser()->getSource();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \App\Entity\Attribut\LayerAttributInterface::setLayer()
|
||||
*/
|
||||
public function setLayer(string $layer): void
|
||||
{
|
||||
$this->requestedRight->setLayer($layer);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \App\Entity\Attribut\TypeAttributInterface::getType()
|
||||
*/
|
||||
public function getType(): string
|
||||
{
|
||||
return $this->requestedRight->getType();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \App\Entity\Attribut\LayerAttributInterface::getLayer()
|
||||
*/
|
||||
public function getLayer(): string
|
||||
{
|
||||
return $this->requestedRight->getLayer();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \App\Entity\Attribut\SourceAttributInterface::getSource()
|
||||
*/
|
||||
public function getSource(): SourceInterface
|
||||
{
|
||||
return $this->requestedRight->getSource();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \App\Entity\Attribut\TypeAttributInterface::setType()
|
||||
*/
|
||||
public function setType(string $type): void
|
||||
{
|
||||
$this->requestedRight->setType($type);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \App\Domain\RequestManagement\RequestedRightInterface::setRequestedSource()
|
||||
*/
|
||||
public function setRequestedSource(RequestedSourceInterface $requestedSource)
|
||||
{
|
||||
$this->requestedRight->setRequestedSource($requestedSource);
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\RequestManagement;
|
||||
|
||||
/**
|
||||
* Offers a Service for managing the rights.
|
||||
*
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
interface RequestedUserRightFacadeInterface extends RequestedRightInterface
|
||||
{
|
||||
}
|
Reference in New Issue
Block a user