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