infinito/application/symfony/src/Domain/UserManagement/UserSourceDirector.php

59 lines
1.3 KiB
PHP
Raw Normal View History

2019-01-04 20:41:37 +01:00
<?php
namespace App\Domain\UserManagement;
use App\Entity\UserInterface;
use App\DBAL\Types\SystemSlugType;
use App\Entity\User;
2019-01-15 22:57:54 +01:00
use App\Repository\Source\SourceRepositoryInterface;
2019-01-04 20:41:37 +01:00
/**
* @author kevinfrantz
*/
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();
$this->user->setSource($this->sourceRepository->findOneBySlug(SystemSlugType::GUEST_USER));
}
/**
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
{
$this->sourceRepository = $sourceRepository;
2019-01-04 20:41:37 +01:00
$this->setUser($user);
}
/**
* {@inheritdoc}
*
* @see \App\Domain\UserManagement\UserSourceDirectorInterface::getUser()
2019-01-04 20:41:37 +01:00
*/
public function getUser(): UserInterface
{
return $this->user;
}
}