public function Twig_Compiler::repr in Zircon Profile 8
Same name and namespace in other branches
- 8.0 vendor/twig/twig/lib/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/ twig/ lib/ Twig/ Compiler.php, line 165
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;
}