mirror of
				https://github.com/kevinveenbirkenbach/infinito.git
				synced 2025-11-04 03:07:58 +00:00 
			
		
		
		
	Optimized RequestManagement
This commit is contained in:
		@@ -1,16 +1,14 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace App\Domain\RightManagement\RightRequestManagement;
 | 
			
		||||
namespace App\Domain\RequestManagement;
 | 
			
		||||
 | 
			
		||||
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;
 | 
			
		||||
use App\Exception\PreconditionFailedException;
 | 
			
		||||
use App\Exception\NotSetException;
 | 
			
		||||
use App\Repository\Source\SourceRepositoryInterface;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
@@ -22,7 +20,7 @@ class RequestedRight implements RequestedRightInterface
 | 
			
		||||
    use TypeAttribut, LayerAttribut, RecieverAttribut;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @var SourceRepository
 | 
			
		||||
     * @var SourceRepositoryInterface
 | 
			
		||||
     */
 | 
			
		||||
    private $sourceRepository;
 | 
			
		||||
 | 
			
		||||
@@ -37,9 +35,9 @@ class RequestedRight implements RequestedRightInterface
 | 
			
		||||
    private $requestedSource;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param EntityManager $entityManager
 | 
			
		||||
     * @param SourceRepositoryInterface $sourceRepository
 | 
			
		||||
     */
 | 
			
		||||
    public function __construct(SourceRepository $sourceRepository)
 | 
			
		||||
    public function __construct(SourceRepositoryInterface $sourceRepository)
 | 
			
		||||
    {
 | 
			
		||||
        $this->sourceRepository = $sourceRepository;
 | 
			
		||||
    }
 | 
			
		||||
@@ -65,7 +63,7 @@ class RequestedRight implements RequestedRightInterface
 | 
			
		||||
     *
 | 
			
		||||
     * @see https://en.wikipedia.org/wiki/Lazy_loading
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     * @see \App\Domain\RightManagement\RightRequestManagement\RequestedRightInterface::getSource()
 | 
			
		||||
     * @see \App\Domain\RequestManagement\RequestedRightInterface::getSource()
 | 
			
		||||
     */
 | 
			
		||||
    final public function getSource(): SourceInterface
 | 
			
		||||
    {
 | 
			
		||||
@@ -87,7 +85,7 @@ class RequestedRight implements RequestedRightInterface
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     *
 | 
			
		||||
     * @see \App\Domain\RightManagement\RightRequestManagement\RequestedRightInterface::setRequestedSource()
 | 
			
		||||
     * @see \App\Domain\RequestManagement\RequestedRightInterface::setRequestedSource()
 | 
			
		||||
     */
 | 
			
		||||
    final public function setRequestedSource(RequestedSourceInterface $requestedSource)
 | 
			
		||||
    {
 | 
			
		||||
@@ -1,11 +1,10 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace App\Domain\RightManagement\RightRequestManagement;
 | 
			
		||||
namespace App\Domain\RequestManagement;
 | 
			
		||||
 | 
			
		||||
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;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace App\Domain\RightManagement\RightRequestManagement;
 | 
			
		||||
namespace App\Domain\RequestManagement;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Allows to use a right as a Service.
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace App\Domain\RightManagement\RightRequestManagement;
 | 
			
		||||
namespace App\Domain\RequestManagement;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Allows to use a right as a Service.
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace App\Domain\SourceManagement;
 | 
			
		||||
namespace App\Domain\RequestManagement;
 | 
			
		||||
 | 
			
		||||
use App\Entity\Source\AbstractSource;
 | 
			
		||||
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace App\Domain\SourceManagement;
 | 
			
		||||
namespace App\Domain\RequestManagement;
 | 
			
		||||
 | 
			
		||||
use App\Entity\Source\SourceInterface;
 | 
			
		||||
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace App\Domain\SourceManagement;
 | 
			
		||||
namespace App\Domain\RequestManagement;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
@@ -0,0 +1,10 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace App\Domain\RequestManagement;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 */
 | 
			
		||||
interface RequestedSourceServiceInterface
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
@@ -1,10 +1,10 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace App\Domain\RightManagement\RightRequestManagement;
 | 
			
		||||
namespace App\Domain\RequestManagement;
 | 
			
		||||
 | 
			
		||||
use App\Entity\Source\SourceInterface;
 | 
			
		||||
use App\Domain\SourceManagement\RequestedSourceInterface;
 | 
			
		||||
use App\Domain\UserManagement\UserSourceDirectorInterface;
 | 
			
		||||
use App\Exception\SetNotPossibleException;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
@@ -37,7 +37,7 @@ final class RequestedUserRightFacade implements RequestedUserRightFacadeInterfac
 | 
			
		||||
     */
 | 
			
		||||
    public function setReciever(SourceInterface $reciever): void
 | 
			
		||||
    {
 | 
			
		||||
        $this->requestedRight->setReciever($reciever);
 | 
			
		||||
        throw new SetNotPossibleException('It\'s not possible to set the reciever!');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -103,7 +103,7 @@ final class RequestedUserRightFacade implements RequestedUserRightFacadeInterfac
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     *
 | 
			
		||||
     * @see \App\Domain\RightManagement\RightRequestManagement\RequestedRightInterface::setRequestedSource()
 | 
			
		||||
     * @see \App\Domain\RequestManagement\RequestedRightInterface::setRequestedSource()
 | 
			
		||||
     */
 | 
			
		||||
    public function setRequestedSource(RequestedSourceInterface $requestedSource)
 | 
			
		||||
    {
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace App\Domain\RightManagement\RightRequestManagement;
 | 
			
		||||
namespace App\Domain\RequestManagement;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Offers a Service for managing the rights.
 | 
			
		||||
@@ -1,7 +0,0 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace App\Domain\SourceManagement;
 | 
			
		||||
 | 
			
		||||
interface RequestedSourceServiceInterface
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
@@ -3,10 +3,9 @@
 | 
			
		||||
namespace App\Domain\UserManagement;
 | 
			
		||||
 | 
			
		||||
use App\Entity\UserInterface;
 | 
			
		||||
use Doctrine\ORM\EntityManagerInterface;
 | 
			
		||||
use App\DBAL\Types\SystemSlugType;
 | 
			
		||||
use App\Entity\User;
 | 
			
		||||
use App\Repository\Source\SourceRepository;
 | 
			
		||||
use App\Repository\Source\SourceRepositoryInterface;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
@@ -19,7 +18,7 @@ final class UserSourceDirector implements UserSourceDirectorInterface
 | 
			
		||||
    private $user;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @var SourceRepository
 | 
			
		||||
     * @var SourceRepositoryInterface
 | 
			
		||||
     */
 | 
			
		||||
    private $sourceRepository;
 | 
			
		||||
 | 
			
		||||
@@ -38,10 +37,10 @@ final class UserSourceDirector implements UserSourceDirectorInterface
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param EntityManagerInterface $entityManager
 | 
			
		||||
     * @param UserInterface          $user
 | 
			
		||||
     * @param SourceRepositoryInterface $sourceRepository
 | 
			
		||||
     * @param UserInterface             $user
 | 
			
		||||
     */
 | 
			
		||||
    public function __construct(SourceRepository $sourceRepository, ?UserInterface $user)
 | 
			
		||||
    public function __construct(SourceRepositoryInterface $sourceRepository, ?UserInterface $user)
 | 
			
		||||
    {
 | 
			
		||||
        $this->sourceRepository = $sourceRepository;
 | 
			
		||||
        $this->setUser($user);
 | 
			
		||||
 
 | 
			
		||||
@@ -4,15 +4,13 @@ namespace App\Repository\Source;
 | 
			
		||||
 | 
			
		||||
use Doctrine\ORM\EntityRepository;
 | 
			
		||||
use App\Entity\Source\SourceInterface;
 | 
			
		||||
use App\Domain\SourceManagement\RequestedSourceInterface;
 | 
			
		||||
use App\Domain\RequestManagement\RequestedSourceInterface;
 | 
			
		||||
 | 
			
		||||
final class SourceRepository extends EntityRepository
 | 
			
		||||
/**
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 */
 | 
			
		||||
final class SourceRepository extends EntityRepository implements SourceRepositoryInterface
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * @param string $slug
 | 
			
		||||
     *
 | 
			
		||||
     * @return SourceInterface|null
 | 
			
		||||
     */
 | 
			
		||||
    public function findOneBySlug(string $slug): ?SourceInterface
 | 
			
		||||
    {
 | 
			
		||||
        return $this->findOneBy([
 | 
			
		||||
@@ -20,13 +18,6 @@ final class SourceRepository extends EntityRepository
 | 
			
		||||
        ]);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Loads a source by id or if not defined, by slug.
 | 
			
		||||
     *
 | 
			
		||||
     * @param RequestedSourceInterface $requestedSource
 | 
			
		||||
     *
 | 
			
		||||
     * @return SourceInterface|null
 | 
			
		||||
     */
 | 
			
		||||
    public function findOneByIdOrSlug(RequestedSourceInterface $requestedSource): ?SourceInterface
 | 
			
		||||
    {
 | 
			
		||||
        if ($requestedSource->hasId()) {
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,32 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace App\Repository\Source;
 | 
			
		||||
 | 
			
		||||
use Doctrine\Common\Persistence\ObjectRepository;
 | 
			
		||||
use Doctrine\Common\Collections\Selectable;
 | 
			
		||||
use App\Entity\Source\SourceInterface;
 | 
			
		||||
use App\Domain\RequestManagement\RequestedSourceInterface;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 */
 | 
			
		||||
interface SourceRepositoryInterface extends ObjectRepository, Selectable
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * Finds an Entity by slug.
 | 
			
		||||
     *
 | 
			
		||||
     * @param string $slug
 | 
			
		||||
     *
 | 
			
		||||
     * @return SourceInterface|null
 | 
			
		||||
     */
 | 
			
		||||
    public function findOneBySlug(string $slug): ?SourceInterface;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Loads a source by id or if not defined, by slug.
 | 
			
		||||
     *
 | 
			
		||||
     * @param RequestedSourceInterface $requestedSource
 | 
			
		||||
     *
 | 
			
		||||
     * @return SourceInterface|null
 | 
			
		||||
     */
 | 
			
		||||
    public function findOneByIdOrSlug(RequestedSourceInterface $requestedSource): ?SourceInterface;
 | 
			
		||||
}
 | 
			
		||||
@@ -1,15 +1,15 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace tests\Unit\Domain\RightManagement\RightRequestManagement;
 | 
			
		||||
namespace tests\Unit\Domain\RequestManagement;
 | 
			
		||||
 | 
			
		||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
 | 
			
		||||
use App\Domain\RightManagement\RightRequestManagement\RequestedRightInterface;
 | 
			
		||||
use App\Domain\RightManagement\RightRequestManagement\RequestedRight;
 | 
			
		||||
use App\Domain\RequestManagement\RequestedRightInterface;
 | 
			
		||||
use App\Domain\RequestManagement\RequestedRight;
 | 
			
		||||
use App\Entity\Source\AbstractSource;
 | 
			
		||||
use App\DBAL\Types\Meta\Right\LayerType;
 | 
			
		||||
use App\Domain\SourceManagement\RequestedSource;
 | 
			
		||||
use App\Domain\RequestManagement\RequestedSource;
 | 
			
		||||
use App\DBAL\Types\SystemSlugType;
 | 
			
		||||
use App\Domain\SourceManagement\RequestedSourceInterface;
 | 
			
		||||
use App\Domain\RequestManagement\RequestedSourceInterface;
 | 
			
		||||
use App\Exception\PreconditionFailedException;
 | 
			
		||||
use App\Exception\NotSetException;
 | 
			
		||||
 | 
			
		||||
@@ -0,0 +1,86 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace tests\Unit\Domain\RightManagement;
 | 
			
		||||
 | 
			
		||||
use PHPUnit\Framework\TestCase;
 | 
			
		||||
use App\Entity\User;
 | 
			
		||||
use App\Domain\RequestManagement\RequestedUserRightFacade;
 | 
			
		||||
use App\DBAL\Types\Meta\Right\LayerType;
 | 
			
		||||
use App\DBAL\Types\Meta\Right\CRUDType;
 | 
			
		||||
use App\Entity\Source\AbstractSource;
 | 
			
		||||
use App\Domain\UserManagement\UserSourceDirectorInterface;
 | 
			
		||||
use App\Domain\RequestManagement\RequestedRightInterface;
 | 
			
		||||
use App\Domain\RequestManagement\RequestedRight;
 | 
			
		||||
use App\Domain\UserManagement\UserSourceDirector;
 | 
			
		||||
use App\Repository\Source\SourceRepositoryInterface;
 | 
			
		||||
use App\Domain\RequestManagement\RequestedSourceInterface;
 | 
			
		||||
use App\DBAL\Types\SystemSlugType;
 | 
			
		||||
use App\Exception\NotSetException;
 | 
			
		||||
use App\Exception\SetNotPossibleException;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 */
 | 
			
		||||
class RequestedUserRightFacadeTest extends TestCase
 | 
			
		||||
{
 | 
			
		||||
    public function testInterface(): void
 | 
			
		||||
    {
 | 
			
		||||
        $userSourceDirector = $this->createMock(UserSourceDirectorInterface::class);
 | 
			
		||||
        $requestedRight = $this->createMock(RequestedRightInterface::class);
 | 
			
		||||
        $requestedUserRightFacade = new RequestedUserRightFacade($userSourceDirector, $requestedRight);
 | 
			
		||||
        $this->assertInstanceOf(RequestedRightInterface::class, $requestedUserRightFacade);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetters(): void
 | 
			
		||||
    {
 | 
			
		||||
        $reciever = $this->createMock(AbstractSource::class);
 | 
			
		||||
        $user = $this->createMock(User::class);
 | 
			
		||||
        $user->method('getSource')->willReturn($reciever);
 | 
			
		||||
        $layer = LayerType::SOURCE;
 | 
			
		||||
        $type = CRUDType::READ;
 | 
			
		||||
        $source = $this->createMock(AbstractSource::class);
 | 
			
		||||
        $reciever = $this->createMock(AbstractSource::class);
 | 
			
		||||
        $userSourceDirector = $this->createMock(UserSourceDirectorInterface::class);
 | 
			
		||||
        $userSourceDirector->method('getUser')->willReturn($user);
 | 
			
		||||
        $requestedRight = $this->createMock(RequestedRightInterface::class);
 | 
			
		||||
        $requestedRight->method('getLayer')->willReturn($layer);
 | 
			
		||||
        $requestedRight->method('getType')->willReturn($type);
 | 
			
		||||
        $requestedRight->method('getSource')->willReturn($source);
 | 
			
		||||
        $requestedUserRightFacade = new RequestedUserRightFacade($userSourceDirector, $requestedRight);
 | 
			
		||||
        $this->assertEquals($layer, $requestedUserRightFacade->getLayer());
 | 
			
		||||
        $this->assertEquals($type, $requestedUserRightFacade->getType());
 | 
			
		||||
        $this->assertEquals($source, $requestedUserRightFacade->getSource());
 | 
			
		||||
        $this->assertEquals($reciever, $requestedUserRightFacade->getReciever());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testSetters(): void
 | 
			
		||||
    {
 | 
			
		||||
        $layer = LayerType::SOURCE;
 | 
			
		||||
        $type = CRUDType::READ;
 | 
			
		||||
        $requestedSource = $this->createMock(RequestedSourceInterface::class);
 | 
			
		||||
        $requestedSource->method('getSlug')->willReturn(SystemSlugType::IMPRINT);
 | 
			
		||||
        $requestedSource->method('hasSlug')->willReturn(true);
 | 
			
		||||
        $sourceRepository = $this->createMock(SourceRepositoryInterface::class);
 | 
			
		||||
        $requestedRight = new RequestedRight($sourceRepository);
 | 
			
		||||
        $user = $this->createMock(User::class);
 | 
			
		||||
        $userSourceDirector = new UserSourceDirector($sourceRepository, $user);
 | 
			
		||||
        $requestedUserRightFacade = new RequestedUserRightFacade($userSourceDirector, $requestedRight);
 | 
			
		||||
        $this->assertNull($requestedUserRightFacade->setLayer($layer));
 | 
			
		||||
        $this->assertNull($requestedUserRightFacade->setType($type));
 | 
			
		||||
        $this->assertNull($requestedUserRightFacade->setRequestedSource($requestedSource));
 | 
			
		||||
        $this->assertEquals($layer, $requestedRight->getLayer());
 | 
			
		||||
        $this->assertEquals($type, $requestedRight->getType());
 | 
			
		||||
        $this->expectException(NotSetException::class);
 | 
			
		||||
        $this->assertNotInstanceOf(RequestedSourceInterface::class, $requestedRight->getSource());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testSetReciever(): void
 | 
			
		||||
    {
 | 
			
		||||
        $reciever = $this->createMock(AbstractSource::class);
 | 
			
		||||
        $userSourceDirector = $this->createMock(UserSourceDirectorInterface::class);
 | 
			
		||||
        $requestedRight = $this->createMock(RequestedRightInterface::class);
 | 
			
		||||
        $requestedUserRightFacade = new RequestedUserRightFacade($userSourceDirector, $requestedRight);
 | 
			
		||||
        $this->expectException(SetNotPossibleException::class);
 | 
			
		||||
        $requestedUserRightFacade->setReciever($reciever);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,23 +0,0 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace tests\Unit\Domain\RightManagement;
 | 
			
		||||
 | 
			
		||||
use PHPUnit\Framework\TestCase;
 | 
			
		||||
use App\Entity\User;
 | 
			
		||||
use App\Entity\Source\SourceInterface;
 | 
			
		||||
use App\Domain\RightManagement\UserRightService;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 */
 | 
			
		||||
class UserRightServiceTest extends TestCase
 | 
			
		||||
{
 | 
			
		||||
    public function testUserSet(): void
 | 
			
		||||
    {
 | 
			
		||||
        $user = new User();
 | 
			
		||||
        $source = $this->createMock(SourceInterface::class);
 | 
			
		||||
        $user->setSource($source);
 | 
			
		||||
        $userRight = new UserRightService($user);
 | 
			
		||||
        $this->assertEquals($source, $userRight->getReciever());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user