You are here

public function Twig_Environment::compileSource in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/twig/twig/lib/Twig/Environment.php \Twig_Environment::compileSource()

Compiles a template source code.

Parameters

string $source The template source code:

string $name The template name:

Return value

string The compiled PHP source code

Throws

Twig_Error_Syntax When there was an error during tokenizing, parsing or compiling

1 call to Twig_Environment::compileSource()
Twig_Environment::loadTemplate in vendor/twig/twig/lib/Twig/Environment.php
Loads a template by name.

File

vendor/twig/twig/lib/Twig/Environment.php, line 664

Class

Twig_Environment
Stores the Twig configuration.

Code

public function compileSource($source, $name = null) {
  try {
    $compiled = $this
      ->compile($this
      ->parse($this
      ->tokenize($source, $name)), $source);
    if (isset($source[0])) {
      $compiled .= '/* ' . str_replace(array(
        '*/',
        "\r\n",
        "\r",
        "\n",
      ), array(
        '*//* ',
        "\n",
        "\n",
        "*/\n/* ",
      ), $source) . "*/\n";
    }
    return $compiled;
  } catch (Twig_Error $e) {
    $e
      ->setTemplateFile($name);
    throw $e;
  } catch (Exception $e) {
    throw new Twig_Error_Syntax(sprintf('An exception has been thrown during the compilation of a template ("%s").', $e
      ->getMessage()), -1, $name, $e);
  }
}