mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-01-09 22:17:26 +01:00
Implemented UserIdentityManager
This commit is contained in:
parent
a074932fb5
commit
e335544808
@ -6,11 +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\Entity\User;
|
|
||||||
use App\Domain\SecureLoadManagement\SecureSourceLoader;
|
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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This controller offers the standart routes for the template.
|
* This controller offers the standart routes for the template.
|
||||||
@ -23,16 +24,10 @@ class DefaultController extends AbstractEntityController
|
|||||||
* @todo Optimize function!
|
* @todo Optimize function!
|
||||||
* @Route("/imprint", name="imprint")
|
* @Route("/imprint", name="imprint")
|
||||||
*/
|
*/
|
||||||
public function imprint(): Response
|
public function imprint(EntityManagerInterface $entityManager): Response
|
||||||
{
|
{
|
||||||
if ($this->getUser()) {
|
$userIdentityManager = new UserIdentityManager($entityManager, $this->getUser());
|
||||||
$user = $this->getUser();
|
$user = $userIdentityManager->getUser();
|
||||||
} else {
|
|
||||||
$user = new User();
|
|
||||||
$user->setSource($this->getDoctrine()
|
|
||||||
->getRepository(AbstractSource::class)
|
|
||||||
->findOneBySlug(SystemSlugType::GUEST_USER));
|
|
||||||
}
|
|
||||||
$requestedSource = new class() extends AbstractSource {
|
$requestedSource = new class() extends AbstractSource {
|
||||||
};
|
};
|
||||||
$requestedSource->setSlug(SystemSlugType::IMPRINT);
|
$requestedSource->setSlug(SystemSlugType::IMPRINT);
|
||||||
|
@ -0,0 +1,68 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\UserManagement;
|
||||||
|
|
||||||
|
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
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var UserInterface
|
||||||
|
*/
|
||||||
|
private $user;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var SourceRepository
|
||||||
|
*/
|
||||||
|
private $sourceRepository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param EntityManagerInterface $entityManager
|
||||||
|
*/
|
||||||
|
private function setSourceRepository(EntityManagerInterface $entityManager): void
|
||||||
|
{
|
||||||
|
$this->sourceRepository = $entityManager->getRepository(AbstractSource::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param UserInterface $user
|
||||||
|
*/
|
||||||
|
private function setUser(?UserInterface $user): void
|
||||||
|
{
|
||||||
|
if ($user) {
|
||||||
|
$this->user = $user;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$this->user = new User();
|
||||||
|
$this->user->setSource($this->sourceRepository->findOneBySlug(SystemSlugType::GUEST_USER));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param EntityManagerInterface $entityManager
|
||||||
|
* @param UserInterface $user
|
||||||
|
*/
|
||||||
|
public function __construct(EntityManagerInterface $entityManager, ?UserInterface $user)
|
||||||
|
{
|
||||||
|
$this->setSourceRepository($entityManager);
|
||||||
|
$this->setUser($user);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*
|
||||||
|
* @see \App\Domain\UserManagement\UserIdentityManagerInterface::getUser()
|
||||||
|
*/
|
||||||
|
public function getUser(): UserInterface
|
||||||
|
{
|
||||||
|
return $this->user;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\UserManagement;
|
||||||
|
|
||||||
|
use App\Entity\UserInterface;
|
||||||
|
|
||||||
|
interface UserIdentityManagerInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @return UserInterface
|
||||||
|
*/
|
||||||
|
public function getUser(): UserInterface;
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Unit\Domain\UserManagement;
|
||||||
|
|
||||||
|
use App\Domain\UserManagement\UserIdentityManager;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||||
|
use App\DBAL\Types\SystemSlugType;
|
||||||
|
use App\Entity\User;
|
||||||
|
|
||||||
|
class UserIdentityManagerTest extends KernelTestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var EntityManagerInterface
|
||||||
|
*/
|
||||||
|
private $entityManager;
|
||||||
|
|
||||||
|
public function setUp(): void
|
||||||
|
{
|
||||||
|
self::bootKernel();
|
||||||
|
$this->entityManager = self::$container->get('doctrine.orm.default_entity_manager');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGuestUser(): void
|
||||||
|
{
|
||||||
|
$origineUser = null;
|
||||||
|
$userIdentityManager = new UserIdentityManager($this->entityManager, $origineUser);
|
||||||
|
$expectedUser = $userIdentityManager->getUser();
|
||||||
|
$this->assertEquals(SystemSlugType::GUEST_USER, $expectedUser->getSource()->getSlug());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUser(): void
|
||||||
|
{
|
||||||
|
$origineUser = new User();
|
||||||
|
$userIdentityManager = new UserIdentityManager($this->entityManager, $origineUser);
|
||||||
|
$expectedUser = $userIdentityManager->getUser();
|
||||||
|
$this->assertEquals($origineUser, $expectedUser);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user