mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-01-09 06:01:35 +01:00
Implemented SourceRESTResponseManager and cleaned up code
This commit is contained in:
parent
e9f4931a5e
commit
843733ad79
@ -6,13 +6,12 @@ use Symfony\Component\Routing\Annotation\Route;
|
|||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use App\DBAL\Types\SystemSlugType;
|
use App\DBAL\Types\SystemSlugType;
|
||||||
use App\Entity\Source\AbstractSource;
|
use App\Entity\Source\AbstractSource;
|
||||||
use App\Domain\SecureLoadManagement\SecureSourceLoader;
|
|
||||||
use App\Entity\Meta\Right;
|
use App\Entity\Meta\Right;
|
||||||
use App\DBAL\Types\LayerType;
|
use App\DBAL\Types\LayerType;
|
||||||
use App\DBAL\Types\RightType;
|
use App\DBAL\Types\RightType;
|
||||||
use App\Domain\UserManagement\UserIdentityManager;
|
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use App\Entity\Source\PureSource;
|
use App\Entity\Source\PureSource;
|
||||||
|
use App\Domain\ResponseManagement\SourceRESTResponseManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This controller offers the standart routes for the template.
|
* This controller offers the standart routes for the template.
|
||||||
@ -23,25 +22,19 @@ final class DefaultController extends AbstractEntityController
|
|||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @todo Optimize function!
|
* @todo Optimize function!
|
||||||
* @Route("/imprint", name="imprint")
|
* @Route("/imprint.{_format}", defaults={"_format"="json"}, name="imprint")
|
||||||
*/
|
*/
|
||||||
public function imprint(EntityManagerInterface $entityManager): Response
|
public function imprint(EntityManagerInterface $entityManager): Response
|
||||||
{
|
{
|
||||||
$userIdentityManager = new UserIdentityManager($entityManager, $this->getUser());
|
|
||||||
$user = $userIdentityManager->getUser();
|
|
||||||
$requestedSource = new PureSource();
|
$requestedSource = new PureSource();
|
||||||
$requestedSource->setSlug(SystemSlugType::IMPRINT);
|
$requestedSource->setSlug(SystemSlugType::IMPRINT);
|
||||||
$requestedRight = new Right();
|
$requestedRight = new Right();
|
||||||
$requestedRight->setSource($requestedSource);
|
$requestedRight->setSource($requestedSource);
|
||||||
$requestedRight->setReciever($user->getSource());
|
|
||||||
$requestedRight->setLayer(LayerType::SOURCE);
|
$requestedRight->setLayer(LayerType::SOURCE);
|
||||||
$requestedRight->setType(RightType::READ);
|
$requestedRight->setType(RightType::READ);
|
||||||
$secureSourceLoader = new SecureSourceLoader($this->getDoctrine()->getManager(), $requestedRight);
|
$sourceResponseManager = new SourceRESTResponseManager($this->getUser(), $entityManager, $requestedRight, $this->getViewHandler());
|
||||||
$view = $this->view($secureSourceLoader->getSource(), 200)
|
|
||||||
->setTemplate('standard/imprint.html.twig')
|
|
||||||
->setTemplateVar('source');
|
|
||||||
|
|
||||||
return $this->handleView($view);
|
return $sourceResponseManager->getResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2,6 +2,11 @@
|
|||||||
|
|
||||||
namespace App\Domain;
|
namespace App\Domain;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated Doesn't make sense!
|
||||||
|
*
|
||||||
|
* @author kevinfrantz
|
||||||
|
*/
|
||||||
abstract class AbstractDomainService
|
abstract class AbstractDomainService
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,107 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\ResponseManagement;
|
||||||
|
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use App\Entity\UserInterface;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author kevinfrantz
|
||||||
|
*/
|
||||||
|
class SourceRESTResponseManager implements SourceRESTResponseManagerInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var UserInterface
|
||||||
|
*/
|
||||||
|
private $user;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var EntityManagerInterface
|
||||||
|
*/
|
||||||
|
private $entityManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var RightInterface
|
||||||
|
*/
|
||||||
|
private $requestedRight;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var ViewHandlerInterface
|
||||||
|
*/
|
||||||
|
private $viewHandler;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var SourceInterface
|
||||||
|
*/
|
||||||
|
private $loadedSource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var View
|
||||||
|
*/
|
||||||
|
private $view;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param UserInterface $user
|
||||||
|
* @param EntityManagerInterface $entityManager
|
||||||
|
* @param RightInterface $requestedRight
|
||||||
|
* @param ViewHandlerInterface $viewHandler
|
||||||
|
*/
|
||||||
|
public function __construct(?UserInterface $user, EntityManagerInterface $entityManager, RightInterface $requestedRight, ViewHandlerInterface $viewHandler)
|
||||||
|
{
|
||||||
|
$this->entityManager = $entityManager;
|
||||||
|
$this->viewHandler = $viewHandler;
|
||||||
|
$this->setUser($user);
|
||||||
|
$this->setRequestedRight($requestedRight);
|
||||||
|
$this->setLoadedSource();
|
||||||
|
$this->setView();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function setView(): void
|
||||||
|
{
|
||||||
|
$this->view = new View($this->loadedSource, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function setLoadedSource(): void
|
||||||
|
{
|
||||||
|
$secureSourceLoader = new SecureSourceLoader($this->entityManager, $this->requestedRight);
|
||||||
|
$this->loadedSource = $secureSourceLoader->getSource();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param UserInterface $user
|
||||||
|
*/
|
||||||
|
private function setUser(?UserInterface $user): void
|
||||||
|
{
|
||||||
|
$userIdentityManager = new UserIdentityManager($this->entityManager, $user);
|
||||||
|
$this->user = $userIdentityManager->getUser();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param RightInterface $requestedRight
|
||||||
|
*
|
||||||
|
* @throws AllreadyDefinedException
|
||||||
|
*/
|
||||||
|
private function setRequestedRight(RightInterface $requestedRight): void
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$requestedRight->getReciever();
|
||||||
|
throw new AllreadyDefinedException('The reciever is allready defined.');
|
||||||
|
} catch (\TypeError $error) {
|
||||||
|
$requestedRight->setReciever($this->user->getSource());
|
||||||
|
$this->requestedRight = $requestedRight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getResponse(): Response
|
||||||
|
{
|
||||||
|
return $this->viewHandler->handle($this->view);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\ResponseManagement;
|
||||||
|
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
|
||||||
|
interface SourceRESTResponseManagerInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @return Response
|
||||||
|
*/
|
||||||
|
public function getResponse(): Response;
|
||||||
|
}
|
@ -11,7 +11,7 @@ use App\Domain\FormManagement\FormMeta;
|
|||||||
/**
|
/**
|
||||||
* @author kevinfrantz
|
* @author kevinfrantz
|
||||||
*/
|
*/
|
||||||
class SourceMeta implements SourceMetaInterface
|
final class SourceMeta implements SourceMetaInterface
|
||||||
{
|
{
|
||||||
const FOLDER = 'entity';
|
const FOLDER = 'entity';
|
||||||
|
|
||||||
|
@ -9,6 +9,8 @@ use App\Domain\FormManagement\FormMetaInterface;
|
|||||||
/**
|
/**
|
||||||
* A meta source offers informations, which the system needs to handle the source.
|
* A meta source offers informations, which the system needs to handle the source.
|
||||||
*
|
*
|
||||||
|
* @deprecated
|
||||||
|
*
|
||||||
* @author kevinfrantz
|
* @author kevinfrantz
|
||||||
*/
|
*/
|
||||||
interface SourceMetaInterface
|
interface SourceMetaInterface
|
||||||
|
@ -7,7 +7,7 @@ use App\DBAL\Types\TemplateType;
|
|||||||
/**
|
/**
|
||||||
* @author kevinfrantz
|
* @author kevinfrantz
|
||||||
*/
|
*/
|
||||||
class TemplateMeta implements TemplateMetaInterface
|
final class TemplateMeta implements TemplateMetaInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
||||||
|
@ -5,6 +5,8 @@ namespace App\Domain\TemplateManagement;
|
|||||||
/**
|
/**
|
||||||
* Manages all informations which are needed to process templates.
|
* Manages all informations which are needed to process templates.
|
||||||
*
|
*
|
||||||
|
* @deprecated
|
||||||
|
*
|
||||||
* @author kevinfrantz
|
* @author kevinfrantz
|
||||||
*/
|
*/
|
||||||
interface TemplateMetaInterface
|
interface TemplateMetaInterface
|
||||||
|
@ -1,12 +0,0 @@
|
|||||||
{% extends "frames/default.html.twig" %}
|
|
||||||
{% block title %}
|
|
||||||
Homepage
|
|
||||||
{% endblock %}
|
|
||||||
{% block content %}
|
|
||||||
<h2>
|
|
||||||
{% trans %}
|
|
||||||
Imprint
|
|
||||||
{% endtrans %}
|
|
||||||
</h2>
|
|
||||||
{{ source.text }}
|
|
||||||
{% endblock %}
|
|
@ -0,0 +1,75 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Unit\Domain\ResponseManagement;
|
||||||
|
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
use App\Entity\Meta\RightInterface;
|
||||||
|
use App\Entity\Meta\Right;
|
||||||
|
use FOS\RestBundle\View\ViewHandlerInterface;
|
||||||
|
use App\Entity\Source\PureSource;
|
||||||
|
use App\DBAL\Types\SystemSlugType;
|
||||||
|
use App\DBAL\Types\LayerType;
|
||||||
|
use App\DBAL\Types\RightType;
|
||||||
|
use App\Domain\ResponseManagement\SourceRESTResponseManager;
|
||||||
|
use App\Exception\AllreadyDefinedException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author kevinfrantz
|
||||||
|
*
|
||||||
|
* @todo Implement more tests!
|
||||||
|
*/
|
||||||
|
class SourceRESTReponseManagerTest extends KernelTestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var EntityManagerInterface
|
||||||
|
*/
|
||||||
|
private $entityManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var RightInterface
|
||||||
|
*/
|
||||||
|
private $requestedRight;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var ViewHandlerInterface
|
||||||
|
*/
|
||||||
|
private $viewHandler;
|
||||||
|
|
||||||
|
private function setRequestedRight(): void
|
||||||
|
{
|
||||||
|
$this->requestedRight = new Right();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function setEntityManager(): void
|
||||||
|
{
|
||||||
|
$this->entityManager = self::$container->get('doctrine.orm.default_entity_manager');
|
||||||
|
}
|
||||||
|
|
||||||
|
private function setViewHandler(): void
|
||||||
|
{
|
||||||
|
$this->viewHandler = $this->createMock(ViewHandlerInterface::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setUp(): void
|
||||||
|
{
|
||||||
|
self::bootKernel();
|
||||||
|
$this->setEntityManager();
|
||||||
|
$this->setRequestedRight();
|
||||||
|
$this->setViewHandler();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testAllreadyDefinedException(): void
|
||||||
|
{
|
||||||
|
$requestedSource = new PureSource();
|
||||||
|
$requestedSource->setSlug(SystemSlugType::IMPRINT);
|
||||||
|
$requestedRight = new Right();
|
||||||
|
$requestedRight->setSource($requestedSource);
|
||||||
|
$requestedRight->setReciever(new PureSource());
|
||||||
|
$requestedRight->setLayer(LayerType::SOURCE);
|
||||||
|
$requestedRight->setType(RightType::READ);
|
||||||
|
$this->expectException(AllreadyDefinedException::class);
|
||||||
|
$sourceResponseManager = new SourceRESTResponseManager(null, $this->entityManager, $requestedRight, $this->viewHandler);
|
||||||
|
$sourceResponseManager->getResponse();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user