COMPLETADO: Fase 1 de la migración a Clean Architecture + POO ## Estructura de Carpetas - ✓ Estructura completa de 4 capas (Domain, Application, Infrastructure, Presentation) - ✓ Carpetas de Use Cases (SaveComponent, GetComponent, DeleteComponent, SyncSchema) - ✓ Estructura de tests (Unit, Integration, E2E) - ✓ Carpetas de schemas y templates ## Composer y Autoloading - ✓ PSR-4 autoloading configurado para ROITheme namespace - ✓ Autoloader optimizado regenerado ## DI Container - ✓ DIContainer implementado con patrón Singleton - ✓ Métodos set(), get(), has() para gestión de servicios - ✓ Getters específicos para ComponentRepository, ValidationService, CacheService - ✓ Placeholders que serán implementados en Fase 5 - ✓ Prevención de clonación y deserialización ## Interfaces - ✓ ComponentRepositoryInterface (Domain) - ✓ ValidationServiceInterface (Application) - ✓ CacheServiceInterface (Application) - ✓ Component entity placeholder (Domain) ## Bootstrap - ✓ functions.php actualizado con carga de Composer autoloader - ✓ Inicialización del DIContainer - ✓ Helper function roi_container() disponible globalmente ## Tests - ✓ 10 tests unitarios para DIContainer (100% cobertura) - ✓ Total: 13 tests unitarios, 28 assertions - ✓ Suite de tests pasando correctamente ## Validación - ✓ Script de validación automatizado (48/48 checks pasados) - ✓ 100% de validaciones exitosas La arquitectura base está lista para la Fase 2. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
154 lines
3.5 KiB
PHP
154 lines
3.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace ROITheme\Infrastructure\DI;
|
|
|
|
use ROITheme\Domain\Component\ComponentRepositoryInterface;
|
|
use ROITheme\Application\Contracts\ValidationServiceInterface;
|
|
use ROITheme\Application\Contracts\CacheServiceInterface;
|
|
|
|
/**
|
|
* Dependency Injection Container
|
|
*
|
|
* Singleton container that manages all service instances.
|
|
* Provides centralized access to dependencies throughout the application.
|
|
*
|
|
* @package ROITheme\Infrastructure\DI
|
|
*/
|
|
final class DIContainer
|
|
{
|
|
private static ?DIContainer $instance = null;
|
|
|
|
/** @var array<string, object> */
|
|
private array $services = [];
|
|
|
|
/**
|
|
* Private constructor to prevent direct instantiation
|
|
*/
|
|
private function __construct()
|
|
{
|
|
// Initialize services here
|
|
}
|
|
|
|
/**
|
|
* Get singleton instance
|
|
*
|
|
* @return self
|
|
*/
|
|
public static function getInstance(): self
|
|
{
|
|
if (self::$instance === null) {
|
|
self::$instance = new self();
|
|
}
|
|
|
|
return self::$instance;
|
|
}
|
|
|
|
/**
|
|
* Prevent cloning
|
|
*/
|
|
private function __clone()
|
|
{
|
|
}
|
|
|
|
/**
|
|
* Prevent unserialization
|
|
*
|
|
* @throws \Exception
|
|
*/
|
|
public function __wakeup(): void
|
|
{
|
|
throw new \Exception('Cannot unserialize singleton');
|
|
}
|
|
|
|
/**
|
|
* Get Component Repository
|
|
*
|
|
* @return ComponentRepositoryInterface
|
|
*/
|
|
public function getComponentRepository(): ComponentRepositoryInterface
|
|
{
|
|
if (!isset($this->services['component_repository'])) {
|
|
// Placeholder - will be replaced in Phase 5
|
|
throw new \RuntimeException('ComponentRepository not implemented yet. Will be available in Phase 5.');
|
|
}
|
|
|
|
return $this->services['component_repository'];
|
|
}
|
|
|
|
/**
|
|
* Get Validation Service
|
|
*
|
|
* @return ValidationServiceInterface
|
|
*/
|
|
public function getValidationService(): ValidationServiceInterface
|
|
{
|
|
if (!isset($this->services['validation_service'])) {
|
|
// Placeholder - will be replaced in Phase 5
|
|
throw new \RuntimeException('ValidationService not implemented yet. Will be available in Phase 5.');
|
|
}
|
|
|
|
return $this->services['validation_service'];
|
|
}
|
|
|
|
/**
|
|
* Get Cache Service
|
|
*
|
|
* @return CacheServiceInterface
|
|
*/
|
|
public function getCacheService(): CacheServiceInterface
|
|
{
|
|
if (!isset($this->services['cache_service'])) {
|
|
// Placeholder - will be replaced in Phase 5
|
|
throw new \RuntimeException('CacheService not implemented yet. Will be available in Phase 5.');
|
|
}
|
|
|
|
return $this->services['cache_service'];
|
|
}
|
|
|
|
/**
|
|
* Register a service
|
|
*
|
|
* @param string $key Service identifier
|
|
* @param object $service Service instance
|
|
* @return void
|
|
*/
|
|
public function set(string $key, object $service): void
|
|
{
|
|
$this->services[$key] = $service;
|
|
}
|
|
|
|
/**
|
|
* Check if service exists
|
|
*
|
|
* @param string $key Service identifier
|
|
* @return bool
|
|
*/
|
|
public function has(string $key): bool
|
|
{
|
|
return isset($this->services[$key]);
|
|
}
|
|
|
|
/**
|
|
* Get a service by key
|
|
*
|
|
* @param string $key Service identifier
|
|
* @return object|null
|
|
*/
|
|
public function get(string $key): ?object
|
|
{
|
|
return $this->services[$key] ?? null;
|
|
}
|
|
|
|
/**
|
|
* Reset container (useful for testing)
|
|
*
|
|
* @return void
|
|
*/
|
|
public static function reset(): void
|
|
{
|
|
self::$instance = null;
|
|
}
|
|
}
|