mirror of
				https://github.com/kevinveenbirkenbach/infinito.git
				synced 2025-11-03 18:58:01 +00:00 
			
		
		
		
	In between commit implementing crud draft
This commit is contained in:
		@@ -9,14 +9,16 @@ use App\Entity\Meta\RightInterface;
 | 
			
		||||
use App\Domain\UserManagement\UserIdentityManager;
 | 
			
		||||
use FOS\RestBundle\View\ViewHandlerInterface;
 | 
			
		||||
use App\Entity\Source\SourceInterface;
 | 
			
		||||
use App\Domain\SecureLoadManagement\SecureSourceLoader;
 | 
			
		||||
use FOS\RestBundle\View\View;
 | 
			
		||||
use App\Exception\AllreadyDefinedException;
 | 
			
		||||
use App\Domain\SecureCRUDManagement\CRUD\Read\SecureSourceReadService;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 *
 | 
			
		||||
 * @todo Implement as a service!
 | 
			
		||||
 */
 | 
			
		||||
class SourceRESTResponseManager implements SourceRESTResponseManagerInterface
 | 
			
		||||
final class SourceRESTResponseManager implements SourceRESTResponseManagerInterface
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * @var UserInterface
 | 
			
		||||
@@ -64,14 +66,14 @@ class SourceRESTResponseManager implements SourceRESTResponseManagerInterface
 | 
			
		||||
        $this->setView();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected function setView(): void
 | 
			
		||||
    private function setView(): void
 | 
			
		||||
    {
 | 
			
		||||
        $this->view = new View($this->loadedSource, 200);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private function setLoadedSource(): void
 | 
			
		||||
    {
 | 
			
		||||
        $secureSourceLoader = new SecureSourceLoader($this->entityManager, $this->requestedRight);
 | 
			
		||||
        $secureSourceLoader = new SecureSourceReadService($this->entityManager, $this->requestedRight);
 | 
			
		||||
        $this->loadedSource = $secureSourceLoader->getSource();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -100,6 +102,11 @@ class SourceRESTResponseManager implements SourceRESTResponseManagerInterface
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     *
 | 
			
		||||
     * @see \App\Domain\ResponseManagement\SourceRESTResponseManagerInterface::getResponse()
 | 
			
		||||
     */
 | 
			
		||||
    public function getResponse(): Response
 | 
			
		||||
    {
 | 
			
		||||
        return $this->viewHandler->handle($this->view);
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,40 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace App\Domain\SecureCRUDManagement;
 | 
			
		||||
 | 
			
		||||
use Symfony\Component\Security\Core\Security;
 | 
			
		||||
use Symfony\Component\HttpFoundation\RequestStack;
 | 
			
		||||
use Doctrine\ORM\EntityManagerInterface;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 */
 | 
			
		||||
abstract class AbstractSecureCRUDService
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * @var RequestStack
 | 
			
		||||
     */
 | 
			
		||||
    protected $requestStack;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @var Security
 | 
			
		||||
     */
 | 
			
		||||
    protected $security;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @var EntityManagerInterface
 | 
			
		||||
     */
 | 
			
		||||
    protected $entityManager;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param RequestStack           $requestStack
 | 
			
		||||
     * @param Security               $security
 | 
			
		||||
     * @param EntityManagerInterface $entityManager
 | 
			
		||||
     */
 | 
			
		||||
    public function __construct(RequestStack $requestStack, Security $security, EntityManagerInterface $entityManager)
 | 
			
		||||
    {
 | 
			
		||||
        $this->requestStack = $requestStack;
 | 
			
		||||
        $this->security = $security;
 | 
			
		||||
        $this->entityManager = $entityManager;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,10 +0,0 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace App\Domain\SecureCRUDManagement\CRUD;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 */
 | 
			
		||||
abstract class AbstractSecureCRUD implements SecureCRUDInterface
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,12 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace App\Domain\SecureCRUDManagement\CRUD;
 | 
			
		||||
 | 
			
		||||
use App\Domain\SecureCRUDManagement\AbstractSecureCRUDService as AbstractSecureCRUDServiceParent;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 */
 | 
			
		||||
abstract class AbstractSecureCRUDService extends AbstractSecureCRUDServiceParent implements SecureCRUDServiceInterface
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
@@ -1,12 +0,0 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace App\Domain\SecureCRUDManagement\CRUD\Create;
 | 
			
		||||
 | 
			
		||||
use App\Domain\SecureCRUDManagement\CRUD\AbstractSecureCRUD;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 */
 | 
			
		||||
abstract class AbstractSecureCreate extends AbstractSecureCRUD implements SecureCreateInterface
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,12 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace App\Domain\SecureCRUDManagement\CRUD\Create;
 | 
			
		||||
 | 
			
		||||
use App\Domain\SecureCRUDManagement\CRUD\AbstractSecureCRUDService;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 */
 | 
			
		||||
abstract class AbstractSecureCreateService extends AbstractSecureCRUDService implements SecureCreateServiceInterface
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
@@ -3,14 +3,14 @@
 | 
			
		||||
namespace App\Domain\SecureCRUDManagement\CRUD\Create;
 | 
			
		||||
 | 
			
		||||
use App\Entity\EntityInterface;
 | 
			
		||||
use App\Domain\SecureCRUDManagement\CRUD\SecureCRUDInterface;
 | 
			
		||||
use App\Domain\SecureCRUDManagement\CRUD\SecureCRUDServiceInterface;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @todo Implement!
 | 
			
		||||
 *
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 */
 | 
			
		||||
interface SecureCreateInterface extends SecureCRUDInterface
 | 
			
		||||
interface SecureCreateServiceInterface extends SecureCRUDServiceInterface
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * @return EntityInterface The created entity
 | 
			
		||||
@@ -7,7 +7,7 @@ use App\Entity\EntityInterface;
 | 
			
		||||
/**
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 */
 | 
			
		||||
final class SecureHeredityCreate extends AbstractSecureCreate
 | 
			
		||||
final class SecureHeredityCreateService extends AbstractSecureCreateService
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * @todo Implement
 | 
			
		||||
@@ -7,7 +7,7 @@ use App\Entity\EntityInterface;
 | 
			
		||||
/**
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 */
 | 
			
		||||
final class SecureMemberCreate extends AbstractSecureCreate
 | 
			
		||||
final class SecureMemberCreateService extends AbstractSecureCreateService
 | 
			
		||||
{
 | 
			
		||||
    public function create(): EntityInterface
 | 
			
		||||
    {
 | 
			
		||||
@@ -7,7 +7,7 @@ use App\Entity\EntityInterface;
 | 
			
		||||
/**
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 */
 | 
			
		||||
final class SecureRightCreate extends AbstractSecureCreate
 | 
			
		||||
final class SecureRightCreateService extends AbstractSecureCreateService
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * @todo Implement!
 | 
			
		||||
@@ -10,12 +10,10 @@ use App\Entity\Source\Primitive\Text\TextSource;
 | 
			
		||||
 *
 | 
			
		||||
 * @todo Implement!
 | 
			
		||||
 */
 | 
			
		||||
final class SecureSourceCreate extends AbstractSecureCreate
 | 
			
		||||
final class SecureSourceCreateService extends AbstractSecureCreateService
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     *
 | 
			
		||||
     * @see \App\Domain\SecureCRUDManagement\CRUD\Create\SecureCreatorInterface::create()
 | 
			
		||||
     * @return EntityInterface
 | 
			
		||||
     */
 | 
			
		||||
    public function create(): EntityInterface
 | 
			
		||||
    {
 | 
			
		||||
@@ -0,0 +1,12 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace App\Domain\SecureCRUDManagement\CRUD\Read;
 | 
			
		||||
 | 
			
		||||
use App\Domain\SecureCRUDManagement\CRUD\AbstractSecureCRUDService;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 */
 | 
			
		||||
abstract class AbstractSecureReadService extends AbstractSecureCRUDService implements SecureReadServiceInterface
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,21 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace App\Domain\SecureCRUDManagement\CRUD\Read;
 | 
			
		||||
 | 
			
		||||
use App\Entity\EntityInterface;
 | 
			
		||||
use App\Entity\Meta\RightInterface;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 */
 | 
			
		||||
final class SecureLawReadService extends AbstractSecureReadService
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     *
 | 
			
		||||
     * @see \App\Domain\SecureCRUDManagement\CRUD\Read\SecureReadServiceInterface::read()
 | 
			
		||||
     */
 | 
			
		||||
    public function read(RightInterface $requestedRight): EntityInterface
 | 
			
		||||
    {
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,21 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace App\Domain\SecureCRUDManagement\CRUD\Read;
 | 
			
		||||
 | 
			
		||||
use App\Entity\EntityInterface;
 | 
			
		||||
use App\Entity\Meta\RightInterface;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 */
 | 
			
		||||
class SecureMemberReadService extends AbstractSecureReadService
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     *
 | 
			
		||||
     * @see \App\Domain\SecureCRUDManagement\CRUD\Read\SecureReadServiceInterface::read()
 | 
			
		||||
     */
 | 
			
		||||
    public function read(RightInterface $requestedRight): EntityInterface
 | 
			
		||||
    {
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,20 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace App\Domain\SecureCRUDManagement\CRUD\Read;
 | 
			
		||||
 | 
			
		||||
use App\Domain\SecureCRUDManagement\CRUD\SecureCRUDServiceInterface;
 | 
			
		||||
use App\Entity\EntityInterface;
 | 
			
		||||
use App\Entity\Meta\RightInterface;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 */
 | 
			
		||||
interface SecureReadServiceInterface extends SecureCRUDServiceInterface
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * @param RightInterface $requestedRight
 | 
			
		||||
     *
 | 
			
		||||
     * @return EntityInterface
 | 
			
		||||
     */
 | 
			
		||||
    public function read(RightInterface $requestedRight): EntityInterface;
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,21 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace App\Domain\SecureCRUDManagement\CRUD\Read;
 | 
			
		||||
 | 
			
		||||
use App\Entity\EntityInterface;
 | 
			
		||||
use App\Entity\Meta\RightInterface;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 */
 | 
			
		||||
final class SecureRightReadService extends AbstractSecureReadService
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     *
 | 
			
		||||
     * @see \App\Domain\SecureCRUDManagement\CRUD\Read\SecureReadServiceInterface::read()
 | 
			
		||||
     */
 | 
			
		||||
    public function read(RightInterface $requestedRight): EntityInterface
 | 
			
		||||
    {
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace App\Domain\SecureLoadManagement;
 | 
			
		||||
namespace App\Domain\SecureCRUDManagement\CRUD\Read;
 | 
			
		||||
 | 
			
		||||
use App\Entity\Source\SourceInterface;
 | 
			
		||||
use App\Entity\Meta\RightInterface;
 | 
			
		||||
@@ -9,11 +9,15 @@ use App\Domain\SecureManagement\SecureSourceChecker;
 | 
			
		||||
use App\Exception\SourceAccessDenied;
 | 
			
		||||
use Doctrine\ORM\EntityManagerInterface;
 | 
			
		||||
use App\Entity\Source\AbstractSource;
 | 
			
		||||
use App\Domain\SecureCRUDManagement\CRUD\AbstractSecureCRUDService;
 | 
			
		||||
use App\Entity\EntityInterface;
 | 
			
		||||
use Symfony\Component\HttpFoundation\RequestStack;
 | 
			
		||||
use Symfony\Component\Security\Core\Security;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 */
 | 
			
		||||
final class SecureSourceLoader implements SecureSourceLoaderInterface
 | 
			
		||||
final class SecureSourceReadService extends AbstractSecureCRUDService //implements SecureSourceReadServiceInterface
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * @todo It would be better to specify the type
 | 
			
		||||
@@ -22,21 +26,14 @@ final class SecureSourceLoader implements SecureSourceLoaderInterface
 | 
			
		||||
     */
 | 
			
		||||
    private $sourceRepository;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * The source attribute of the right needs a slug OR id.
 | 
			
		||||
     *
 | 
			
		||||
     * @var RightInterface the right which is requested
 | 
			
		||||
     */
 | 
			
		||||
    private $requestedRight;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param SourceInterface $source
 | 
			
		||||
     *
 | 
			
		||||
     * @return RightInterface
 | 
			
		||||
     */
 | 
			
		||||
    private function getClonedRightWithModifiedSource(SourceInterface $source): RightInterface
 | 
			
		||||
    private function getClonedRightWithModifiedSource(SourceInterface $source, RightInterface $requestedRight): RightInterface
 | 
			
		||||
    {
 | 
			
		||||
        $requestedRight = clone $this->requestedRight;
 | 
			
		||||
        $requestedRight = clone $requestedRight;
 | 
			
		||||
        $requestedRight->setSource($source);
 | 
			
		||||
 | 
			
		||||
        return $requestedRight;
 | 
			
		||||
@@ -54,21 +51,26 @@ final class SecureSourceLoader implements SecureSourceLoaderInterface
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function __construct(EntityManagerInterface $entityManager, RightInterface $requestedRight)
 | 
			
		||||
    {
 | 
			
		||||
        $this->sourceRepository = $entityManager->getRepository(AbstractSource::class);
 | 
			
		||||
        $this->requestedRight = $requestedRight;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     *
 | 
			
		||||
     * @see \App\Domain\SecureLoadManagement\SecureSourceLoaderInterface::getSource()
 | 
			
		||||
     * @see \App\Domain\SecureCRUDManagement\AbstractSecureCRUDService::__construct()
 | 
			
		||||
     */
 | 
			
		||||
    public function getSource(): SourceInterface
 | 
			
		||||
    public function __construct(RequestStack $requestStack, Security $security, EntityManagerInterface $entityManager)
 | 
			
		||||
    {
 | 
			
		||||
        $this->sourceRepository = $entityManager->getRepository(AbstractSource::class);
 | 
			
		||||
        parent::__construct($requestStack, $security, $entityManager);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param RightInterface $requestedRight
 | 
			
		||||
     *
 | 
			
		||||
     * @return EntityInterface
 | 
			
		||||
     */
 | 
			
		||||
    public function read(RightInterface $requestedRight): EntityInterface
 | 
			
		||||
    {
 | 
			
		||||
        $source = $this->loadSource();
 | 
			
		||||
        $requestedRight = $this->getClonedRightWithModifiedSource($source);
 | 
			
		||||
        $requestedRight = $this->getClonedRightWithModifiedSource($source, $requestedRight);
 | 
			
		||||
        $secureSourceChecker = new SecureSourceChecker($source);
 | 
			
		||||
        if ($secureSourceChecker->hasPermission($requestedRight)) {
 | 
			
		||||
            return $source;
 | 
			
		||||
@@ -0,0 +1,10 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace App\Domain\SecureCRUDManagement\CRUD\Read;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 */
 | 
			
		||||
interface SecureSourceReadServiceInterface extends SecureReadServiceInterface
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
@@ -7,6 +7,6 @@ namespace App\Domain\SecureCRUDManagement\CRUD;
 | 
			
		||||
 *
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 */
 | 
			
		||||
interface SecureCRUDInterface
 | 
			
		||||
interface SecureCRUDServiceInterface
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
@@ -2,35 +2,17 @@
 | 
			
		||||
 | 
			
		||||
namespace App\Domain\SecureCRUDManagement\Factory;
 | 
			
		||||
 | 
			
		||||
use App\Domain\SecureCRUDManagement\CRUD\SecureCRUDInterface;
 | 
			
		||||
use App\Entity\Meta\RightInterface;
 | 
			
		||||
use Symfony\Component\HttpFoundation\Request;
 | 
			
		||||
use Symfony\Component\Security\Core\Security;
 | 
			
		||||
use Symfony\Component\HttpFoundation\RequestStack;
 | 
			
		||||
use Doctrine\ORM\EntityManagerInterface;
 | 
			
		||||
use App\Domain\SecureCRUDManagement\AbstractSecureCRUDService;
 | 
			
		||||
use App\Domain\SecureCRUDManagement\CRUD\SecureCRUDServiceInterface;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 *
 | 
			
		||||
 * @todo Improve code performance
 | 
			
		||||
 */
 | 
			
		||||
final class SecureCRUDFactoryService implements SecureCRUDFactoryServiceInterface
 | 
			
		||||
final class SecureCRUDFactoryService extends AbstractSecureCRUDService implements SecureCRUDFactoryServiceInterface
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * @var Request
 | 
			
		||||
     */
 | 
			
		||||
    private $request;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @var Security
 | 
			
		||||
     */
 | 
			
		||||
    private $security;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @var EntityManagerInterface
 | 
			
		||||
     */
 | 
			
		||||
    private $entityManager;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param string $crud
 | 
			
		||||
     *
 | 
			
		||||
@@ -59,14 +41,7 @@ final class SecureCRUDFactoryService implements SecureCRUDFactoryServiceInterfac
 | 
			
		||||
     */
 | 
			
		||||
    private function getCRUDNamespace(string $layer, string $crud): string
 | 
			
		||||
    {
 | 
			
		||||
        return 'App\\Domain\\SecureCRUDManagement\\CRUD\\'.$this->getCrud($crud).'\\'.$this->getClassName($layer, $crud);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function __construct(RequestStack $requestStack, Security $security, EntityManagerInterface $entityManager)
 | 
			
		||||
    {
 | 
			
		||||
        $this->request = $requestStack->getCurrentRequest();
 | 
			
		||||
        $this->security = $security;
 | 
			
		||||
        $this->entityManager = $entityManager;
 | 
			
		||||
        return 'App\\Domain\\SecureCRUDManagement\\CRUD\\'.$this->getCrud($crud).'\\'.$this->getClassName($layer, $crud).'Service';
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -74,10 +49,10 @@ final class SecureCRUDFactoryService implements SecureCRUDFactoryServiceInterfac
 | 
			
		||||
     *
 | 
			
		||||
     * @see \App\Domain\SecureCRUDManagement\Factory\SecureCRUDFactoryServiceInterface::create()
 | 
			
		||||
     */
 | 
			
		||||
    public function create(RightInterface $requestedRight): SecureCRUDInterface
 | 
			
		||||
    public function create(RightInterface $requestedRight): SecureCRUDServiceInterface
 | 
			
		||||
    {
 | 
			
		||||
        $namespace = $this->getCRUDNamespace($requestedRight->getLayer(), $requestedRight->getType());
 | 
			
		||||
 | 
			
		||||
        return new $namespace($this->request, $this->security, $this->entityManager);
 | 
			
		||||
        return new $namespace($this->requestStack, $this->security, $this->entityManager);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -3,7 +3,7 @@
 | 
			
		||||
namespace App\Domain\SecureCRUDManagement\Factory;
 | 
			
		||||
 | 
			
		||||
use App\Entity\Meta\RightInterface;
 | 
			
		||||
use App\Domain\SecureCRUDManagement\CRUD\SecureCRUDInterface;
 | 
			
		||||
use App\Domain\SecureCRUDManagement\CRUD\SecureCRUDServiceInterface;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
@@ -11,7 +11,7 @@ use App\Domain\SecureCRUDManagement\CRUD\SecureCRUDInterface;
 | 
			
		||||
interface SecureCRUDFactoryServiceInterface
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * @return SecureCRUDInterface
 | 
			
		||||
     * @return SecureCRUDServiceInterface
 | 
			
		||||
     */
 | 
			
		||||
    public function create(RightInterface $requestedRight): SecureCRUDInterface;
 | 
			
		||||
    public function create(RightInterface $requestedRight): SecureCRUDServiceInterface;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,19 +0,0 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace App\Domain\SecureLoadManagement;
 | 
			
		||||
 | 
			
		||||
use App\Entity\Source\SourceInterface;
 | 
			
		||||
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 */
 | 
			
		||||
interface SecureSourceLoaderInterface
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * @throws AccessDeniedHttpException
 | 
			
		||||
     *
 | 
			
		||||
     * @return SourceInterface
 | 
			
		||||
     */
 | 
			
		||||
    public function getSource(): SourceInterface;
 | 
			
		||||
}
 | 
			
		||||
@@ -1,12 +1,10 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace Tests\Unit\Domain\SecureLoadManagement;
 | 
			
		||||
namespace tests\Unit\Domain\SecureCRUDManagement\CRUD\Read;
 | 
			
		||||
 | 
			
		||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
 | 
			
		||||
use Doctrine\Common\Persistence\ObjectRepository;
 | 
			
		||||
use App\Entity\Source\AbstractSource;
 | 
			
		||||
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
 | 
			
		||||
use App\Domain\SecureLoadManagement\SecureSourceLoader;
 | 
			
		||||
use App\Entity\Source\Primitive\Text\TextSource;
 | 
			
		||||
use App\DBAL\Types\SystemSlugType;
 | 
			
		||||
use App\Entity\Meta\Right;
 | 
			
		||||
@@ -15,13 +13,15 @@ use App\DBAL\Types\Meta\Right\CRUDType;
 | 
			
		||||
use App\Entity\Source\Complex\UserSource;
 | 
			
		||||
use App\Entity\Source\Primitive\Text\TextSourceInterface;
 | 
			
		||||
use Doctrine\ORM\EntityManagerInterface;
 | 
			
		||||
use App\Domain\SecureCRUDManagement\CRUD\Read\SecureSourceReadService;
 | 
			
		||||
use Symfony\Component\Security\Core\Security;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 *
 | 
			
		||||
 * @todo Implement more tests
 | 
			
		||||
 */
 | 
			
		||||
class SecureSourceLoaderTest extends KernelTestCase
 | 
			
		||||
class SecureSourceReadServiceTest extends KernelTestCase
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * @var ObjectRepository
 | 
			
		||||
@@ -33,16 +33,18 @@ class SecureSourceLoaderTest extends KernelTestCase
 | 
			
		||||
     */
 | 
			
		||||
    private $entityManager;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @var SecureSourceReadService
 | 
			
		||||
     */
 | 
			
		||||
    private $secureSourceReadService;
 | 
			
		||||
 | 
			
		||||
    public function setUp(): void
 | 
			
		||||
    {
 | 
			
		||||
        self::bootKernel();
 | 
			
		||||
        $this->entityManager = self::$container->get('doctrine.orm.default_entity_manager');
 | 
			
		||||
        $this->setSourceRepository();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private function setSourceRepository(): void
 | 
			
		||||
    {
 | 
			
		||||
        $this->sourceRepository = $this->entityManager->getRepository(AbstractSource::class);
 | 
			
		||||
        $requestStack = self::$container->get('request_stack');
 | 
			
		||||
        $security = new Security(self::$kernel->getContainer());
 | 
			
		||||
        $entityManager = self::$container->get('doctrine.orm.default_entity_manager');
 | 
			
		||||
        $this->secureSourceReadService = new SecureSourceReadService($requestStack, $security, $entityManager);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testAccessDeniedException(): void
 | 
			
		||||
@@ -54,9 +56,8 @@ class SecureSourceLoaderTest extends KernelTestCase
 | 
			
		||||
        $requestedRight->setLayer(LayerType::SOURCE);
 | 
			
		||||
        $requestedRight->setType(CRUDType::READ);
 | 
			
		||||
        $requestedRight->setReciever(new UserSource());
 | 
			
		||||
        $secureSourceLoader = new SecureSourceLoader($this->entityManager, $requestedRight);
 | 
			
		||||
        $this->expectException(AccessDeniedHttpException::class);
 | 
			
		||||
        $secureSourceLoader->getSource();
 | 
			
		||||
        $this->secureSourceReadService->read($requestedRight);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGranted(): void
 | 
			
		||||
@@ -68,7 +69,7 @@ class SecureSourceLoaderTest extends KernelTestCase
 | 
			
		||||
        $requestedRight->setLayer(LayerType::SOURCE);
 | 
			
		||||
        $requestedRight->setType(CRUDType::READ);
 | 
			
		||||
        $requestedRight->setReciever($this->sourceRepository->findOneBySlug(SystemSlugType::GUEST_USER));
 | 
			
		||||
        $secureSourceLoader = new SecureSourceLoader($this->entityManager, $requestedRight);
 | 
			
		||||
        $this->assertInstanceOf(TextSourceInterface::class, $secureSourceLoader->getSource());
 | 
			
		||||
        $textSourceResponse = $this->secureSourceReadService->read($requestedRight);
 | 
			
		||||
        $this->assertInstanceOf(TextSourceInterface::class, $textSourceResponse);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -8,7 +8,7 @@ use Symfony\Component\Security\Core\Security;
 | 
			
		||||
use App\Domain\SecureCRUDManagement\Factory\SecureCRUDFactoryService;
 | 
			
		||||
use App\DBAL\Types\Meta\Right\LayerType;
 | 
			
		||||
use App\Entity\Meta\Right;
 | 
			
		||||
use App\Domain\SecureCRUDManagement\CRUD\SecureCRUDInterface;
 | 
			
		||||
use App\Domain\SecureCRUDManagement\CRUD\SecureCRUDServiceInterface;
 | 
			
		||||
use App\DBAL\Types\Meta\Right\CRUDType;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
@@ -50,7 +50,7 @@ class SecureCRUDFactoryServiceTest extends KernelTestCase
 | 
			
		||||
                    $requestedRight->setLayer($layer);
 | 
			
		||||
                    $requestedRight->setType($crud);
 | 
			
		||||
                    $secureCreator = $this->secureCRUDFactoryService->create($requestedRight);
 | 
			
		||||
                    $this->assertInstanceOf(SecureCRUDInterface::class, $secureCreator);
 | 
			
		||||
                    $this->assertInstanceOf(SecureCRUDServiceInterface::class, $secureCreator);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user