Debian Codegraph @

vendor/mck89/peast/lib/Peast/Syntax/Node/TemplateElement.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 a template element.
16 * For example `foo` and `bar` in: `foo${exp}bar`
17 *
18 * @author Marco Marchiò <[email protected]>
19 */
20 class TemplateElement extends Node
21 {
22 /**
23 * Map of node properties
24 *
25 * @var array
26 */
27 protected $propertiesMap = array(
28 "value" => false,
29 "tail" => false,
30 "rawValue" => false
31 );
32
33 /**
34 * Node's value
35 *
36 * @var string
37 */
38 protected $value;
39
40 /**
41 * Tail flag that is true when the element is the tail element in a template
42 *
43 * @var bool
44 */
45 protected $tail = false;
46
47 /**
48 * Node's raw value
49 *
50 * @var string
51 */
52 protected $rawValue;
53
54 /**
55 * Return node's value
56 *
57 * @return string
58 */
59 public function getValue()
60 {
61 return $this->value;
62 }
63
64 /**
65 * Sets node's value
66 *
67 * @param mixed $value Value
68 *
69 * @return $this
70 */
71 public function setValue($value)
72 {
73 $this->value = $value;
74 $this->rawValue = Utils::quoteLiteralString($value, "`");
75 return $this;
76 }
77
78 /**
79 * Returns the tail flag that is true when the element is the tail element
80 * in a template
81 *
82 * @return bool
83 */
84 public function getTail()
85 {
86 return $this->tail;
87 }
88
89 /**
90 * Sets the tail flag that is true when the element is the tail element
91 * in a template
92 *
93 * @param bool $tail Tail flag
94 *
95 * @return $this
96 */
97 public function setTail($tail)
98 {
99 $this->tail = (bool) $tail;
100 return $this;
101 }
102
103 /**
104 * Returns node's raw value
105 *
106 * @return string
107 */
108 public function getRawValue()
109 {
110 return $this->rawValue;
111 }
112
113 /**
114 * Sets node's raw value that must be wrapped in templates quotes.
115 *
116 * @param string $rawValue Raw value
117 *
118 * @return $this
119 */
120 public function setRawValue($rawValue)
121 {
122 $rawValue = preg_replace("#^[`}]|(?:`|\\\$\{)$#", "", $rawValue);
123 $this->setValue(Utils::unquoteLiteralString("`$rawValue`"));
124 $this->rawValue = $rawValue;
125 return $this;
126 }
127 }