Files
roi-theme/shared/Infrastructure/Facades/ComponentManager.php
FrankZamora 71cfd54166 fix: Corregir case de namespaces para compatibilidad Linux/PSR-4
Cambios realizados:
- \API\ → \Api\ (4 archivos)
- \WordPress → \Wordpress (12 archivos)
- \DI\ → \Di\ (4 archivos)

Los namespaces ahora coinciden exactamente con la estructura
de carpetas (Api/, Wordpress/, Di/) para garantizar
compatibilidad con sistemas case-sensitive (Linux/producción)
y cumplimiento de PSR-4.

Archivos corregidos: 16

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-26 18:12:05 -06:00

142 lines
3.8 KiB
PHP

<?php
declare(strict_types=1);
namespace ROITheme\Shared\Infrastructure\Facades;
use ROITheme\Shared\Application\UseCases\SaveComponent\SaveComponentUseCase;
use ROITheme\Shared\Application\UseCases\SaveComponent\SaveComponentRequest;
use ROITheme\Shared\Application\UseCases\GetComponent\GetComponentUseCase;
use ROITheme\Shared\Application\UseCases\GetComponent\GetComponentRequest;
use ROITheme\Shared\Application\UseCases\DeleteComponent\DeleteComponentUseCase;
use ROITheme\Shared\Application\UseCases\DeleteComponent\DeleteComponentRequest;
use ROITheme\Shared\Infrastructure\Di\DIContainer;
/**
* ComponentManager - Facade para el sistema
*
* RESPONSABILIDAD: Punto de entrada unificado y simple
*
* PATRÓN: Facade
* - Oculta complejidad interna
* - Proporciona API simple
* - Orquesta Use Cases
*
* USO:
* ```php
* $manager = new ComponentManager($container);
* $result = $manager->saveComponent('top_bar', $data);
* ```
*
* @package ROITheme\Infrastructure\Facades
*/
final class ComponentManager
{
public function __construct(
private DIContainer $container
) {}
/**
* Guardar componente
*
* @param string $componentName
* @param array $data
* @return array ['success' => bool, 'data' => mixed, 'errors' => array|null]
*/
public function saveComponent(string $componentName, array $data): array
{
$request = new SaveComponentRequest($componentName, $data);
$useCase = new SaveComponentUseCase(
$this->container->getComponentRepository(),
$this->container->getValidationService(),
$this->container->getCacheService()
);
$response = $useCase->execute($request);
return $response->toArray();
}
/**
* Obtener componente
*
* @param string $componentName
* @return array ['success' => bool, 'data' => mixed, 'error' => string|null]
*/
public function getComponent(string $componentName): array
{
$request = new GetComponentRequest($componentName);
$useCase = new GetComponentUseCase(
$this->container->getComponentRepository(),
$this->container->getCacheService()
);
$response = $useCase->execute($request);
return $response->toArray();
}
/**
* Eliminar componente
*
* @param string $componentName
* @return array ['success' => bool, 'message' => string|null, 'error' => string|null]
*/
public function deleteComponent(string $componentName): array
{
$request = new DeleteComponentRequest($componentName);
$useCase = new DeleteComponentUseCase(
$this->container->getComponentRepository(),
$this->container->getCacheService()
);
$response = $useCase->execute($request);
return [
'success' => $response->isSuccess(),
'message' => $response->getMessage(),
'error' => $response->getError()
];
}
/**
* Sincronizar schemas desde JSON
*
* @param string|null $componentName Si null, sincroniza todos
* @return array
*/
public function syncSchema(?string $componentName = null): array
{
$syncService = $this->container->getSchemaSyncService();
if ($componentName === null) {
return $syncService->syncAll();
}
return $syncService->syncComponent($componentName);
}
/**
* Limpiar componentes obsoletos
*
* @return array ['removed' => array]
*/
public function cleanup(): array
{
$cleanupService = $this->container->getCleanupService();
return $cleanupService->removeObsolete();
}
/**
* Invalidar todo el cache
*
* @return bool
*/
public function invalidateCache(): bool
{
return $this->container->getCacheService()->invalidateAll();
}
}