public function 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

drupal/core/vendor/twig/twig/lib/Twig/Compiler.php, line 155

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(');
    $i = 0;
    foreach ($value as $key => $value) {
      if ($i++) {
        $this
          ->raw(', ');
      }
      $this
        ->repr($key);
      $this
        ->raw(' => ');
      $this
        ->repr($value);
    }
    $this
      ->raw(')');
  }
  else {
    $this
      ->string($value);
  }
  return $this;
}