mirror of
				https://github.com/kevinveenbirkenbach/infinito.git
				synced 2025-10-31 01:09:41 +00:00 
			
		
		
		
	Implemented RightRequestManagement
This commit is contained in:
		| @@ -0,0 +1,106 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Domain\RightManagement\RightRequestManagement; | ||||
|  | ||||
| use Doctrine\ORM\EntityManager; | ||||
| use App\Repository\Source\SourceRepository; | ||||
| use App\Domain\SourceManagement\RequestedSourceInterface; | ||||
| use App\Entity\Source\SourceInterface; | ||||
| use App\Entity\Attribut\TypeAttribut; | ||||
| use App\Entity\Attribut\LayerAttribut; | ||||
| use App\Entity\Attribut\RecieverAttribut; | ||||
|  | ||||
| /** | ||||
|  * @author kevinfrantz | ||||
|  */ | ||||
| class RequestedRight implements RequestedRightInterface | ||||
| { | ||||
|     use TypeAttribut, LayerAttribut, RecieverAttribut; | ||||
|  | ||||
|     /** | ||||
|      * @var SourceRepository | ||||
|      */ | ||||
|     private $sourceRepository; | ||||
|  | ||||
|     /** | ||||
|      * @var SourceInterface | ||||
|      */ | ||||
|     private $source; | ||||
|  | ||||
|     /** | ||||
|      * @var RequestedSourceInterface | ||||
|      */ | ||||
|     private $requestedSource; | ||||
|  | ||||
|     /** | ||||
|      * @param EntityManager $entityManager | ||||
|      */ | ||||
|     public function __construct(SourceRepository $sourceRepository) | ||||
|     { | ||||
|         $this->sourceRepository = $sourceRepository; | ||||
|     } | ||||
|  | ||||
|     private function loadSource(): void | ||||
|     { | ||||
|         $this->source = $this->sourceRepository->findOneByIdOrSlug($this->requestedSource); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return bool | ||||
|      */ | ||||
|     private function isIdEquals(): bool | ||||
|     { | ||||
|         if ($this->requestedSource->hasId() && $this->source->hasId()) { | ||||
|             return false; | ||||
|         } | ||||
|  | ||||
|         return $this->requestedSource->getId() === $this->source->getId(); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return bool | ||||
|      */ | ||||
|     private function isSlugEquals(): bool | ||||
|     { | ||||
|         if ($this->requestedSource->hasSlug() && $this->source->hasSlug()) { | ||||
|             return false; | ||||
|         } | ||||
|  | ||||
|         return $this->requestedSource->getSlug() === $this->source->getSlug(); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return bool Tells if a reload of the source is neccessary | ||||
|      */ | ||||
|     private function isReloadNeccessary(): bool | ||||
|     { | ||||
|         return $this->isIdEquals() && $this->isSlugEquals(); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Uses some kind of Lazy loading. | ||||
|      * | ||||
|      * @see https://en.wikipedia.org/wiki/Lazy_loading | ||||
|      * {@inheritdoc} | ||||
|      * @see \App\Domain\RightManagement\RightRequestManagement\RequestedRightInterface::getSource() | ||||
|      */ | ||||
|     final public function getSource(): SourceInterface | ||||
|     { | ||||
|         if ($this->isReloadNeccessary()) { | ||||
|             $this->loadSource(); | ||||
|         } | ||||
|  | ||||
|         return $this->source; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * {@inheritdoc} | ||||
|      * | ||||
|      * @see \App\Domain\RightManagement\RightRequestManagement\RequestedRightInterface::setRequestedSource() | ||||
|      */ | ||||
|     final public function setRequestedSource(RequestedSourceInterface $requestedSource) | ||||
|     { | ||||
|         $this->requestedSource = $requestedSource; | ||||
|         $this->loadSource(); | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,27 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Domain\RightManagement\RightRequestManagement; | ||||
|  | ||||
| use App\Entity\Attribut\TypeAttributInterface; | ||||
| use App\Entity\Attribut\RecieverAttributInterface; | ||||
| use App\Entity\Attribut\LayerAttributInterface; | ||||
| use App\Domain\SourceManagement\RequestedSourceInterface; | ||||
| 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\RightManagement\RightRequestManagement; | ||||
|  | ||||
| /** | ||||
|  * Allows to use a right as a Service. | ||||
|  * | ||||
|  * @author kevinfrantz | ||||
|  */ | ||||
| final class RequestedRightService extends RequestedRight | ||||
| { | ||||
| } | ||||
| @@ -0,0 +1,12 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Domain\RightManagement\RightRequestManagement; | ||||
|  | ||||
| /** | ||||
|  * Allows to use a right as a Service. | ||||
|  * | ||||
|  * @author kevinfrantz | ||||
|  */ | ||||
| interface RequestedRightServiceInterface extends RequestedRightInterface | ||||
| { | ||||
| } | ||||
| @@ -0,0 +1,112 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Domain\RightManagement\RightRequestManagement; | ||||
|  | ||||
| use App\Entity\Source\SourceInterface; | ||||
| use App\Domain\SourceManagement\RequestedSourceInterface; | ||||
| use App\Domain\UserManagement\UserSourceDirectorInterface; | ||||
|  | ||||
| /** | ||||
|  * @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 | ||||
|     { | ||||
|         $this->requestedRight->setReciever($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\RightManagement\RightRequestManagement\RequestedRightInterface::setRequestedSource() | ||||
|      */ | ||||
|     public function setRequestedSource(RequestedSourceInterface $requestedSource) | ||||
|     { | ||||
|         $this->requestedRight->setRequestedSource($requestedSource); | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,12 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Domain\RightManagement\RightRequestManagement; | ||||
|  | ||||
| /** | ||||
|  * Offers a Service for managing the rights. | ||||
|  * | ||||
|  * @author kevinfrantz | ||||
|  */ | ||||
| interface RequestedUserRightFacadeInterface extends RequestedRightInterface | ||||
| { | ||||
| } | ||||
| @@ -1,47 +0,0 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Domain\RightManagement; | ||||
|  | ||||
| use App\Entity\Meta\Right; | ||||
| use App\Entity\Source\SourceInterface; | ||||
| use App\Exception\SetNotPossibleException; | ||||
| use App\Domain\UserManagement\UserSourceDirectorInterface; | ||||
|  | ||||
| /** | ||||
|  * @author kevinfrantz | ||||
|  */ | ||||
| final class UserRight extends Right implements UserRightInterface | ||||
| { | ||||
|     /** | ||||
|      * @var UserSourceDirectorInterface | ||||
|      */ | ||||
|     private $userSourceDirector; | ||||
|  | ||||
|     /** | ||||
|      * @param UserSourceDirectorInterface $userSourceDirector | ||||
|      */ | ||||
|     public function __construct(UserSourceDirectorInterface $userSourceDirector) | ||||
|     { | ||||
|         $this->userSourceDirector = $userSourceDirector; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * {@inheritdoc} | ||||
|      * | ||||
|      * @see \App\Entity\Attribut\RecieverAttributInterface::setReciever() | ||||
|      */ | ||||
|     public function setReciever(SourceInterface $reciever): void | ||||
|     { | ||||
|         throw new SetNotPossibleException('This class doesn\'t allow to set a reciever!'); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * {@inheritdoc} | ||||
|      * | ||||
|      * @see \App\Entity\Attribut\RecieverAttributInterface::getReciever() | ||||
|      */ | ||||
|     public function getReciever(): SourceInterface | ||||
|     { | ||||
|         return $this->userSourceDirector->getUser()->getSource(); | ||||
|     } | ||||
| } | ||||
| @@ -1,14 +0,0 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Domain\RightManagement; | ||||
|  | ||||
| use App\Entity\Meta\RightInterface; | ||||
|  | ||||
| /** | ||||
|  * Offers a Service for managing the rights. | ||||
|  * | ||||
|  * @author kevinfrantz | ||||
|  */ | ||||
| interface UserRightInterface extends RightInterface | ||||
| { | ||||
| } | ||||
| @@ -4,7 +4,6 @@ namespace App\Domain\SecureCRUDManagement\CRUD\Read; | ||||
|  | ||||
| use App\Entity\Source\SourceInterface; | ||||
| use App\Entity\Meta\RightInterface; | ||||
| use Doctrine\Common\Persistence\ObjectRepository; | ||||
| use App\Domain\SecureManagement\SecureSourceChecker; | ||||
| use App\Exception\SourceAccessDenied; | ||||
| use Doctrine\ORM\EntityManagerInterface; | ||||
| @@ -53,6 +52,7 @@ final class SecureSourceReadService extends AbstractSecureCRUDService //implemen | ||||
|  | ||||
|     /** | ||||
|      * @todo This will not work! Change interface to requested right! | ||||
|      * | ||||
|      * @param RightInterface $requestedRight | ||||
|      * | ||||
|      * @return EntityInterface | ||||
|   | ||||
		Reference in New Issue
	
	Block a user