Debian Codegraph @

vendor/mck89/peast/lib/Peast/Syntax/Node/Identifier.php

raw
1 <?php
2 /**
3 * This file is part of the Peast package
4 *
5 * (c) Marco Marchiò <[email protected]>
6 *
7 * For the full copyright and license information refer to the LICENSE file
8 * distributed with this source code
9 */
10 namespace Peast\Syntax\Node;
11
12 use Peast\Syntax\Utils;
13
14 /**
15 * A node that represents an identifier.
16 *
17 * @author Marco Marchiò <[email protected]>
18 */
19 class Identifier extends Node implements Expression, Pattern
20 {
21 /**
22 * Map of node properties
23 *
24 * @var array
25 */
26 protected $propertiesMap = array(
27 "name" => false,
28 "rawName" => false,
29 );
30
31 /**
32 * The identifier's name
33 *
34 * @var string
35 */
36 protected $name;
37
38 /**
39 * The identifier's raw name
40 *
41 * @var string
42 */
43 protected $rawName;
44
45 /**
46 * Returns the identifier's name
47 *
48 * @return string
49 */
50 public function getName()
51 {
52 return $this->name;
53 }
54
55 /**
56 * Sets the identifier's name
57 *
58 * @param string $name The name to set
59 *
60 * @return $this
61 */
62 public function setName($name)
63 {
64 $this->name = $this->rawName = $name;
65 return $this;
66 }
67
68 /**
69 * Returns the identifier's raw name
70 *
71 * @return string
72 */
73 public function getRawName()
74 {
75 return $this->rawName;
76 }
77
78 /**
79 * Sets the identifier's raw name
80 *
81 * @param string $name The raw name to set
82 *
83 * @return $this
84 */
85 public function setRawName($name)
86 {
87 $this->rawName = $name;
88 if (strpos($name, "\\") !== false) {
89 $this->name = preg_replace_callback(
90 "#\\\\u(?:\{([a-fA-F0-9]+)\}|([a-fA-F0-9]{4}))#",
91 function ($match) {
92 return Utils::unicodeToUtf8(hexdec($match[1] ? : $match[2]));
93 },
94 $name
95 );
96 } else {
97 $this->name = $name;
98 }
99 return $this;
100 }
101 }