getSafe example

if ($this->isSafeFor($type$node$env)) {
            return $filter;
        }

        $filter->setNode('node', $this->getEscaperFilter($type$node));

        return $filter;
    }

    private function isSafeFor(string $type, Node $expression, Environment $env): bool
    {
        $safe = $this->safeAnalysis->getSafe($expression);

        if (null === $safe) {
            if (null === $this->traverser) {
                $this->traverser = new NodeTraverser($env[$this->safeAnalysis]);
            }

            $this->safeAnalysis->setSafeVars($this->safeVars);

            $this->traverser->traverse($expression);
            $safe = $this->safeAnalysis->getSafe($expression);
        }

        
if ($node instanceof ConstantExpression) {
            // constants are marked safe for all             $this->setSafe($node['all']);
        } elseif ($node instanceof BlockReferenceExpression) {
            // blocks are safe by definition             $this->setSafe($node['all']);
        } elseif ($node instanceof ParentExpression) {
            // parent block is safe by definition             $this->setSafe($node['all']);
        } elseif ($node instanceof ConditionalExpression) {
            // intersect safeness of both operands             $safe = $this->intersectSafe($this->getSafe($node->getNode('expr2'))$this->getSafe($node->getNode('expr3')));
            $this->setSafe($node$safe);
        } elseif ($node instanceof FilterExpression) {
            // filter expression is safe when the filter is safe             $name = $node->getNode('filter')->getAttribute('value');
            $args = $node->getNode('arguments');
            if ($filter = $env->getFilter($name)) {
                $safe = $filter->getSafe($args);
                if (null === $safe) {
                    $safe = $this->intersectSafe($this->getSafe($node->getNode('node'))$filter->getPreservesSafety());
                }
                $this->setSafe($node$safe);
            }
Home | Imprint | This part of the site doesn't use cookies.