You are here

public function Twig_Template::getSource in Translation template extractor 7.3

Returns the template source code.

Return value

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

File

vendor/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);
}