src/Compiler/Command/Extend/ExtendEnumTypeDefinitionCommand.php
<?php
declare(strict_types=1);
namespace Railt\SDL\Compiler\Command\Extend;
use Railt\SDL\Compiler\Command\Build\BuildEnumTypeDefinitionCommand;
use Railt\SDL\Compiler\Command\ExtendCommand;
use Railt\SDL\Exception\CompilationException;
use Railt\SDL\Node\Statement\Extension\EnumTypeExtensionNode;
use Railt\TypeSystem\Definition\Type\EnumType;
/**
* @template-extends ExtendCommand<EnumTypeExtensionNode>
*
* @internal This is an internal library class, please do not use it in your code.
* @psalm-internal Railt\SDL\Compiler\Command
*/
final class ExtendEnumTypeDefinitionCommand extends ExtendCommand
{
public function exec(): void
{
$type = $this->ctx->getType($this->stmt->name->value, $this->stmt->name);
if (!$type instanceof EnumType) {
$message = \vsprintf('Cannot extend %s by enum extension', [
(string)$type,
]);
throw CompilationException::create($message, $this->stmt->name);
}
$this->ctx->push(new BuildEnumTypeDefinitionCommand(
ctx: $this->ctx,
node: $this->stmt,
definition: $type,
));
}
}