You are here

public function Twig_Template::getSource in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/twig/twig/lib/Twig/Template.php \Twig_Template::getSource()

Returns the template source code.

Return value

string|null The template source code or null if it is not available

File

vendor/twig/twig/lib/Twig/Template.php, line 328

Class

Twig_Template
Default base class for compiled templates.

Code

public function getSource() {
  $reflector = new ReflectionClass($this);
  $file = $reflector
    ->getFileName();
  if (!file_exists($file)) {
    return;
  }
  $source = file($file, FILE_IGNORE_NEW_LINES);
  array_splice($source, 0, $reflector
    ->getEndLine());
  $i = 0;
  while (isset($source[$i]) && '/* */' === substr_replace($source[$i], '', 3, -2)) {
    $source[$i] = str_replace('*//* ', '*/', substr($source[$i], 3, -2));
    ++$i;
  }
  array_splice($source, $i);
  return implode("\n", $source);
}