<?php
declare(strict_types=1);

namespace PpPhp\Core\Platform\DI\Compiler\Stages;

use PpPhp\Core\Platform\DI\Compiler\CompilerContext;
use PpPhp\Core\Platform\DI\Compiler\CompilerStageInterface;
use PpPhp\Core\Platform\DI\Compiler\DefinitionCompiler;

final class DefinitionCompilationStage implements CompilerStageInterface
{
    public function __construct(private readonly DefinitionCompiler $compiler = new DefinitionCompiler()) {}

    public function name(): string { return 'definition-compilation'; }

    public function process(CompilerContext $context): void
    {
        foreach ($context->definitions()->all() as $definition) {
            $context->addCompiled($this->compiler->compile($definition));
        }
    }
}
