*/ 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; } }