function StringLiteral::setRaw
Sets node's raw value
Parameters
mixed $raw Raw value:
Return value
$this
Throws
\Exception
Overrides Literal::setRaw
File
-
vendor/
mck89/ peast/ lib/ Peast/ Syntax/ Node/ StringLiteral.php, line 71
Class
- StringLiteral
- A node that represents a string literal.
Namespace
Peast\Syntax\NodeCode
public function setRaw($raw) {
if (!is_string($raw) || strlen($raw) < 2) {
throw new \Exception("Invalid string");
}
$startQuote = $raw[0];
$endQuote = substr($raw, -1);
if ($startQuote !== "'" && $startQuote !== '"' || $startQuote !== $endQuote) {
throw new \Exception("Invalid string");
}
$this->value = Utils::unquoteLiteralString($raw);
$this->setFormat($raw[0] === "'" ? self::SINGLE_QUOTED : self::DOUBLE_QUOTED);
$this->raw = $raw;
return $this;
}