feat : mise à jour de la structure du projet

This commit is contained in:
2026-04-09 11:02:19 +02:00
parent bcfecb2281
commit 68d62c31ec
69 changed files with 4782 additions and 408 deletions
@@ -0,0 +1,26 @@
<?php
declare(strict_types=1);
namespace App\Shared\Infrastructure\ApiPlatform\State;
use ApiPlatform\Metadata\Operation;
use ApiPlatform\State\ProviderInterface;
use App\Shared\Infrastructure\ApiPlatform\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);
}
}
@@ -0,0 +1,38 @@
<?php
declare(strict_types=1);
namespace App\Shared\Infrastructure\ApiPlatform\State;
use ApiPlatform\Metadata\Operation;
use ApiPlatform\State\ProviderInterface;
use App\Shared\Infrastructure\ApiPlatform\Resource\ModulesResource;
/**
* @implements ProviderInterface<object>
*/
class ModulesProvider implements ProviderInterface
{
/** @var list<string> */
private readonly array $activeModuleIds;
public function __construct()
{
$configPath = dirname(__DIR__, 5).'/config/modules.php';
$moduleClasses = file_exists($configPath) ? require $configPath : [];
$ids = [];
foreach ($moduleClasses as $moduleClass) {
if (defined($moduleClass.'::ID')) {
$ids[] = $moduleClass::ID;
}
}
$this->activeModuleIds = $ids;
}
public function provide(Operation $operation, array $uriVariables = [], array $context = []): object
{
return new ModulesResource($this->activeModuleIds);
}
}
@@ -0,0 +1,81 @@
<?php
declare(strict_types=1);
namespace App\Shared\Infrastructure\ApiPlatform\State;
use ApiPlatform\Metadata\Operation;
use ApiPlatform\State\ProviderInterface;
use App\Shared\Infrastructure\ApiPlatform\Resource\SidebarResource;
/**
* @implements ProviderInterface<object>
*/
class SidebarProvider implements ProviderInterface
{
/** @var list<string> */
private readonly array $activeModuleIds;
/** @var list<array{label: string, icon: string, items: list<array{label: string, to: string, icon: string, module: string}>}> */
private readonly array $sidebarConfig;
public function __construct()
{
$configDir = dirname(__DIR__, 5).'/config';
// Load active modules
$modulesFile = $configDir.'/modules.php';
$moduleClasses = file_exists($modulesFile) ? require $modulesFile : [];
$ids = [];
foreach ($moduleClasses as $moduleClass) {
if (defined($moduleClass.'::ID')) {
$ids[] = $moduleClass::ID;
}
}
$this->activeModuleIds = $ids;
// Load sidebar config
$sidebarFile = $configDir.'/sidebar.php';
$this->sidebarConfig = file_exists($sidebarFile) ? require $sidebarFile : [];
}
public function provide(Operation $operation, array $uriVariables = [], array $context = []): object
{
$sections = [];
$disabledRoutes = [];
foreach ($this->sidebarConfig as $section) {
$items = [];
foreach ($section['items'] ?? [] as $item) {
$isActive = in_array($item['module'] ?? null, $this->activeModuleIds, true);
if (!$isActive) {
if (isset($item['to'])) {
$disabledRoutes[] = $item['to'];
}
continue;
}
$items[] = [
'label' => $item['label'],
'to' => $item['to'],
'icon' => $item['icon'],
];
}
if ([] === $items) {
continue;
}
$sections[] = [
'label' => $section['label'],
'icon' => $section['icon'],
'items' => $items,
];
}
return new SidebarResource($sections, array_values(array_unique($disabledRoutes)));
}
}