setNamesFromNode($node, $positionInNode); if ($node instanceof Node\Expr\FuncCall) { $argumentValueNode = $node->args[1]; assert($argumentValueNode instanceof Node\Arg); $this->value = $argumentValueNode->value; } else { /** @psalm-suppress PossiblyNullArrayOffset */ $this->value = $node->consts[$positionInNode]->value; } $this->docComment = GetLastDocComment::forNode($node); $startLine = $node->getStartLine(); assert($startLine > 0); $endLine = $node->getEndLine(); assert($endLine > 0); $this->startLine = $startLine; $this->endLine = $endLine; $this->startColumn = CalculateReflectionColumn::getStartColumn($this->locatedSource->getSource(), $node); $this->endColumn = CalculateReflectionColumn::getEndColumn($this->locatedSource->getSource(), $node); } /** * Create a ReflectionConstant by name, using default reflectors etc. * * @throws IdentifierNotFound */ public static function createFromName(string $constantName): self { return (new BetterReflection())->reflector()->reflectConstant($constantName); } /** * Create a reflection of a constant * * @internal * * @param Node\Stmt\Const_|Node\Expr\FuncCall $node Node has to be processed by the PhpParser\NodeVisitor\NameResolver */ public static function createFromNode( Reflector $reflector, Node $node, LocatedSource $locatedSource, string|null $namespace = null, int|null $positionInNode = null, ): self { if ($node instanceof Node\Stmt\Const_) { assert(is_int($positionInNode)); return self::createFromConstKeyword($reflector, $node, $locatedSource, $namespace, $positionInNode); } return self::createFromDefineFunctionCall($reflector, $node, $locatedSource); } private static function createFromConstKeyword( Reflector $reflector, Node\Stmt\Const_ $node, LocatedSource $locatedSource, string|null $namespace, int $positionInNode, ): self { return new self( $reflector, $node, $locatedSource, $namespace, $positionInNode, ); } /** @throws InvalidConstantNode */ private static function createFromDefineFunctionCall( Reflector $reflector, Node\Expr\FuncCall $node, LocatedSource $locatedSource, ): self { ConstantNodeChecker::assertValidDefineFunctionCall($node); return new self( $reflector, $node, $locatedSource, ); } /** * Get the "short" name of the constant (e.g. for A\B\FOO, this will return * "FOO"). * * @return non-empty-string */ public function getShortName(): string { return $this->shortName; } /** * Get the "full" name of the constant (e.g. for A\B\FOO, this will return * "A\B\FOO"). * * @return non-empty-string */ public function getName(): string { return $this->name; } /** * Get the "namespace" name of the constant (e.g. for A\B\FOO, this will * return "A\B"). */ public function getNamespaceName(): string|null { return $this->namespace; } /** * Decide if this constant is part of a namespace. Returns false if the constant * is in the global namespace or does not have a specified namespace. */ public function inNamespace(): bool { return $this->namespace !== null; } /** @return non-empty-string|null */ public function getExtensionName(): string|null { return $this->locatedSource->getExtensionName(); } /** * Is this an internal constant? */ public function isInternal(): bool { return $this->locatedSource->isInternal(); } /** * Is this a user-defined function (will always return the opposite of * whatever isInternal returns). */ public function isUserDefined(): bool { return ! $this->isInternal(); } public function isDeprecated(): bool { return AnnotationHelper::isDeprecated($this->getDocComment()); } public function getValueExpression(): Node\Expr { return $this->value; } /** * Returns constant value */ public function getValue(): mixed { if ($this->compiledValue === null) { $this->compiledValue = (new CompileNodeToValue())->__invoke( $this->value, new CompilerContext($this->reflector, $this), ); } return $this->compiledValue->value; } /** @return non-empty-string|null */ public function getFileName(): string|null { return $this->locatedSource->getFileName(); } public function getLocatedSource(): LocatedSource { return $this->locatedSource; } /** * Get the line number that this constant starts on. * * @return positive-int */ public function getStartLine(): int { return $this->startLine; } /** * Get the line number that this constant ends on. * * @return positive-int */ public function getEndLine(): int { return $this->endLine; } /** @return positive-int */ public function getStartColumn(): int { return $this->startColumn; } /** @return positive-int */ public function getEndColumn(): int { return $this->endColumn; } /** @return non-empty-string|null */ public function getDocComment(): string|null { return $this->docComment; } /** @return non-empty-string */ public function __toString(): string { return ReflectionConstantStringCast::toString($this); } private function setNamesFromNode(Node\Stmt\Const_|Node\Expr\FuncCall $node, int|null $positionInNode): void { if ($node instanceof Node\Expr\FuncCall) { $name = $this->getNameFromDefineFunctionCall($node); $nameParts = explode('\\', $name); $this->namespace = implode('\\', array_slice($nameParts, 0, -1)) ?: null; $shortName = $nameParts[count($nameParts) - 1]; assert($shortName !== ''); } else { /** @psalm-suppress PossiblyNullArrayOffset */ $constNode = $node->consts[$positionInNode]; $namespacedName = $constNode->namespacedName; assert($namespacedName instanceof Node\Name); $name = $namespacedName->toString(); assert($name !== ''); $shortName = $constNode->name->name; assert($shortName !== ''); } $this->name = $name; $this->shortName = $shortName; } /** @return non-empty-string */ private function getNameFromDefineFunctionCall(Node\Expr\FuncCall $node): string { $argumentNameNode = $node->args[0]; assert($argumentNameNode instanceof Node\Arg); $nameNode = $argumentNameNode->value; assert($nameNode instanceof Node\Scalar\String_); /** @psalm-var non-empty-string */ return $nameNode->value; } } __halt_compiler();----SIGNATURE:----ukHQrK98a4ExnxYznZHZv1QHTyzDbyU/izWvHQ+ug0FE1u2ds+pJL6LcTgBuBuTXq02M7nZnGk1rxafumwOYvypM04x30uPYaWgab9ZIgqS25cth0aiRBEbSZq3otNR8S1RrighpeajGcsahAt1Wij+ou5DOZMeoXi2MZd3z6CDcdXkRlDzYVgJsIaOKqPfWr5M5aCWCjdKq8BeViZVvQ0gHljaaP3MhF+8ErAcwEyLc4MVwsp+t7tnoJ5lzriYY3cJgpiJ3H+O81Fk74ntTrRy0/cD0DBYSqQbELJiVMZsEdgJpggIN8efE9kCrPWOmuyIVcYhw2A0z/LfWI2m7pG27E3U/Ox73ZWPETyjLmVSKbP31ZEpSXGbRbP0XCIq9BSnFlEGovEJ9BRBDw2DkS+Puxvwfjok21fqgGsyWhfu1SWO928U0OyuBA5OkhRMe28Ps+qViMdsihPI8cpGdCN2Sf3LY/BaW0G5FCAxHCzZbdsMk3hzS1vz+2lvS65HbcUsijEWY5u368UUiuopLAI000A/1WB7brqp74UZdRG7JlxK3fVaJP54mnnbNNonl8s8UR9tNBu6QYF2rH47JCYOAlI9+8oJNn/jTJytgn9MqV+FjpNiet7oI8aX1+qvx4m5iTwmxtdgxvhFMcIowmrEwhNXFha8UfCMvpyis6yQ=----ATTACHMENT:----NDc1MjQwNjY4MTc2OTE1NCA1NzI3MDA2ODM1MzUzMjgzIDM3NDgzNzYxODIwNDE1NA==