]>
Commit | Line | Data |
---|---|---|
f45a286b AD |
1 | <?php |
2 | ||
3 | /** | |
4 | * Provides lookup array of attribute types to HTMLPurifier_AttrDef objects | |
5 | */ | |
6 | class HTMLPurifier_AttrTypes | |
7 | { | |
8 | /** | |
9 | * Lookup array of attribute string identifiers to concrete implementations | |
10 | */ | |
11 | protected $info = array(); | |
12 | ||
13 | /** | |
14 | * Constructs the info array, supplying default implementations for attribute | |
15 | * types. | |
16 | */ | |
17 | public function __construct() { | |
18 | // pseudo-types, must be instantiated via shorthand | |
19 | $this->info['Enum'] = new HTMLPurifier_AttrDef_Enum(); | |
20 | $this->info['Bool'] = new HTMLPurifier_AttrDef_HTML_Bool(); | |
21 | ||
22 | $this->info['CDATA'] = new HTMLPurifier_AttrDef_Text(); | |
23 | $this->info['ID'] = new HTMLPurifier_AttrDef_HTML_ID(); | |
24 | $this->info['Length'] = new HTMLPurifier_AttrDef_HTML_Length(); | |
25 | $this->info['MultiLength'] = new HTMLPurifier_AttrDef_HTML_MultiLength(); | |
26 | $this->info['NMTOKENS'] = new HTMLPurifier_AttrDef_HTML_Nmtokens(); | |
27 | $this->info['Pixels'] = new HTMLPurifier_AttrDef_HTML_Pixels(); | |
28 | $this->info['Text'] = new HTMLPurifier_AttrDef_Text(); | |
29 | $this->info['URI'] = new HTMLPurifier_AttrDef_URI(); | |
30 | $this->info['LanguageCode'] = new HTMLPurifier_AttrDef_Lang(); | |
31 | $this->info['Color'] = new HTMLPurifier_AttrDef_HTML_Color(); | |
32 | ||
33 | // unimplemented aliases | |
34 | $this->info['ContentType'] = new HTMLPurifier_AttrDef_Text(); | |
35 | $this->info['ContentTypes'] = new HTMLPurifier_AttrDef_Text(); | |
36 | $this->info['Charsets'] = new HTMLPurifier_AttrDef_Text(); | |
37 | $this->info['Character'] = new HTMLPurifier_AttrDef_Text(); | |
38 | ||
f4f0f80d AD |
39 | // "proprietary" types |
40 | $this->info['Class'] = new HTMLPurifier_AttrDef_HTML_Class(); | |
41 | ||
f45a286b AD |
42 | // number is really a positive integer (one or more digits) |
43 | // FIXME: ^^ not always, see start and value of list items | |
44 | $this->info['Number'] = new HTMLPurifier_AttrDef_Integer(false, false, true); | |
45 | } | |
46 | ||
47 | /** | |
48 | * Retrieves a type | |
49 | * @param $type String type name | |
50 | * @return Object AttrDef for type | |
51 | */ | |
52 | public function get($type) { | |
53 | ||
54 | // determine if there is any extra info tacked on | |
55 | if (strpos($type, '#') !== false) list($type, $string) = explode('#', $type, 2); | |
56 | else $string = ''; | |
57 | ||
58 | if (!isset($this->info[$type])) { | |
59 | trigger_error('Cannot retrieve undefined attribute type ' . $type, E_USER_ERROR); | |
60 | return; | |
61 | } | |
62 | ||
63 | return $this->info[$type]->make($string); | |
64 | ||
65 | } | |
66 | ||
67 | /** | |
68 | * Sets a new implementation for a type | |
69 | * @param $type String type name | |
70 | * @param $impl Object AttrDef for type | |
71 | */ | |
72 | public function set($type, $impl) { | |
73 | $this->info[$type] = $impl; | |
74 | } | |
75 | } | |
76 | ||
77 | // vim: et sw=4 sts=4 |