Files
roi-theme/Shared/Infrastructure/Facades/ComponentManager.php
FrankZamora 90863cd8f5 fix(structure): Correct case-sensitivity for Linux compatibility
Rename folders to match PHP PSR-4 autoloading conventions:
- schemas → Schemas
- shared → Shared
- Wordpress → WordPress (in all locations)

Fixes deployment issues on Linux servers where filesystem is case-sensitive.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-26 22:53:34 -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();
}
}