Implement %HTML.Attr.Name.UseCDATA which relaxes name validation rules.
[htmlpurifier.git] / library / HTMLPurifier / AttrTypes.php
blob6c624bb0ba6dc801d5212abe4088e2f0fd4e412e
1 <?php
3 /**
4 * Provides lookup array of attribute types to HTMLPurifier_AttrDef objects
5 */
6 class HTMLPurifier_AttrTypes
8 /**
9 * Lookup array of attribute string identifiers to concrete implementations
11 protected $info = array();
13 /**
14 * Constructs the info array, supplying default implementations for attribute
15 * types.
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();
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();
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();
39 // number is really a positive integer (one or more digits)
40 // FIXME: ^^ not always, see start and value of list items
41 $this->info['Number'] = new HTMLPurifier_AttrDef_Integer(false, false, true);
44 /**
45 * Retrieves a type
46 * @param $type String type name
47 * @return Object AttrDef for type
49 public function get($type) {
51 // determine if there is any extra info tacked on
52 if (strpos($type, '#') !== false) list($type, $string) = explode('#', $type, 2);
53 else $string = '';
55 if (!isset($this->info[$type])) {
56 trigger_error('Cannot retrieve undefined attribute type ' . $type, E_USER_ERROR);
57 return;
60 return $this->info[$type]->make($string);
64 /**
65 * Sets a new implementation for a type
66 * @param $type String type name
67 * @param $impl Object AttrDef for type
69 public function set($type, $impl) {
70 $this->info[$type] = $impl;
74 // vim: et sw=4 sts=4