mirror of
				https://github.com/kevinveenbirkenbach/infinito.git
				synced 2025-11-04 03:07:58 +00:00 
			
		
		
		
	Implemented UserIdentityService
This commit is contained in:
		@@ -20,6 +20,7 @@ use App\Domain\ResponseManagement\SourceRESTResponseManager;
 | 
			
		||||
final class DefaultController extends AbstractController
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * @deprecated Use load via source instead of fixed route
 | 
			
		||||
     * @todo Optimize function!
 | 
			
		||||
     * @Route("/imprint.{_format}", defaults={"_format"="json"}, name="imprint")
 | 
			
		||||
     */
 | 
			
		||||
 
 | 
			
		||||
@@ -1,13 +0,0 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace App\Domain\ResponseManagement;
 | 
			
		||||
 | 
			
		||||
use Symfony\Component\HttpFoundation\Response;
 | 
			
		||||
 | 
			
		||||
interface SourceRESTResponseManagerInterface
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * @return Response
 | 
			
		||||
     */
 | 
			
		||||
    public function getResponse(): Response;
 | 
			
		||||
}
 | 
			
		||||
@@ -7,6 +7,7 @@ use App\Entity\UserInterface;
 | 
			
		||||
use Doctrine\ORM\EntityManagerInterface;
 | 
			
		||||
use App\Entity\Meta\RightInterface;
 | 
			
		||||
use App\Domain\UserManagement\UserIdentityManager;
 | 
			
		||||
use Symfony\Component\Security\Core\User\UserInterface as CoreUserInterface;
 | 
			
		||||
use FOS\RestBundle\View\ViewHandlerInterface;
 | 
			
		||||
use App\Entity\Source\SourceInterface;
 | 
			
		||||
use FOS\RestBundle\View\View;
 | 
			
		||||
@@ -18,13 +19,8 @@ use App\Domain\SecureCRUDManagement\CRUD\Read\SecureSourceReadService;
 | 
			
		||||
 *
 | 
			
		||||
 * @todo Implement as a service!
 | 
			
		||||
 */
 | 
			
		||||
final class SourceRESTResponseManager implements SourceRESTResponseManagerInterface
 | 
			
		||||
final class SourceRESTResponseManagerService implements SourceRESTResponseManagerServiceInterface
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * @var UserInterface
 | 
			
		||||
     */
 | 
			
		||||
    private $user;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @var EntityManagerInterface
 | 
			
		||||
     */
 | 
			
		||||
@@ -35,32 +31,20 @@ final class SourceRESTResponseManager implements SourceRESTResponseManagerInterf
 | 
			
		||||
     */
 | 
			
		||||
    private $requestedRight;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @var ViewHandlerInterface
 | 
			
		||||
     */
 | 
			
		||||
    private $viewHandler;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @var SourceInterface
 | 
			
		||||
     */
 | 
			
		||||
    private $loadedSource;
 | 
			
		||||
 | 
			
		||||
    
 | 
			
		||||
    /**
 | 
			
		||||
     * @var View
 | 
			
		||||
     * @var UserInterface
 | 
			
		||||
     */
 | 
			
		||||
    private $view;
 | 
			
		||||
    private $user;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param UserInterface          $user
 | 
			
		||||
     * @param EntityManagerInterface $entityManager
 | 
			
		||||
     * @param RightInterface         $requestedRight
 | 
			
		||||
     * @param ViewHandlerInterface   $viewHandler
 | 
			
		||||
     */
 | 
			
		||||
    public function __construct(?UserInterface $user, EntityManagerInterface $entityManager, RightInterface $requestedRight, ViewHandlerInterface $viewHandler)
 | 
			
		||||
    public function __construct(CoreUserInterface $user,SecureSourceReadService $secureSourceRead, EntityManagerInterface $entityManager, RightInterface $requestedRight)
 | 
			
		||||
    {
 | 
			
		||||
        $this->entityManager = $entityManager;
 | 
			
		||||
        $this->viewHandler = $viewHandler;
 | 
			
		||||
        $this->setUser($user);
 | 
			
		||||
        $this->user = $user;
 | 
			
		||||
        $this->setRequestedRight($requestedRight);
 | 
			
		||||
        $this->setLoadedSource();
 | 
			
		||||
        $this->setView();
 | 
			
		||||
@@ -71,21 +55,6 @@ final class SourceRESTResponseManager implements SourceRESTResponseManagerInterf
 | 
			
		||||
        $this->view = new View($this->loadedSource, 200);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private function setLoadedSource(): void
 | 
			
		||||
    {
 | 
			
		||||
        $secureSourceLoader = new SecureSourceReadService($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
 | 
			
		||||
     *
 | 
			
		||||
@@ -103,12 +72,11 @@ final class SourceRESTResponseManager implements SourceRESTResponseManagerInterf
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     *
 | 
			
		||||
     * @see \App\Domain\ResponseManagement\SourceRESTResponseManagerInterface::getResponse()
 | 
			
		||||
     * {@inheritDoc}
 | 
			
		||||
     * @see \App\Domain\ResponseManagement\SourceRESTResponseManagerServiceInterface::getResponse()
 | 
			
		||||
     */
 | 
			
		||||
    public function getResponse(): Response
 | 
			
		||||
    public function getResponse(ViewHandlerInterface $viewHandler): Response
 | 
			
		||||
    {
 | 
			
		||||
        return $this->viewHandler->handle($this->view);
 | 
			
		||||
        return $viewHandler->handle($this->view);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,14 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace App\Domain\ResponseManagement;
 | 
			
		||||
 | 
			
		||||
use Symfony\Component\HttpFoundation\Response;
 | 
			
		||||
use FOS\RestBundle\View\ViewHandlerInterface;
 | 
			
		||||
 | 
			
		||||
interface SourceRESTResponseManagerServiceInterface
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * @return Response
 | 
			
		||||
     */
 | 
			
		||||
    public function getResponse(ViewHandlerInterface $viewHandler): Response;
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,41 @@
 | 
			
		||||
<?php
 | 
			
		||||
namespace App\Domain\RightManagement;
 | 
			
		||||
 | 
			
		||||
use App\Entity\Meta\Right;
 | 
			
		||||
use App\Entity\UserInterface as InfinitoUserInterface;
 | 
			
		||||
use App\Entity\Source\SourceInterface;
 | 
			
		||||
use App\Entity\UserInterface;
 | 
			
		||||
use Symfony\Component\Security\Core\Security;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 *
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 *        
 | 
			
		||||
 */
 | 
			
		||||
final class UserRightService extends Right implements UserRightServiceInterface
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * 
 | 
			
		||||
     * @var Security
 | 
			
		||||
     */
 | 
			
		||||
   private $security;
 | 
			
		||||
 | 
			
		||||
   
 | 
			
		||||
    public function __construct(Security $security)
 | 
			
		||||
    {
 | 
			
		||||
        $this->security = $security;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritDoc}
 | 
			
		||||
     * @see \App\Entity\Attribut\RecieverAttributInterface::setReciever()
 | 
			
		||||
     */
 | 
			
		||||
    public function setReciever(SourceInterface $reciever):void{
 | 
			
		||||
        
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    public function getReciever():SourceInterface{
 | 
			
		||||
        return $this->user->getSource();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -0,0 +1,14 @@
 | 
			
		||||
<?php
 | 
			
		||||
namespace App\Domain\RightManagement;
 | 
			
		||||
 | 
			
		||||
use App\Entity\Meta\RightInterface;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Offers a Service for managing the rights
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
interface UserRightServiceInterface extends RightInterface
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -0,0 +1,53 @@
 | 
			
		||||
<?php
 | 
			
		||||
namespace App\Domain\UserManagement;
 | 
			
		||||
 | 
			
		||||
use App\Entity\UserInterface;
 | 
			
		||||
use Doctrine\ORM\EntityManager;
 | 
			
		||||
use Symfony\Component\Security\Core\Security;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * 
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 * @todo Test!
 | 
			
		||||
 */
 | 
			
		||||
final class UserIdentityService implements UserIdentityServiceInterface
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * @var EntityManager
 | 
			
		||||
     */
 | 
			
		||||
    private $entityManager;
 | 
			
		||||
    
 | 
			
		||||
    /**
 | 
			
		||||
     * @var Security
 | 
			
		||||
     */
 | 
			
		||||
    private $security;
 | 
			
		||||
    
 | 
			
		||||
    /**
 | 
			
		||||
     * @var UserIdentityManagerInterface
 | 
			
		||||
     */
 | 
			
		||||
    private $userIdentityManager;
 | 
			
		||||
    
 | 
			
		||||
    /**
 | 
			
		||||
     * @param EntityManager $entityManager
 | 
			
		||||
     * @param Security $security
 | 
			
		||||
     */
 | 
			
		||||
    public function __construct(EntityManager $entityManager, Security $security){
 | 
			
		||||
        $this->entityManager = $entityManager;
 | 
			
		||||
        $this->security = $security;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    private function setUserIdentityManager():void{
 | 
			
		||||
        $this->userIdentityManager = new UserIdentityManager($this->entityManager, $this->security->getUser());
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
    /**
 | 
			
		||||
     * @todo Optimzed performance!
 | 
			
		||||
     * {@inheritDoc}
 | 
			
		||||
     * @see \App\Domain\UserManagement\UserIdentityManagerInterface::getUser()
 | 
			
		||||
     */
 | 
			
		||||
    public function getUser(): UserInterface
 | 
			
		||||
    {
 | 
			
		||||
        $this->setUserIdentityManager();
 | 
			
		||||
        return $this->userIdentityManager->getUser();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,12 @@
 | 
			
		||||
<?php
 | 
			
		||||
namespace App\Domain\UserManagement;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * 
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
interface UserIdentityServiceInterface extends UserIdentityManagerInterface
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user