Fix two minor bugs, updating Phorum and removing unused $dir variable.
[htmlpurifier/darkodev.git] / library / HTMLPurifier / AttrDef / Switch.php
blobc9e3ed193e77d0cbeac150d02105b81173eb37c0
1 <?php
3 /**
4 * Decorator that, depending on a token, switches between two definitions.
5 */
6 class HTMLPurifier_AttrDef_Switch
9 protected $tag;
10 protected $withTag, $withoutTag;
12 /**
13 * @param string $tag Tag name to switch upon
14 * @param HTMLPurifier_AttrDef $with_tag Call if token matches tag
15 * @param HTMLPurifier_AttrDef $without_tag Call if token doesn't match, or there is no token
17 public function __construct($tag, $with_tag, $without_tag) {
18 $this->tag = $tag;
19 $this->withTag = $with_tag;
20 $this->withoutTag = $without_tag;
23 public function validate($string, $config, $context) {
24 $token = $context->get('CurrentToken', true);
25 if (!$token || $token->name !== $this->tag) {
26 return $this->withoutTag->validate($string, $config, $context);
27 } else {
28 return $this->withTag->validate($string, $config, $context);
34 // vim: et sw=4 sts=4