示例#1
0
 /**
  * Called before child nodes are visited.
  *
  * @param IfwPsn_Vendor_Twig_NodeInterface $node The node to visit
  * @param IfwPsn_Vendor_Twig_Environment   $env  The Twig environment instance
  *
  * @return IfwPsn_Vendor_Twig_NodeInterface The modified node
  */
 public function enterNode(IfwPsn_Vendor_Twig_NodeInterface $node, IfwPsn_Vendor_Twig_Environment $env)
 {
     if ($node instanceof IfwPsn_Vendor_Twig_Node_Module) {
         if ($env->hasExtension('escaper') && ($defaultStrategy = $env->getExtension('escaper')->getDefaultStrategy($node->getAttribute('filename')))) {
             $this->defaultStrategy = $defaultStrategy;
         }
         $this->safeVars = array();
     } elseif ($node instanceof IfwPsn_Vendor_Twig_Node_AutoEscape) {
         $this->statusStack[] = $node->getAttribute('value');
     } elseif ($node instanceof IfwPsn_Vendor_Twig_Node_Block) {
         $this->statusStack[] = isset($this->blocks[$node->getAttribute('name')]) ? $this->blocks[$node->getAttribute('name')] : $this->needEscaping($env);
     } elseif ($node instanceof IfwPsn_Vendor_Twig_Node_Import) {
         $this->safeVars[] = $node->getNode('var')->getAttribute('name');
     }
     return $node;
 }
示例#2
0
文件: Core.php 项目: jasmun/Noco100
/**
 * Renders a template.
 *
 * @param string|array $template       The template to render or an array of templates to try consecutively
 * @param array        $variables      The variables to pass to the template
 * @param Boolean      $with_context   Whether to pass the current context variables or not
 * @param Boolean      $ignore_missing Whether to ignore missing templates or not
 * @param Boolean      $sandboxed      Whether to sandbox the template or not
 *
 * @return string The rendered template
 */
function ifwpsn_twig_include(IfwPsn_Vendor_Twig_Environment $env, $context, $template, $variables = array(), $withContext = true, $ignoreMissing = false, $sandboxed = false)
{
    $alreadySandboxed = false;
    $sandbox = null;
    if ($withContext) {
        $variables = array_merge($context, $variables);
    }
    if ($isSandboxed = $sandboxed && $env->hasExtension('sandbox')) {
        $sandbox = $env->getExtension('sandbox');
        if (!($alreadySandboxed = $sandbox->isSandboxed())) {
            $sandbox->enableSandbox();
        }
    }
    try {
        return $env->resolveTemplate($template)->render($variables);
    } catch (IfwPsn_Vendor_Twig_Error_Loader $e) {
        if (!$ignoreMissing) {
            throw $e;
        }
    }
    if ($isSandboxed && !$alreadySandboxed) {
        $sandbox->disableSandbox();
    }
}