File indexing completed on 2024-05-12 06:02:04

0001 <?php
0002 
0003 /**
0004  * Decorator that, depending on a token, switches between two definitions.
0005  */
0006 class HTMLPurifier_AttrDef_Switch
0007 {
0008 
0009     /**
0010      * @type string
0011      */
0012     protected $tag;
0013 
0014     /**
0015      * @type HTMLPurifier_AttrDef
0016      */
0017     protected $withTag;
0018 
0019     /**
0020      * @type HTMLPurifier_AttrDef
0021      */
0022     protected $withoutTag;
0023 
0024     /**
0025      * @param string $tag Tag name to switch upon
0026      * @param HTMLPurifier_AttrDef $with_tag Call if token matches tag
0027      * @param HTMLPurifier_AttrDef $without_tag Call if token doesn't match, or there is no token
0028      */
0029     public function __construct($tag, $with_tag, $without_tag)
0030     {
0031         $this->tag = $tag;
0032         $this->withTag = $with_tag;
0033         $this->withoutTag = $without_tag;
0034     }
0035 
0036     /**
0037      * @param string $string
0038      * @param HTMLPurifier_Config $config
0039      * @param HTMLPurifier_Context $context
0040      * @return bool|string
0041      */
0042     public function validate($string, $config, $context)
0043     {
0044         $token = $context->get('CurrentToken', true);
0045         if (!$token || $token->name !== $this->tag) {
0046             return $this->withoutTag->validate($string, $config, $context);
0047         } else {
0048             return $this->withTag->validate($string, $config, $context);
0049         }
0050     }
0051 }
0052 
0053 // vim: et sw=4 sts=4