refactor : reorganize codebase to DDD architecture
Some checks failed
Auto Tag Develop / tag (push) Has been cancelled
Some checks failed
Auto Tag Develop / tag (push) Has been cancelled
Backend: - src/Api/Auth/State/ — MeProvider, UserPasswordHasherProcessor - src/Api/Shared/Resource/ — AppVersion - src/Api/Shared/State/ — AppVersionProvider - src/Domain/, src/Application/, src/Infrastructure/ — skeleton ready - User entity stays in src/Entity/ (framework, outside DDD) Frontend: - frontend/domains/ — skeleton ready for bounded contexts Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
24
src/Api/Auth/State/MeProvider.php
Normal file
24
src/Api/Auth/State/MeProvider.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Api\Auth\State;
|
||||
|
||||
use ApiPlatform\Metadata\Operation;
|
||||
use ApiPlatform\State\ProviderInterface;
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
|
||||
/**
|
||||
* @implements ProviderInterface<\App\Entity\User>
|
||||
*/
|
||||
class MeProvider implements ProviderInterface
|
||||
{
|
||||
public function __construct(
|
||||
private readonly Security $security,
|
||||
) {}
|
||||
|
||||
public function provide(Operation $operation, array $uriVariables = [], array $context = []): ?object
|
||||
{
|
||||
return $this->security->getUser();
|
||||
}
|
||||
}
|
||||
34
src/Api/Auth/State/UserPasswordHasherProcessor.php
Normal file
34
src/Api/Auth/State/UserPasswordHasherProcessor.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Api\Auth\State;
|
||||
|
||||
use ApiPlatform\Metadata\Operation;
|
||||
use ApiPlatform\State\ProcessorInterface;
|
||||
use App\Entity\User;
|
||||
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
|
||||
|
||||
/**
|
||||
* @implements ProcessorInterface<User, User>
|
||||
*/
|
||||
class UserPasswordHasherProcessor implements ProcessorInterface
|
||||
{
|
||||
public function __construct(
|
||||
/** @var ProcessorInterface<User, User> */
|
||||
private readonly ProcessorInterface $persistProcessor,
|
||||
private readonly UserPasswordHasherInterface $passwordHasher,
|
||||
) {}
|
||||
|
||||
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): mixed
|
||||
{
|
||||
if ($data instanceof User && null !== $data->getPlainPassword()) {
|
||||
$data->setPassword(
|
||||
$this->passwordHasher->hashPassword($data, $data->getPlainPassword())
|
||||
);
|
||||
$data->eraseCredentials();
|
||||
}
|
||||
|
||||
return $this->persistProcessor->process($data, $operation, $uriVariables, $context);
|
||||
}
|
||||
}
|
||||
24
src/Api/Shared/Resource/AppVersion.php
Normal file
24
src/Api/Shared/Resource/AppVersion.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Api\Shared\Resource;
|
||||
|
||||
use ApiPlatform\Metadata\ApiResource;
|
||||
use ApiPlatform\Metadata\Get;
|
||||
use App\Api\Shared\State\AppVersionProvider;
|
||||
|
||||
#[ApiResource(
|
||||
operations: [
|
||||
new Get(
|
||||
uriTemplate: '/version',
|
||||
provider: AppVersionProvider::class,
|
||||
),
|
||||
],
|
||||
)]
|
||||
class AppVersion
|
||||
{
|
||||
public function __construct(
|
||||
public readonly string $version,
|
||||
) {}
|
||||
}
|
||||
26
src/Api/Shared/State/AppVersionProvider.php
Normal file
26
src/Api/Shared/State/AppVersionProvider.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Api\Shared\State;
|
||||
|
||||
use ApiPlatform\Metadata\Operation;
|
||||
use ApiPlatform\State\ProviderInterface;
|
||||
use App\Api\Shared\Resource\AppVersion;
|
||||
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
||||
|
||||
/**
|
||||
* @implements ProviderInterface<object>
|
||||
*/
|
||||
class AppVersionProvider implements ProviderInterface
|
||||
{
|
||||
public function __construct(
|
||||
#[Autowire(param: 'app.version')]
|
||||
private readonly string $appVersion,
|
||||
) {}
|
||||
|
||||
public function provide(Operation $operation, array $uriVariables = [], array $context = []): object
|
||||
{
|
||||
return new AppVersion($this->appVersion);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user