VariableName; } /** * @param mixed $variable * @throws InstructionException * @noinspection PhpMissingParamTypeInspection */ public function setVariableName($variable): void { $this->VariableName = InstructionBuilder::fromRaw($variable); } /** * @param Engine $engine * @return mixed * @throws EvaluationException * @throws NameException * @throws TypeException */ public function eval(Engine $engine): mixed { $variable = $engine->eval($this->VariableName); if(!is_string($variable)) throw new TypeException(sprintf('Expected string, got %s', Utilities::getType($variable, true))); return $engine->getEnvironment()->getRuntimeVariable($variable); } /** * Returns an array representation of the object * * @return array */ public function toArray(): array { return InstructionBuilder::toRaw(self::getType(), [ 'name' => $this->VariableName ]); } /** * Constructs a new GetVariable instruction from an array representation * * @param array $data * @return InstructionInterface * @throws InstructionException */ public static function fromArray(array $data): InstructionInterface { $instruction = new self(); $instruction->setVariableName($data['name'] ?? null); return $instruction; } /** * @inheritDoc */ public function __toString(): string { return sprintf( self::getType() . ' %s', Utilities::entityToString($this->VariableName) ); } }