Ported AbstractFactory, UserFactory.
This commit is contained in:
parent
7c9ee60103
commit
5afc8d91b4
|
@ -1,16 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace src\PointToolsBundle\Service\Factory;
|
|
||||||
|
|
||||||
use Psr\Log\LoggerInterface;
|
|
||||||
|
|
||||||
abstract class AbstractFactory
|
|
||||||
{
|
|
||||||
/** @var LoggerInterface */
|
|
||||||
protected $logger;
|
|
||||||
|
|
||||||
public function __construct(LoggerInterface $logger)
|
|
||||||
{
|
|
||||||
$this->logger = $logger;
|
|
||||||
}
|
|
||||||
}
|
|
14
src/Factory/AbstractFactory.php
Normal file
14
src/Factory/AbstractFactory.php
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Factory;
|
||||||
|
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
|
|
||||||
|
abstract class AbstractFactory
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
protected LoggerInterface $logger,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,35 +1,25 @@
|
||||||
<?php
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace src\PointToolsBundle\Service\Factory;
|
namespace App\Factory;
|
||||||
|
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use src\PointToolsBundle\DTO\Api\User as UserDTO;
|
use App\DTO\Api\User as UserDTO;
|
||||||
use src\PointToolsBundle\Entity\User;
|
use App\Entity\User;
|
||||||
use src\PointToolsBundle\Repository\UserRepository;
|
use App\Exception\Factory\InvalidUserDataException;
|
||||||
use src\PointToolsBundle\Exception\Factory\InvalidUserDataException;
|
use App\Repository\UserRepository;
|
||||||
use src\PointToolsBundle\Service\Factory\AbstractFactory;
|
|
||||||
|
|
||||||
class UserFactory extends AbstractFactory
|
class UserFactory extends AbstractFactory
|
||||||
{
|
{
|
||||||
public const DATE_FORMAT = 'Y-m-d_H:i:s';
|
public const DATE_FORMAT = 'Y-m-d_H:i:s';
|
||||||
|
|
||||||
/** @var UserRepository */
|
public function __construct(
|
||||||
private $userRepository;
|
LoggerInterface $logger,
|
||||||
|
private readonly UserRepository $userRepository,
|
||||||
|
) {
|
||||||
public function __construct(LoggerInterface $logger, UserRepository $userRepository)
|
|
||||||
{
|
|
||||||
parent::__construct($logger);
|
parent::__construct($logger);
|
||||||
$this->userRepository = $userRepository;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param UserDTO $userData
|
|
||||||
*
|
|
||||||
* @return User
|
|
||||||
*
|
|
||||||
* @throws InvalidUserDataException
|
|
||||||
*/
|
|
||||||
public function findOrCreateFromDTO(UserDTO $userData): User
|
public function findOrCreateFromDTO(UserDTO $userData): User
|
||||||
{
|
{
|
||||||
// @todo LOG
|
// @todo LOG
|
||||||
|
@ -56,9 +46,7 @@ class UserFactory extends AbstractFactory
|
||||||
return $user;
|
return $user;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** @return User[] */
|
||||||
* @return User[]
|
|
||||||
*/
|
|
||||||
public function findOrCreateFromDTOArray(array $usersData): array
|
public function findOrCreateFromDTOArray(array $usersData): array
|
||||||
{
|
{
|
||||||
// @todo LOG
|
// @todo LOG
|
Loading…
Reference in a new issue