fix : fix UserOutput type and use UserRepositoryInterface in CreateUserCommand
Change UserOutput.id from int to ?int to match User::getId() return type. Replace EntityManagerInterface with UserRepositoryInterface in CreateUserCommand. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -10,7 +10,7 @@ use DateTimeImmutable;
|
|||||||
final readonly class UserOutput
|
final readonly class UserOutput
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
public int $id,
|
public ?int $id,
|
||||||
public string $username,
|
public string $username,
|
||||||
/** @var list<string> */
|
/** @var list<string> */
|
||||||
public array $roles,
|
public array $roles,
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ declare(strict_types=1);
|
|||||||
namespace App\Module\Core\Infrastructure\Console;
|
namespace App\Module\Core\Infrastructure\Console;
|
||||||
|
|
||||||
use App\Module\Core\Domain\Entity\User;
|
use App\Module\Core\Domain\Entity\User;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use App\Module\Core\Domain\Repository\UserRepositoryInterface;
|
||||||
use Symfony\Component\Console\Attribute\AsCommand;
|
use Symfony\Component\Console\Attribute\AsCommand;
|
||||||
use Symfony\Component\Console\Command\Command;
|
use Symfony\Component\Console\Command\Command;
|
||||||
use Symfony\Component\Console\Input\InputArgument;
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
@@ -22,7 +22,7 @@ use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
|
|||||||
class CreateUserCommand extends Command
|
class CreateUserCommand extends Command
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly EntityManagerInterface $em,
|
private readonly UserRepositoryInterface $userRepository,
|
||||||
private readonly UserPasswordHasherInterface $passwordHasher,
|
private readonly UserPasswordHasherInterface $passwordHasher,
|
||||||
) {
|
) {
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
@@ -52,8 +52,7 @@ class CreateUserCommand extends Command
|
|||||||
$user->setRoles(['ROLE_ADMIN']);
|
$user->setRoles(['ROLE_ADMIN']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->em->persist($user);
|
$this->userRepository->save($user);
|
||||||
$this->em->flush();
|
|
||||||
|
|
||||||
$io->success(sprintf('User "%s" created%s.', $username, $input->getOption('admin') ? ' with ROLE_ADMIN' : ''));
|
$io->success(sprintf('User "%s" created%s.', $username, $input->getOption('admin') ? ' with ROLE_ADMIN' : ''));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user