Make test script less chatty when log_errors is on.
[htmlpurifier.git] / library / HTMLPurifier / AttrTypes.php
blobfc2ea4e5881bfc301db5fc7fcd9cd1aae9082932
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 // "proprietary" types
40 $this->info['Class'] = new HTMLPurifier_AttrDef_HTML_Class();
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);
47 /**
48 * Retrieves a type
49 * @param $type String type name
50 * @return Object AttrDef for type
52 public function get($type) {
54 // determine if there is any extra info tacked on
55 if (strpos($type, '#') !== false) list($type, $string) = explode('#', $type, 2);
56 else $string = '';
58 if (!isset($this->info[$type])) {
59 trigger_error('Cannot retrieve undefined attribute type ' . $type, E_USER_ERROR);
60 return;
63 return $this->info[$type]->make($string);
67 /**
68 * Sets a new implementation for a type
69 * @param $type String type name
70 * @param $impl Object AttrDef for type
72 public function set($type, $impl) {
73 $this->info[$type] = $impl;
77 // vim: et sw=4 sts=4