Fix problem where stacked AttrTransforms clobber each other.
[htmlpurifier.git] / library / HTMLPurifier / AttrTypes.php
blob6f985ff934750f0c5d068e991228748e8bf3ce93
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 // XXX This is kind of poor, since we don't actually /clone/
19 // instances; instead, we use the supplied make() attribute. So,
20 // the underlying class must know how to deal with arguments.
21 // With the old implementation of Enum, that ignored its
22 // arguments when handling a make dispatch, the IAlign
23 // definition wouldn't work.
25 // pseudo-types, must be instantiated via shorthand
26 $this->info['Enum'] = new HTMLPurifier_AttrDef_Enum();
27 $this->info['Bool'] = new HTMLPurifier_AttrDef_HTML_Bool();
29 $this->info['CDATA'] = new HTMLPurifier_AttrDef_Text();
30 $this->info['ID'] = new HTMLPurifier_AttrDef_HTML_ID();
31 $this->info['Length'] = new HTMLPurifier_AttrDef_HTML_Length();
32 $this->info['MultiLength'] = new HTMLPurifier_AttrDef_HTML_MultiLength();
33 $this->info['NMTOKENS'] = new HTMLPurifier_AttrDef_HTML_Nmtokens();
34 $this->info['Pixels'] = new HTMLPurifier_AttrDef_HTML_Pixels();
35 $this->info['Text'] = new HTMLPurifier_AttrDef_Text();
36 $this->info['URI'] = new HTMLPurifier_AttrDef_URI();
37 $this->info['LanguageCode'] = new HTMLPurifier_AttrDef_Lang();
38 $this->info['Color'] = new HTMLPurifier_AttrDef_HTML_Color();
39 $this->info['IAlign'] = self::makeEnum('top,middle,bottom,left,right');
40 $this->info['LAlign'] = self::makeEnum('top,bottom,left,right');
41 $this->info['FrameTarget'] = new HTMLPurifier_AttrDef_HTML_FrameTarget();
43 // unimplemented aliases
44 $this->info['ContentType'] = new HTMLPurifier_AttrDef_Text();
45 $this->info['ContentTypes'] = new HTMLPurifier_AttrDef_Text();
46 $this->info['Charsets'] = new HTMLPurifier_AttrDef_Text();
47 $this->info['Character'] = new HTMLPurifier_AttrDef_Text();
49 // "proprietary" types
50 $this->info['Class'] = new HTMLPurifier_AttrDef_HTML_Class();
52 // number is really a positive integer (one or more digits)
53 // FIXME: ^^ not always, see start and value of list items
54 $this->info['Number'] = new HTMLPurifier_AttrDef_Integer(false, false, true);
57 private static function makeEnum($in) {
58 return new HTMLPurifier_AttrDef_Clone(new HTMLPurifier_AttrDef_Enum(explode(',', $in)));
61 /**
62 * Retrieves a type
63 * @param $type String type name
64 * @return Object AttrDef for type
66 public function get($type) {
68 // determine if there is any extra info tacked on
69 if (strpos($type, '#') !== false) list($type, $string) = explode('#', $type, 2);
70 else $string = '';
72 if (!isset($this->info[$type])) {
73 trigger_error('Cannot retrieve undefined attribute type ' . $type, E_USER_ERROR);
74 return;
77 return $this->info[$type]->make($string);
81 /**
82 * Sets a new implementation for a type
83 * @param $type String type name
84 * @param $impl Object AttrDef for type
86 public function set($type, $impl) {
87 $this->info[$type] = $impl;
91 // vim: et sw=4 sts=4