]> git.immae.eu Git - github/wallabag/wallabag.git/blame - inc/3rdparty/htmlpurifier/HTMLPurifier/AttrDef/Switch.php
remove autoload section in composer.json
[github/wallabag/wallabag.git] / inc / 3rdparty / htmlpurifier / HTMLPurifier / AttrDef / Switch.php
CommitLineData
d4949327
NL
1<?php\r
2\r
3/**\r
4 * Decorator that, depending on a token, switches between two definitions.\r
5 */\r
6class HTMLPurifier_AttrDef_Switch\r
7{\r
8\r
9 /**\r
10 * @type string\r
11 */\r
12 protected $tag;\r
13\r
14 /**\r
15 * @type HTMLPurifier_AttrDef\r
16 */\r
17 protected $withTag;\r
18\r
19 /**\r
20 * @type HTMLPurifier_AttrDef\r
21 */\r
22 protected $withoutTag;\r
23\r
24 /**\r
25 * @param string $tag Tag name to switch upon\r
26 * @param HTMLPurifier_AttrDef $with_tag Call if token matches tag\r
27 * @param HTMLPurifier_AttrDef $without_tag Call if token doesn't match, or there is no token\r
28 */\r
29 public function __construct($tag, $with_tag, $without_tag)\r
30 {\r
31 $this->tag = $tag;\r
32 $this->withTag = $with_tag;\r
33 $this->withoutTag = $without_tag;\r
34 }\r
35\r
36 /**\r
37 * @param string $string\r
38 * @param HTMLPurifier_Config $config\r
39 * @param HTMLPurifier_Context $context\r
40 * @return bool|string\r
41 */\r
42 public function validate($string, $config, $context)\r
43 {\r
44 $token = $context->get('CurrentToken', true);\r
45 if (!$token || $token->name !== $this->tag) {\r
46 return $this->withoutTag->validate($string, $config, $context);\r
47 } else {\r
48 return $this->withTag->validate($string, $config, $context);\r
49 }\r
50 }\r
51}\r
52\r
53// vim: et sw=4 sts=4\r