public function Twig_Compiler::repr in Translation template extractor 6.3
Same name and namespace in other branches
- 7.3 vendor/Twig/Compiler.php \Twig_Compiler::repr()
Returns a PHP representation of a given value.
Parameters
mixed $value The value to convert:
Return value
Twig_Compiler The current compiler instance
File
- vendor/
Twig/ Compiler.php, line 166
Class
- Twig_Compiler
- Compiles a node to PHP code.
Code
public function repr($value) {
if (is_int($value) || is_float($value)) {
if (false !== ($locale = setlocale(LC_NUMERIC, 0))) {
setlocale(LC_NUMERIC, 'C');
}
$this
->raw($value);
if (false !== $locale) {
setlocale(LC_NUMERIC, $locale);
}
}
elseif (null === $value) {
$this
->raw('null');
}
elseif (is_bool($value)) {
$this
->raw($value ? 'true' : 'false');
}
elseif (is_array($value)) {
$this
->raw('array(');
$first = true;
foreach ($value as $key => $v) {
if (!$first) {
$this
->raw(', ');
}
$first = false;
$this
->repr($key);
$this
->raw(' => ');
$this
->repr($v);
}
$this
->raw(')');
}
else {
$this
->string($value);
}
return $this;
}