Optimized for SPA

This commit is contained in:
Kevin Frantz
2019-01-05 23:52:37 +01:00
parent 9e685260e9
commit bccd6efaff
393 changed files with 253 additions and 37 deletions

View File

@@ -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);
}
}

View File

@@ -0,0 +1,13 @@
<?php
namespace App\Domain\ResponseManagement;
use Symfony\Component\HttpFoundation\Response;
interface SourceRESTResponseManagerInterface
{
/**
* @return Response
*/
public function getResponse(): Response;
}