<?php
/**
* Service Definitions for DI Container.
*
* All repositories and services are explicitly registered to ensure
* proper database connections and avoid instantiation in controllers.
*
* @param Framework\Container $container
*/
use Application\ContentCollectionService;
use Application\PipelineStepService;
use Domain\Repository\ChatMessageRepositoryInterface;
use Domain\Repository\ChatSessionRepositoryInterface;
use Domain\Repository\CodeAnalysisRepositoryInterface;
use Domain\Repository\CollectionRepositoryInterface;
use Domain\Repository\ContentRepositoryInterface;
use Domain\Repository\DokumentationRepositoryInterface;
use Domain\Repository\PipelineRepositoryInterface;
use Domain\Repository\TaskRepositoryInterface;
use Domain\Service\CodeScannerInterface;
use Framework\Container;
use Infrastructure\AI\AIConfig;
use Infrastructure\AI\ChatService;
use Infrastructure\AI\ContentQualityValidator;
use Infrastructure\AI\ModelRegistry;
use Infrastructure\AI\OllamaService;
use Infrastructure\AI\QdrantService;
use Infrastructure\AI\VectorSearchService;
use Infrastructure\CodeAnalysis\CodeScanner;
use Infrastructure\CodeAnalysis\JsFileParser;
use Infrastructure\CodeAnalysis\PhpFileParser;
use Infrastructure\CodeAnalysis\PythonFileParser;
use Infrastructure\Config\DatabaseFactory;
use Infrastructure\Docs\ChunkAnalysisService;
use Infrastructure\Docs\ChunkingService;
use Infrastructure\Docs\ChunkSyncService;
use Infrastructure\Docs\HybridSearchService;
use Infrastructure\Formatter\ApiResponseFormatter;
use Infrastructure\Formatting\ChatMessageFormatter;
use Infrastructure\Logging\AuditLogger;
use Infrastructure\Persistence\ChatMessageRepository;
use Infrastructure\Persistence\ChatSessionRepository;
use Infrastructure\Persistence\CodeAnalysisRepository;
use Infrastructure\Persistence\CollectionRepository;
use Infrastructure\Persistence\ContentConfigRepository;
use Infrastructure\Persistence\ContentRepository;
use Infrastructure\Persistence\ContractRepository;
use Infrastructure\Persistence\CriticsRepository;
use Infrastructure\Persistence\DokumentationRepository;
use Infrastructure\Persistence\FileBackupRepository;
use Infrastructure\Persistence\KiProtokollRepository;
use Infrastructure\Persistence\PipelineRepository;
use Infrastructure\Persistence\PromptsRepository;
use Infrastructure\Persistence\SystemExplorerRepository;
use Infrastructure\Persistence\TaskAssignmentRepository;
use Infrastructure\Persistence\TaskCommentRepository;
use Infrastructure\Persistence\TaskRepository;
use Infrastructure\Persistence\TaskResultRepository;
use Infrastructure\SemanticExplorerRepository;
use Infrastructure\Validation\CollectionValidator;
// NOTE: UseCases are NOT explicitly registered here.
// They are resolved via Container::autowire() automatically.
// Only register: Interfaces, Services with special config, Repositories.
return function (Container $container): void {
// =========================================================================
// DATABASE CONNECTIONS
// =========================================================================
// ki_dev database connection
$container->set('pdo.dev', fn () => DatabaseFactory::dev());
// ki_content database connection
$container->set('pdo.content', fn () => DatabaseFactory::content());
// =========================================================================
// REPOSITORIES - ki_dev database
// =========================================================================
$container->set(SystemExplorerRepository::class, fn () => new SystemExplorerRepository());
$container->set(DokumentationRepository::class, fn () => new DokumentationRepository());
$container->set(FileBackupRepository::class, fn () => new FileBackupRepository());
$container->set(ContractRepository::class, fn () => new ContractRepository());
$container->set(TaskRepository::class, fn () => new TaskRepository());
$container->set(TaskAssignmentRepository::class, fn () => new TaskAssignmentRepository());
$container->set(TaskResultRepository::class, fn () => new TaskResultRepository());
$container->set(TaskCommentRepository::class, fn () => new TaskCommentRepository());
$container->set(KiProtokollRepository::class, fn () => new KiProtokollRepository());
$container->set(CollectionRepository::class, fn () => new CollectionRepository());
$container->set(PipelineRepository::class, fn () => new PipelineRepository());
$container->set(CodeAnalysisRepository::class, function (Container $c) {
return new CodeAnalysisRepository($c->get('pdo.dev'));
});
// =========================================================================
// REPOSITORIES - ki_content database
// =========================================================================
$container->set(ContentRepository::class, fn () => new ContentRepository());
$container->set(SemanticExplorerRepository::class, fn () => new SemanticExplorerRepository());
$container->set(ChatSessionRepository::class, fn () => new ChatSessionRepository());
$container->set(ChatMessageRepository::class, fn () => new ChatMessageRepository());
$container->set(PromptsRepository::class, fn () => new PromptsRepository());
$container->set(CriticsRepository::class, fn () => new CriticsRepository());
$container->set(ContentConfigRepository::class, fn () => new ContentConfigRepository());
// =========================================================================
// INTERFACE ALIASES (Domain → Infrastructure)
// =========================================================================
$container->set(TaskRepositoryInterface::class, fn (Container $c) => $c->get(TaskRepository::class));
$container->set(ChatSessionRepositoryInterface::class, fn (Container $c) => $c->get(ChatSessionRepository::class));
$container->set(ChatMessageRepositoryInterface::class, fn (Container $c) => $c->get(ChatMessageRepository::class));
$container->set(CollectionRepositoryInterface::class, fn (Container $c) => $c->get(CollectionRepository::class));
$container->set(PipelineRepositoryInterface::class, fn (Container $c) => $c->get(PipelineRepository::class));
$container->set(ContentRepositoryInterface::class, fn (Container $c) => $c->get(ContentRepository::class));
$container->set(DokumentationRepositoryInterface::class, fn (Container $c) => $c->get(DokumentationRepository::class));
$container->set(CodeAnalysisRepositoryInterface::class, fn (Container $c) => $c->get(CodeAnalysisRepository::class));
// =========================================================================
// CODE ANALYSIS SERVICES
// =========================================================================
$container->set(PhpFileParser::class, fn () => new PhpFileParser());
$container->set(CodeScanner::class, function (Container $c) {
return new CodeScanner(
$c->get(CodeAnalysisRepository::class),
$c->get(PhpFileParser::class)
);
});
$container->set(CodeScannerInterface::class, fn (Container $c) => $c->get(CodeScanner::class));
// =========================================================================
// AI SERVICES
// =========================================================================
$container->set(AIConfig::class, fn () => AIConfig::fromCredentialsFile());
$container->set(ChatService::class, function (Container $c) {
return $c->get(AIConfig::class)->createChatService();
});
$container->set(OllamaService::class, function (Container $c) {
return $c->get(AIConfig::class)->createOllamaService();
});
$container->set(QdrantService::class, function (Container $c) {
return $c->get(AIConfig::class)->createQdrantService();
});
$container->set(VectorSearchService::class, fn () => new VectorSearchService());
$container->set(ContentQualityValidator::class, function (Container $c) {
return new ContentQualityValidator($c->get(OllamaService::class));
});
$container->set(ModelRegistry::class, function (Container $c) {
return new ModelRegistry($c->get('pdo.dev'));
});
// =========================================================================
// APPLICATION SERVICES
// =========================================================================
$container->set(AuditLogger::class, fn () => new AuditLogger());
$container->set(ChunkSyncService::class, function (Container $c) {
return new ChunkSyncService(
$c->get('pdo.dev'),
$c->get(OllamaService::class)
);
});
$container->set(HybridSearchService::class, function (Container $c) {
return new HybridSearchService(
$c->get('pdo.dev'),
$c->get(OllamaService::class)
);
});
$container->set(ChunkAnalysisService::class, function (Container $c) {
return new ChunkAnalysisService(
$c->get('pdo.dev'),
$c->get(OllamaService::class)
);
});
$container->set(ChunkingService::class, function (Container $c) {
return new ChunkingService(
$c->get('pdo.dev'),
$c->get(DokumentationRepository::class)
);
});
$container->set(CollectionValidator::class, function (Container $c) {
return new CollectionValidator($c->get(CollectionRepository::class));
});
$container->set(ContentCollectionService::class, function (Container $c) {
return new ContentCollectionService(
$c->get(CollectionRepository::class),
$c->get(CollectionValidator::class)
);
});
$container->set(PipelineStepService::class, function (Container $c) {
return new PipelineStepService($c->get(PipelineRepository::class));
});
// =========================================================================
// FORMATTERS
// =========================================================================
$container->set(ApiResponseFormatter::class, fn () => new ApiResponseFormatter());
$container->set(ChatMessageFormatter::class, fn () => new ChatMessageFormatter());
// =========================================================================
// USE CASES - Resolved via Autowiring
// =========================================================================
// All UseCases are automatically resolved by Container::autowire().
// Dependencies are injected based on constructor type-hints.
// No explicit registration needed - just ensure:
// 1. All interface dependencies have aliases registered above
// 2. All concrete dependencies are registered or autowirable
};