[ AppConfig::class => $config, View::class => new View(dirname(__DIR__) . '/templates'), LoggerInterface::class => static fn (): LoggerInterface => LoggerFactory::create($config), PDO::class => static fn (): PDO => new PDO( sprintf('pgsql:host=%s;port=%d;dbname=%s', $config->dbHost, $config->dbPort, $config->dbName), $config->dbUser, $config->dbPassword, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_EMULATE_PREPARES => false], ), PathSafety::class => static fn (): PathSafety => new PathSafety($config->libraryPath), FileEnumeratorInterface::class => static fn (ContainerInterface $c): FileEnumeratorInterface => new FileEnumerator(new LocalFilesystem(), $c->get(PathSafety::class)), SpaceChecker::class => static fn (): SpaceChecker => new SpaceChecker(), StreamingHasher::class => static fn (ContainerInterface $c): StreamingHasher => new StreamingHasher($c->get(PathSafety::class)), StlValidator::class => static fn (ContainerInterface $c): StlValidator => new StlValidator($c->get(PathSafety::class)), VerifiedCopier::class => static fn (ContainerInterface $c): VerifiedCopier => new VerifiedCopier($c->get(PathSafety::class)), // Repositories share one PDO connection so the job repository's atomic() is a real transaction. CatalogRepositoryInterface::class => static fn (ContainerInterface $c): CatalogRepositoryInterface => new PdoCatalogRepository($c->get(PDO::class)), CatalogService::class => static fn (ContainerInterface $c): CatalogService => new CatalogService($c->get(CatalogRepositoryInterface::class)), ImportJobRepositoryInterface::class => static fn (ContainerInterface $c): ImportJobRepositoryInterface => new PdoImportJobRepository($c->get(PDO::class)), ImportService::class => static fn (ContainerInterface $c): ImportService => new ImportService( $c->get(FileEnumeratorInterface::class), $c->get(ImportJobRepositoryInterface::class), $c->get(CatalogRepositoryInterface::class), $c->get(SpaceChecker::class), $config->libraryPath, ), ImportWorkerFactory::class => static fn (ContainerInterface $c): ImportWorkerFactory => new class ($c) implements ImportWorkerFactory { public function __construct(private readonly ContainerInterface $c) { } public function __invoke(callable $shouldStop): ImportWorker { /** @var PathSafety $safety */ $safety = $c->get(PathSafety::class); return new ImportWorker( $c->get(ImportJobRepositoryInterface::class), $c->get(CatalogRepositoryInterface::class), $c->get(StreamingHasher::class), $c->get(VerifiedCopier::class), $c->get(StlValidator::class), $safety, $c->get(SpaceChecker::class), $safety->libraryRoot(), $c->get(LoggerInterface::class), $shouldStop, ); } }, ConsoleServices::class => static fn (ContainerInterface $c): ConsoleServices => new ContainerConsoleServices( $c->get(ImportService::class), $c->get(ImportWorkerFactory::class), ), ];