Migración completa a Clean Architecture con componentes funcionales
- Reorganización de estructura: Admin/, Public/, Shared/, Schemas/ - 12 componentes migrados: TopNotificationBar, Navbar, CtaLetsTalk, Hero, FeaturedImage, TableOfContents, CtaBoxSidebar, SocialShare, CtaPost, RelatedPost, ContactForm, Footer - Panel de administración con tabs Bootstrap 5 funcionales - Schemas JSON para configuración de componentes - Renderers dinámicos con CSSGeneratorService (cero CSS hardcodeado) - FormBuilders para UI admin con Design System consistente - Fix: Bootstrap JS cargado en header para tabs funcionales - Fix: buildTextInput maneja valores mixed (bool/string) - Eliminación de estructura legacy (src/, admin/, assets/css/componente-*) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
141
shared/Infrastructure/Facades/ComponentManager.php
Normal file
141
shared/Infrastructure/Facades/ComponentManager.php
Normal file
@@ -0,0 +1,141 @@
|
||||
<?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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user