mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-01-09 22:17:26 +01:00
Optimized draft for UserSourceDirector and UserRight
This commit is contained in:
parent
1dc428bcfd
commit
2837df25f8
@ -21,6 +21,7 @@ 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")
|
||||
*/
|
||||
|
@ -6,7 +6,6 @@ use Symfony\Component\HttpFoundation\Response;
|
||||
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;
|
||||
@ -35,13 +34,13 @@ final class SourceRESTResponseManagerService implements SourceRESTResponseManage
|
||||
* @var SourceInterface
|
||||
*/
|
||||
private $loadedSource;
|
||||
|
||||
|
||||
/**
|
||||
* @var UserInterface
|
||||
*/
|
||||
private $user;
|
||||
|
||||
public function __construct(CoreUserInterface $user,SecureSourceReadService $secureSourceRead, EntityManagerInterface $entityManager, RightInterface $requestedRight)
|
||||
public function __construct(CoreUserInterface $user, SecureSourceReadService $secureSourceRead, EntityManagerInterface $entityManager, RightInterface $requestedRight)
|
||||
{
|
||||
$this->entityManager = $entityManager;
|
||||
$this->user = $user;
|
||||
@ -72,7 +71,8 @@ final class SourceRESTResponseManagerService implements SourceRESTResponseManage
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \App\Domain\ResponseManagement\SourceRESTResponseManagerServiceInterface::getResponse()
|
||||
*/
|
||||
public function getResponse(ViewHandlerInterface $viewHandler): Response
|
||||
|
47
application/symfony/src/Domain/RightManagement/UserRight.php
Normal file
47
application/symfony/src/Domain/RightManagement/UserRight.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\RightManagement;
|
||||
|
||||
use App\Entity\Meta\Right;
|
||||
use App\Entity\Source\SourceInterface;
|
||||
use App\Exception\SetNotPossibleException;
|
||||
use App\Domain\UserManagement\UserSourceDirectorInterface;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
final class UserRight extends Right implements UserRightInterface
|
||||
{
|
||||
/**
|
||||
* @var UserSourceDirectorInterface
|
||||
*/
|
||||
private $userSourceDirector;
|
||||
|
||||
/**
|
||||
* @param UserSourceDirectorInterface $userSourceDirector
|
||||
*/
|
||||
public function __construct(UserSourceDirectorInterface $userSourceDirector)
|
||||
{
|
||||
$this->userSourceDirector = $userSourceDirector;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \App\Entity\Attribut\RecieverAttributInterface::setReciever()
|
||||
*/
|
||||
public function setReciever(SourceInterface $reciever): void
|
||||
{
|
||||
throw new SetNotPossibleException('This class doesn\'t allow to set a reciever!');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \App\Entity\Attribut\RecieverAttributInterface::getReciever()
|
||||
*/
|
||||
public function getReciever(): SourceInterface
|
||||
{
|
||||
return $this->userSourceDirector->getUser()->getSource();
|
||||
}
|
||||
}
|
@ -1,14 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\RightManagement;
|
||||
|
||||
use App\Entity\Meta\RightInterface;
|
||||
|
||||
/**
|
||||
* Offers a Service for managing the rights
|
||||
* @author kevinfrantz
|
||||
* Offers a Service for managing the rights.
|
||||
*
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
interface UserRightServiceInterface extends RightInterface
|
||||
interface UserRightInterface extends RightInterface
|
||||
{
|
||||
}
|
||||
|
@ -1,41 +0,0 @@
|
||||
<?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();
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +0,0 @@
|
||||
<?php
|
||||
namespace App\Domain\UserManagement;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author kevinfrantz
|
||||
*
|
||||
*/
|
||||
interface UserIdentityServiceInterface extends UserIdentityManagerInterface
|
||||
{
|
||||
}
|
||||
|
@ -6,13 +6,12 @@ use App\Entity\UserInterface;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use App\DBAL\Types\SystemSlugType;
|
||||
use App\Entity\User;
|
||||
use App\Entity\Source\AbstractSource;
|
||||
use App\Repository\Source\SourceRepository;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
final class UserIdentityManager implements UserIdentityManagerInterface
|
||||
final class UserSourceDirector implements UserSourceDirectorInterface
|
||||
{
|
||||
/**
|
||||
* @var UserInterface
|
||||
@ -24,14 +23,6 @@ final class UserIdentityManager implements UserIdentityManagerInterface
|
||||
*/
|
||||
private $sourceRepository;
|
||||
|
||||
/**
|
||||
* @param EntityManagerInterface $entityManager
|
||||
*/
|
||||
private function setSourceRepository(EntityManagerInterface $entityManager): void
|
||||
{
|
||||
$this->sourceRepository = $entityManager->getRepository(AbstractSource::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param UserInterface $user
|
||||
*/
|
||||
@ -50,16 +41,16 @@ final class UserIdentityManager implements UserIdentityManagerInterface
|
||||
* @param EntityManagerInterface $entityManager
|
||||
* @param UserInterface $user
|
||||
*/
|
||||
public function __construct(EntityManagerInterface $entityManager, ?UserInterface $user)
|
||||
public function __construct(SourceRepository $sourceRepository, ?UserInterface $user)
|
||||
{
|
||||
$this->setSourceRepository($entityManager);
|
||||
$this->sourceRepository = $sourceRepository;
|
||||
$this->setUser($user);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \App\Domain\UserManagement\UserIdentityManagerInterface::getUser()
|
||||
* @see \App\Domain\UserManagement\UserSourceDirectorInterface::getUser()
|
||||
*/
|
||||
public function getUser(): UserInterface
|
||||
{
|
@ -4,7 +4,7 @@ namespace App\Domain\UserManagement;
|
||||
|
||||
use App\Entity\UserInterface;
|
||||
|
||||
interface UserIdentityManagerInterface
|
||||
interface UserSourceDirectorInterface
|
||||
{
|
||||
/**
|
||||
* @return UserInterface
|
@ -1,53 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\UserManagement;
|
||||
|
||||
use App\Entity\UserInterface;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
use App\Entity\Source\AbstractSource;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author kevinfrantz
|
||||
*
|
||||
* @todo Test!
|
||||
*/
|
||||
final class UserIdentityService implements UserIdentityServiceInterface
|
||||
final class UserSourceDirectorService implements UserSourceDirectorServiceInterface
|
||||
{
|
||||
/**
|
||||
* @var EntityManager
|
||||
*/
|
||||
private $entityManager;
|
||||
|
||||
|
||||
/**
|
||||
* @var Security
|
||||
*/
|
||||
private $security;
|
||||
|
||||
/**
|
||||
* @var UserIdentityManagerInterface
|
||||
*/
|
||||
private $userIdentityManager;
|
||||
|
||||
|
||||
/**
|
||||
* @param EntityManager $entityManager
|
||||
* @param Security $security
|
||||
* @param Security $security
|
||||
*/
|
||||
public function __construct(EntityManager $entityManager, 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());
|
||||
|
||||
/**
|
||||
* @return UserSourceDirectorInterface
|
||||
*/
|
||||
private function getUserSourceDirector(): UserSourceDirectorInterface
|
||||
{
|
||||
$sourceRepository = $this->entityManager->getRepository(AbstractSource::class);
|
||||
$user = $this->security->getUser();
|
||||
|
||||
return new UserSourceDirector($sourceRepository, $user);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @todo Optimzed performance!
|
||||
* {@inheritDoc}
|
||||
* @see \App\Domain\UserManagement\UserIdentityManagerInterface::getUser()
|
||||
*
|
||||
* @return UserInterface
|
||||
*/
|
||||
public function getUser(): UserInterface
|
||||
{
|
||||
$this->setUserIdentityManager();
|
||||
return $this->userIdentityManager->getUser();
|
||||
return $this->getUserSourceDirector()->getUser();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\UserManagement;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
interface UserSourceDirectorServiceInterface extends UserSourceDirectorInterface
|
||||
{
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exception;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
class SetNotPossibleException extends \Exception
|
||||
{
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace tests\Unit\Domain\RightManagement;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
@ -7,19 +8,16 @@ use App\Entity\Source\SourceInterface;
|
||||
use App\Domain\RightManagement\UserRightService;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author kevinfrantz
|
||||
*
|
||||
*/
|
||||
class UserRightServiceTest extends TestCase
|
||||
{
|
||||
public function testUserSet():void{
|
||||
public function testUserSet(): void
|
||||
{
|
||||
$user = new User();
|
||||
$source = $this->createMock(SourceInterface::class);
|
||||
$user->setSource($source);
|
||||
$userRight = new UserRightService($user);
|
||||
$this->assertEquals($source, $userRight->getReciever());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user