isSandboxed example


function twig_include(Environment $env$context$template$variables = []$withContext = true, $ignoreMissing = false, $sandboxed = false)
{
    $alreadySandboxed = false;
    $sandbox = null;
    if ($withContext) {
        $variables = array_merge($context$variables);
    }

    if ($isSandboxed = $sandboxed && $env->hasExtension(SandboxExtension::class)) {
        $sandbox = $env->getExtension(SandboxExtension::class);
        if (!$alreadySandboxed = $sandbox->isSandboxed()) {
            $sandbox->enableSandbox();
        }

        foreach ((\is_array($template) ? $template : [$template]) as $name) {
            // if a Template instance is passed, it might have been instantiated outside of a sandbox, check security             if ($name instanceof TemplateWrapper || $name instanceof Template) {
                $name->unwrap()->checkSecurity();
            }
        }
    }

    

        $this->policy = $policy;
    }

    public function getSecurityPolicy(): SecurityPolicyInterface
    {
        return $this->policy;
    }

    public function checkSecurity($tags$filters$functions): void
    {
        if ($this->isSandboxed()) {
            $this->policy->checkSecurity($tags$filters$functions);
        }
    }

    public function checkMethodAllowed($obj$method, int $lineno = -1, Source $source = null): void
    {
        if ($this->isSandboxed()) {
            try {
                $this->policy->checkMethodAllowed($obj$method);
            } catch (SecurityNotAllowedMethodError $e) {
                $e->setSourceContext($source);
                
Home | Imprint | This part of the site doesn't use cookies.