Example #1
0
 /**
  * Compiles the node to PHP.
  *
  * @param \Twig_Compiler A Twig_Compiler instance
  */
 public function compile(\Twig_Compiler $compiler)
 {
     $compiler->addDebugInfo($this);
     $config = $this->environment->get_src_config();
     $compiler->write("\$asset_file = ")->subcompile($this->getNode('expr'))->raw(";\n")->write("\$asset = new \\src\\template\\asset(\$asset_file, \$this->getEnvironment()->get_path_helper());\n")->write("if (substr(\$asset_file, 0, 2) !== './' && \$asset->is_relative()) {\n")->indent()->write("\$asset_path = \$asset->get_path();")->write("\$local_file = \$this->getEnvironment()->get_src_root_path() . \$asset_path;\n")->write("if (!file_exists(\$local_file)) {\n")->indent()->write("\$local_file = \$this->getEnvironment()->findTemplate(\$asset_path);\n")->write("\$asset->set_path(\$local_file, true);\n")->outdent()->write("\$asset->add_assets_version('{$config['assets_version']}');\n")->write("\$asset_file = \$asset->get_url();\n")->write("}\n")->outdent()->write("}\n")->write("\$context['definition']->append('{$this->get_definition_name()}', '");
     $this->append_asset($compiler);
     $compiler->raw("\n');\n");
 }
Example #2
0
 /**
  * Compiles the node to PHP.
  *
  * @param \Twig_Compiler A Twig_Compiler instance
  */
 public function compile(\Twig_Compiler $compiler)
 {
     $compiler->addDebugInfo($this);
     $config = $this->environment->get_src_config();
     if (!$config['tpl_allow_php']) {
         $compiler->write("// PHP Disabled\n");
         return;
     }
     $compiler->raw($this->getNode('text')->getAttribute('data'));
 }
Example #3
0
 /**
  * Compiles the node to PHP.
  *
  * @param \Twig_Compiler A Twig_Compiler instance
  */
 public function compile(\Twig_Compiler $compiler)
 {
     $compiler->addDebugInfo($this);
     $config = $this->environment->get_src_config();
     if (!$config['tpl_allow_php']) {
         $compiler->write("// INCLUDEPHP Disabled\n");
         return;
     }
     if ($this->getAttribute('ignore_missing')) {
         $compiler->write("try {\n")->indent();
     }
     $compiler->write("\$location = ")->subcompile($this->getNode('expr'))->raw(";\n")->write("if (src_is_absolute(\$location)) {\n")->indent()->write("require(\$location);\n")->outdent()->write("} else if (file_exists(\$this->getEnvironment()->get_src_root_path() . \$location)) {\n")->indent()->write("require(\$this->getEnvironment()->get_src_root_path() . \$location);\n")->outdent()->write("} else {\n")->indent()->write("require(\$this->getEnvironment()->getLoader()->getCacheKey(\$location));\n")->outdent()->write("}\n");
     if ($this->getAttribute('ignore_missing')) {
         $compiler->outdent()->write("} catch (\\Twig_Error_Loader \$e) {\n")->indent()->write("// ignore missing template\n")->outdent()->write("}\n\n");
     }
 }