Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F7471996
StringLiteral.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
StringLiteral.php
View Options
<?php
/**
* This file is part of the Peast package
*
* (c) Marco Marchiò <marco.mm89@gmail.com>
*
* For the full copyright and license information refer to the LICENSE file
* distributed with this source code
*/
namespace
Peast\Syntax\Node
;
use
Peast\Syntax\Utils
;
/**
* A node that represents a string literal.
*
* @author Marco Marchiò <marco.mm89@gmail.com>
*/
class
StringLiteral
extends
Literal
{
/**
* Map of node properties
*
* @var array
*/
protected
$propertiesMap
=
array
(
"format"
=>
false
);
//Format constants
/**
* Double quoted string
*/
const
DOUBLE_QUOTED
=
"double"
;
/**
* Single quoted string
*/
const
SINGLE_QUOTED
=
"single"
;
/**
* String format
*
* @var string
*/
protected
$format
=
self
::
DOUBLE_QUOTED
;
/**
* Sets node's value
*
* @param string $value Value
*
* @return $this
*/
public
function
setValue
(
$value
)
{
$this
->
value
=
(
string
)
$value
;
//Force recalculation of the raw value
return
$this
->
setFormat
(
$this
->
format
);
}
/**
* Sets node's raw value
*
* @param mixed $raw Raw value
*
* @return $this
*
* @throws \Exception
*/
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
;
}
/**
* Returns string format
*
* @return string
*/
public
function
getFormat
()
{
return
$this
->
format
;
}
/**
* Sets string format
*
* @param string $format Format, one of the format constants
*
* @return $this
*/
public
function
setFormat
(
$format
)
{
$this
->
format
=
$format
;
$quote
=
$format
===
self
::
SINGLE_QUOTED
?
"'"
:
'"'
;
$this
->
raw
=
Utils
::
quoteLiteralString
(
$this
->
value
,
$quote
);
return
$this
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Mon, Nov 23, 08:21 (4 d, 47 m ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
1b/70/93b384b8b34d25bc9b97f716819d
Default Alt Text
StringLiteral.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment