2019-01-04 20:41:37 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Domain\UserManagement;
|
|
|
|
|
|
|
|
use App\Entity\UserInterface;
|
|
|
|
use App\Entity\User;
|
2019-01-15 22:57:54 +01:00
|
|
|
use App\Repository\Source\SourceRepositoryInterface;
|
2019-02-03 01:01:26 +01:00
|
|
|
use App\Domain\FixtureManagement\FixtureSource\GuestUserFixtureSource;
|
2019-01-04 20:41:37 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @author kevinfrantz
|
|
|
|
*/
|
2019-01-13 14:00:16 +01:00
|
|
|
final class UserSourceDirector implements UserSourceDirectorInterface
|
2019-01-04 20:41:37 +01:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var UserInterface
|
|
|
|
*/
|
|
|
|
private $user;
|
|
|
|
|
|
|
|
/**
|
2019-01-15 22:57:54 +01:00
|
|
|
* @var SourceRepositoryInterface
|
2019-01-04 20:41:37 +01:00
|
|
|
*/
|
|
|
|
private $sourceRepository;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param UserInterface $user
|
|
|
|
*/
|
|
|
|
private function setUser(?UserInterface $user): void
|
|
|
|
{
|
|
|
|
if ($user) {
|
|
|
|
$this->user = $user;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$this->user = new User();
|
2019-02-03 01:01:26 +01:00
|
|
|
$this->user->setSource($this->sourceRepository->findOneBySlug(GuestUserFixtureSource::getSlug()));
|
2019-01-04 20:41:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-01-15 22:57:54 +01:00
|
|
|
* @param SourceRepositoryInterface $sourceRepository
|
|
|
|
* @param UserInterface $user
|
2019-01-04 20:41:37 +01:00
|
|
|
*/
|
2019-01-15 22:57:54 +01:00
|
|
|
public function __construct(SourceRepositoryInterface $sourceRepository, ?UserInterface $user)
|
2019-01-04 20:41:37 +01:00
|
|
|
{
|
2019-01-13 14:00:16 +01:00
|
|
|
$this->sourceRepository = $sourceRepository;
|
2019-01-04 20:41:37 +01:00
|
|
|
$this->setUser($user);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*
|
2019-01-13 14:00:16 +01:00
|
|
|
* @see \App\Domain\UserManagement\UserSourceDirectorInterface::getUser()
|
2019-01-04 20:41:37 +01:00
|
|
|
*/
|
|
|
|
public function getUser(): UserInterface
|
|
|
|
{
|
|
|
|
return $this->user;
|
|
|
|
}
|
|
|
|
}
|