Fix two minor bugs, updating Phorum and removing unused $dir variable.
[htmlpurifier/darkodev.git] / library / HTMLPurifier / TokenFactory.php
blob7cf48fb41c1ee30b3d2a5f21a22579effb1d547d
1 <?php
3 /**
4 * Factory for token generation.
6 * @note Doing some benchmarking indicates that the new operator is much
7 * slower than the clone operator (even discounting the cost of the
8 * constructor). This class is for that optimization.
9 * Other then that, there's not much point as we don't
10 * maintain parallel HTMLPurifier_Token hierarchies (the main reason why
11 * you'd want to use an abstract factory).
12 * @todo Port DirectLex to use this
14 class HTMLPurifier_TokenFactory
17 /**
18 * Prototypes that will be cloned.
19 * @private
21 // p stands for prototype
22 private $p_start, $p_end, $p_empty, $p_text, $p_comment;
24 /**
25 * Generates blank prototypes for cloning.
27 public function __construct() {
28 $this->p_start = new HTMLPurifier_Token_Start('', array());
29 $this->p_end = new HTMLPurifier_Token_End('');
30 $this->p_empty = new HTMLPurifier_Token_Empty('', array());
31 $this->p_text = new HTMLPurifier_Token_Text('');
32 $this->p_comment= new HTMLPurifier_Token_Comment('');
35 /**
36 * Creates a HTMLPurifier_Token_Start.
37 * @param $name Tag name
38 * @param $attr Associative array of attributes
39 * @return Generated HTMLPurifier_Token_Start
41 public function createStart($name, $attr = array()) {
42 $p = clone $this->p_start;
43 $p->__construct($name, $attr);
44 return $p;
47 /**
48 * Creates a HTMLPurifier_Token_End.
49 * @param $name Tag name
50 * @return Generated HTMLPurifier_Token_End
52 public function createEnd($name) {
53 $p = clone $this->p_end;
54 $p->__construct($name);
55 return $p;
58 /**
59 * Creates a HTMLPurifier_Token_Empty.
60 * @param $name Tag name
61 * @param $attr Associative array of attributes
62 * @return Generated HTMLPurifier_Token_Empty
64 public function createEmpty($name, $attr = array()) {
65 $p = clone $this->p_empty;
66 $p->__construct($name, $attr);
67 return $p;
70 /**
71 * Creates a HTMLPurifier_Token_Text.
72 * @param $data Data of text token
73 * @return Generated HTMLPurifier_Token_Text
75 public function createText($data) {
76 $p = clone $this->p_text;
77 $p->__construct($data);
78 return $p;
81 /**
82 * Creates a HTMLPurifier_Token_Comment.
83 * @param $data Data of comment token
84 * @return Generated HTMLPurifier_Token_Comment
86 public function createComment($data) {
87 $p = clone $this->p_comment;
88 $p->__construct($data);
89 return $p;
94 // vim: et sw=4 sts=4