Optimized draft for UserSourceDirector and UserRight

This commit is contained in:
Kevin Frantz
2019-01-13 14:00:16 +01:00
parent 1dc428bcfd
commit 2837df25f8
12 changed files with 108 additions and 100 deletions

View File

@@ -1,12 +0,0 @@
<?php
namespace App\Domain\UserManagement;
/**
*
* @author kevinfrantz
*
*/
interface UserIdentityServiceInterface extends UserIdentityManagerInterface
{
}

View File

@@ -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
{

View File

@@ -4,7 +4,7 @@ namespace App\Domain\UserManagement;
use App\Entity\UserInterface;
interface UserIdentityManagerInterface
interface UserSourceDirectorInterface
{
/**
* @return UserInterface

View File

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

View File

@@ -0,0 +1,10 @@
<?php
namespace App\Domain\UserManagement;
/**
* @author kevinfrantz
*/
interface UserSourceDirectorServiceInterface extends UserSourceDirectorInterface
{
}