4 * Decorator that, depending on a token, switches between two definitions.
6 class HTMLPurifier_AttrDef_Switch
15 * @type HTMLPurifier_AttrDef
20 * @type HTMLPurifier_AttrDef
22 protected $withoutTag;
25 * @param string $tag Tag name to switch upon
26 * @param HTMLPurifier_AttrDef $with_tag Call if token matches tag
27 * @param HTMLPurifier_AttrDef $without_tag Call if token doesn't match, or there is no token
29 public function __construct($tag, $with_tag, $without_tag)
32 $this->withTag
= $with_tag;
33 $this->withoutTag
= $without_tag;
37 * @param string $string
38 * @param HTMLPurifier_Config $config
39 * @param HTMLPurifier_Context $context
42 public function validate($string, $config, $context)
44 $token = $context->get('CurrentToken', true);
45 if (!$token ||
$token->name
!== $this->tag
) {
46 return $this->withoutTag
->validate($string, $config, $context);
48 return $this->withTag
->validate($string, $config, $context);