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:----i3Ujaso8/hAkNawpCbGoCye8L0RbhcdD85sVEn9FwnJGhpeeSmYbA/gl7FwFKtUAWdFCjAhiLG34ZWC4NkVgonXa2dwPrn+FpbtLR3gOmiBqAKdlmJBtFNaxiNlu4SgNzhkpqn4xJpz9XGOsIAU8kSl5Wi/wWc2iytmLeH+2bLJbGNU30coQhIdIRobqrxiWY45MEYjaeJ0IBA3wfONzQYQ1mqgAb2dgrNsg+sSe+DZXYBLCTPexJUK8QASsu/u4oTo4l/pqVULmHlIROX+Ce/fiI9EQy2nW7LIIkI2c1GuYPvEZudtxnb6jw6xW7KedN4oMugep4ZvaK8geq9SjRX2mRthn6OrHcCdWYSOUdpmn8EGOsP/00TIHkzkieomeDSJg2Qqx4VTVp3Frn4TCbwfZsOR32LVJTvuVqBXB1E3gOAm2zPnMKJz1GHj5LapymjOOgA/z31RuUIKhMjVLhpDxRGpezZRHY0vBadZU1c/kL/gp8vawrKuDy/uT5z5g4sSkFBdEJV4lRwUrCxcf+C8DNkeAS0qS0DRudd8iGGYdasXT6zridGP1LSSOHokUxTSr9GG0O+qZhjF46Pn6YukKHqv8B26L+GhaLcNV8+PTCTEnUhC7cqEwwenXZwY13vovcSKWbvPOA/PF+xnBw9jE4b/1+0oRp+FQzaNtcvo=----ATTACHMENT:----MzE1NzM4Mzg5ODE3NDIwMCAxMjg4NTc4NzY5MzMxNTA5IDk4NTEzOTYzMDI5NzU3MjY=