You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
1.7 KiB

3 years ago
  1. <?php declare(strict_types=1);
  2. namespace PhpParser\Node;
  3. use PhpParser\NodeAbstract;
  4. /**
  5. * Represents a non-namespaced name. Namespaced names are represented using Name nodes.
  6. */
  7. class Identifier extends NodeAbstract
  8. {
  9. /** @var string Identifier as string */
  10. public $name;
  11. private static $specialClassNames = [
  12. 'self' => true,
  13. 'parent' => true,
  14. 'static' => true,
  15. ];
  16. /**
  17. * Constructs an identifier node.
  18. *
  19. * @param string $name Identifier as string
  20. * @param array $attributes Additional attributes
  21. */
  22. public function __construct(string $name, array $attributes = []) {
  23. $this->attributes = $attributes;
  24. $this->name = $name;
  25. }
  26. public function getSubNodeNames() : array {
  27. return ['name'];
  28. }
  29. /**
  30. * Get identifier as string.
  31. *
  32. * @return string Identifier as string.
  33. */
  34. public function toString() : string {
  35. return $this->name;
  36. }
  37. /**
  38. * Get lowercased identifier as string.
  39. *
  40. * @return string Lowercased identifier as string
  41. */
  42. public function toLowerString() : string {
  43. return strtolower($this->name);
  44. }
  45. /**
  46. * Checks whether the identifier is a special class name (self, parent or static).
  47. *
  48. * @return bool Whether identifier is a special class name
  49. */
  50. public function isSpecialClassName() : bool {
  51. return isset(self::$specialClassNames[strtolower($this->name)]);
  52. }
  53. /**
  54. * Get identifier as string.
  55. *
  56. * @return string Identifier as string
  57. */
  58. public function __toString() : string {
  59. return $this->name;
  60. }
  61. public function getType() : string {
  62. return 'Identifier';
  63. }
  64. }