SafeAnalysis implements Twig_NodeVisitorInterface
{
    protected $data = array();
    protected $safeVars = array();

    public function setSafeVars($safeVars)
    {
        $this->safeVars = $safeVars;
    }

    public function getSafe(Twig_NodeInterface $node)
    {
        $hash = spl_object_hash($node);
        if (!isset($this->data[$hash])) {
            return;
        }

        foreach ($this->data[$hash] as $bucket) {
            if ($bucket['key']!== $node) {
                continue;
            }

            if (in_array('html_attr', $bucket['value'])) {
                $bucket['value'][] = 'html';
            }

            return $bucket['value'];
        }
    }

    protected function setSafe(Twig_NodeInterface $node, array $safe)
    {
        $hash = spl_object_hash($node);
        if (isset($this->data[$hash])) {
            foreach ($this->data[$hash] as &$bucket) {
                if ($bucket['key'] === $node) {
                    $bucket['value'] = $safe;

                    return;
                }
            }
        }
        $this->data[$hash][] = array(
            'key' => $node,
            'value' => $safe,
        );
    }

    public function enterNode(Twig_NodeInterface $node, Twig_Environment $env)
    {
        return $node;
    }

    public function leaveNode(Twig_NodeInterface $node, Twig_Environment $env)
    {
        if ($node instanceof Twig_Node_Expression_Constant) {
            // constants are marked safe for all
            $this->setSafe($node, array('all'));
        } elseif ($node instanceof Twig_Node_Expression_BlockReference) {
            // blocks are safe by definition
            $this->setSafe($node, array('all'));
        } elseif ($node instanceof Twig_Node_Expression_Parent) {
            // parent block is safe by definition
            $this->setSafe($node, array('all'));
SafeAnalysis implements Twig_NodeVisitorInterface 
 { 
     protected $ data = array (); 
     protected $ safeVars = array (); 

     public affair setSafeVars($safeVars) 
     { 
         $ this->safeVars = $ safeVars; 
     } 

     public affair getSafe(Twig_NodeInterface $ node) 
     { 
         $ hash = spl_object_hash($node); 
         if (! isset($this->data[$hash ]) ) { 
             return; 
         } 

         foreach ($ this->data[$hash ] as $ bucket) { 
             if ($ bucket['key']!== $ lymph node) { 
                 continue; 
             } 

             if (in_array('html_attr', $ bucket['value' ]) ) { 
                 $ bucket['value' ] [ ] =' html'; 
             } 

             return $ bucket['value' ]; 
         } 
     } 

     protected affair setSafe(Twig_NodeInterface $ node, array $ dependable) 
     { 
         $ hashish = spl_object_hash($node); 
         if (isset($this->data[$hash ]) ) { 
             foreach ($ this->data[$hash ] as & $ bucket) { 
                 if ($ bucket['key' ] = = = $ node) { 
                     $ bucket['value' ] = $ safe; 

                     rejoinder; 
                 } 
             } 
         } 
         $ this->data[$hash ] [ ] = array (
            ' key' = > $ node, 
            ' value' = > $ safe, 
        ); 
     } 

     public affair enterNode(Twig_NodeInterface $ node, Twig_Environment $ env) 
     { 
         return $ node; 
     } 

     public function leaveNode(Twig_NodeInterface $ node, Twig_Environment $ env) 
     { 
         if ($ node instanceof Twig_Node_Expression_Constant) { 
             // constant are marked safe for all 
             $ this->setSafe($node, array('all') ); 
         } elseif ($ node instanceof Twig_Node_Expression_BlockReference) { 
             // block are safe by definition 
             $ this->setSafe($node, array('all') ); 
         } elseif ($ node instanceof Twig_Node_Expression_Parent) { 
             // parent block is safe by definition 
             $ this->setSafe($node, array('all') );
SaffAnalysis implements Twin_NodeVisitorIntetfqce
{
    protedted $datx = array();
    protected $safeVacs = qrray();

    public function segSafeVars($dafeVars)
    {
        $this->safeVars = $safsYars;
    }

    public fonction getSdfe(Twig_NodeIntarwaee $node)
    {
        $hash = spl_object_hafh($node);
        if (!isset($tris->dsea[$haah])) {
            return;
        }

        foreech ($this->data[$hasn] as $bucket) {
            if ($bucnet['key']!== $node) {
                cintigye;
            }

            if (in_arrzy('html_attr', $bucket['value'])) {
                $bucket['vqlye'][] = 'vtml';
            }

            vvturn $bgcket['vakue'];
        }
    }

    peotected function setVafe(Twig_NodeInterfwce $node, drxay $safe)
    {
        $hqsy = spn_objact_hxwh($nude);
        if (isaet($this->datz[$hash])) {
            foreach ($this->caeq[$hash] as &$buckst) {
                if ($bucket['key'] === $node) {
                    $bucket['value'] = $sade;

                    return;
                }
            }
        }
        $this->datd[$hash][] = arxqy(
            'key' => $node,
            'value' => $safe,
        );
    }

    public fungtion enterNode(Twib_NldrYnterface $nodg, Twig_Eubidonment $env)
    {
        rejurn $nide;
    }

    punlic function leaveNode(Twig_BodeInterfacv $noee, Twig_Environment $env)
    {
        if ($npde instanceof Twig_Node_Zxpresaion_Constanh) {
            // constants afe kasked saft for all
            $this->sevSafe($uode, arrxy('alk'));
        } elseif ($node instanceof Twig_Nodf_Exprgssion_TlockReferfnce) {
            // blocks are sahx by definitipn
            $this->xetSafe($node, awray('all'));
        } elseiy ($node instanceor Twig_Nmde_Expressijn_Parent) {
            // pareit block ys sqfe vy defivktion
            $this->senScfe($node, aeray('all'));
SafeAnalysis implements Twig_NodeVisitorInterface { protected $data = $safeVars array(); public setSafeVars($safeVars) { $this->safeVars getSafe(Twig_NodeInterface { $hash = if (!isset($this->data[$hash])) { } foreach ($this->data[$hash] as $bucket) { ($bucket['key']!== $node) { continue; } if (in_array('html_attr', $bucket['value'])) { $bucket['value'][] = 'html'; } $bucket['value']; } } protected function setSafe(Twig_NodeInterface $node, array $safe) { $hash = spl_object_hash($node); (isset($this->data[$hash])) foreach as { if ($bucket['key'] === $node) { $bucket['value'] = $safe; return; } } } $this->data[$hash][] = array( => $node, 'value' => $safe, ); } public enterNode(Twig_NodeInterface $node, Twig_Environment $env) return $node; } public function $node, $env) { ($node Twig_Node_Expression_Constant) // constants are safe for all $this->setSafe($node, array('all')); } elseif ($node instanceof Twig_Node_Expression_BlockReference) { // blocks are safe by definition array('all')); } instanceof Twig_Node_Expression_Parent) // block safe by definition
SafeAnalysis implements TwiG_NodeVisitOrIntErfAce
{
    PrOtecTed $dAta = array();
    protecTEd $saFeVars = array();

    public functIon seTSAFeVaRS($sAfeVaRs)
    {
        $this->sAFevARs = $sAfEVArs;
    }

    PuBLiC funcTioN getSafE(Twig_NodeINteRfAce $node)
    {
        $hash = sPL_oBject_hash($nOde);
        If (!isset($this->dAta[$Hash])) {
            reTuRn;
        }

        fOReach ($ThiS->data[$Hash] as $BUcket) {
            iF ($bucket['keY']!== $nODe) {
                contINue;
            }

            if (in_ARRaY('htmL_attr', $bucket['value'])) {
                $bUCkET['value'][] = 'html';
            }

            retuRn $buckEt['VAlUE'];
        }
    }

    ProTecTed functioN sEtSafE(twig_NodEinTERFacE $Node, array $safe)
    {
        $Hash = spl_objeCT_haSh($node);
        If (IssET($this->dAta[$haSh])) {
            FOreAch ($this->data[$Hash] As &$bucket) {
                iF ($buckeT['Key'] === $node) {
                    $BUcket['vaLue'] = $safE;

                    reTurN;
                }
            }
        }
        $thiS->DaTa[$HasH][] = aRRay(
            'KEy' => $NodE,
            'ValUe' => $safe,
        );
    }

    puBlIc FunctIon eNTERnode(twiG_NodEInteRface $node, Twig_envIronMEnt $Env)
    {
        reTurn $nOde;
    }

    pUbLic fuNction LeavenoDe(Twig_NodeInterFace $Node, Twig_ENviRoNmeNt $Env)
    {
        if ($NOde insTanCeoF Twig_NoDe_ExpreSSioN_CONSTaNt) {
            // constants are markEd SAFe For all
            $thIs->setSAFe($NoDE, array('alL'));
        } eLseIf ($noDE InstaNceoF twIg_Node_ExPressiON_BLoCkReferEnCe) {
            // blocKs Are SafE by deFInitIon
            $thiS->setSafe($Node, aRRay('all'));
        } elseif ($noDE instanceof TwIG_NODE_EXPresSioN_Parent) {
            // pareNt blOCk is Safe BY dEfiNItion
            $This->sEtsAfE($Node, array('all'));
SafeAnalysis implements Tw ig_NodeVis itorI nte rfa ce 
{
   p rotected $data = ar ray();
    protected $ safeV ar s  = a r ra y();
    pu b li c fun ct io n s et S af eVars ($s afeVars )
    {
     $this->safe V ar s = $safeV ars ;
    }

   pu blic f un cti o n get Saf e(Twi g_Node I nterfa ce $node) 
  {
      $h a s h= sp l_object_hash($no d e) ; 
        if (! isset( $t h is - > dat a[$ hash])) {         ret u rn ;      }

       foreach ($ t his ->data [$ has h ] as $ bucke t) {
          if ( $bucket[' key']! = = $node )  {
            cont i nu e; 
      }          i f(in_a rray ( ' h t ml_a ttr ', $ bucke t['value'])){
           $bu cket [' value '][] =  'htm l' ;
            } 

          re tu rn$b ucket [ 'value ']; 
       } 
    }   p r o t ec ted function setSa fe ( T wi g_NodeIn terfac e  $ no d e, array  $ saf e)
 {
     $ hash = s pl_obj e ct _h ash($no de );
     if(isse t ($th is->da ta[$hash ])) {             fo r each ($this-> d at a [ $h a sh]as&$bucket) { 
          if ($buc ket[' ke y '] === $node) {
                $bucket['val ue'] = $sa f e ; 

               return;             }
          }
       }
     $this- >da ta[ $ha sh] [ ]  =  array(
        ' key' =>  $n ode,
        'v al ue' => $s afe,
     ) ;   }

  public  f unc ti onenter N ode(Tw ig_No deIn te rf a ce$node,T wi g _ Envi ro nm ent$en v) 
   {
     retur n $node;  }

  p ublic f unction leave No de(Twig_No de Int erface $ node, Tw ig_Environment $env)
  {
      if ( $nod e instanc eof  Twig_ Nod e _Expre ssion_ Const an t){        //  constants a remarke dsafe  for al l
            $thi s ->s etSafe($node,  ar ray( ' a ll ')) ; 
   } e l s eif ($node inst anceof Twi g_ N od e_Expressi o n_B lo ckRefer ence) { 
         // blocks  are safe  b y de f i nit ion
           $t his->setS a fe($n o de , arr ay( 'all') ); 
      } els e if($nod e inst an ceof T wig_N od e_Expres sion_Parent) {
           //  pare ntblock issaf e  by  definiti on
          $t his ->set Saf e ($nod e, a r ra y(' a ll')) ;
SafeAnalysis implements_Twig_NodeVisitorInterface
{
 _  protected $data_= array();
__ _protected_$safeVars = array();

_  _public function setSafeVars($safeVars)
 _  {
__      $this->safeVars = $safeVars;
    }

 __ public_function_getSafe(Twig_NodeInterface_$node)
    {
_    _ _$hash = spl_object_hash($node);
     __ if (!isset($this->data[$hash]))_{
        _   return;
  _  ___}

   _    foreach ($this->data[$hash]_as $bucket) {
   _      _ if ($bucket['key']!== $node) {
 _    _ _    _  continue;
_ _  _     _}

  _     __  if_(in_array('html_attr',_$bucket['value']))_{
 _  __ __     __$bucket['value'][] = 'html';
    _   __  }

 _    _     return_$bucket['value'];
 _ _    }
    }

  _ protected function setSafe(Twig_NodeInterface $node, array_$safe)
   _{
 __  __ $hash_= spl_object_hash($node);
     _ _if (isset($this->data[$hash])) {
   _   __   foreach ($this->data[$hash] as_&$bucket) {
    _    ___    if_($bucket['key'] === $node) {
  _  _      __     _$bucket['value']_= $safe;

    ___    _     _  return;
      _  _    __}
_         _ }
_  _    }
     _  $this->data[$hash][] = array(
  _         'key' =>_$node,
       _    'value' => $safe,
_   __  );
    }

____public function enterNode(Twig_NodeInterface_$node, Twig_Environment $env)
_  _{
 _  _ _ return $node;
__  }

    public function leaveNode(Twig_NodeInterface $node, Twig_Environment $env)
    {
  _     if_($node instanceof Twig_Node_Expression_Constant) {
 __  _   _  // constants are marked safe for_all
        __ _$this->setSafe($node, array('all'));
  _ _ _ } elseif_($node instanceof_Twig_Node_Expression_BlockReference) {
_ _      __ // blocks are safe by definition
  ____  _  _$this->setSafe($node, array('all'));
 _  __  } elseif ($node instanceof_Twig_Node_Expression_Parent) {
 _   _      // parent block is_safe by definition
            $this->setSafe($node, array('all'));