MDL-11082 Improved groups upgrade performance 1.8x -> 1.9; thanks Eloy for telling...
[moodle-pu.git] / lib / htmlpurifier / HTMLPurifier / TokenFactory.php
blobd15ee1a9e12263f25613b6bc769246cd5d99be47
1 <?php
3 require_once 'HTMLPurifier/Token.php';
5 /**
6 * Factory for token generation (PHP 5 only).
7 *
8 * @note Doing some benchmarking indicates that the new operator is much
9 * slower than the clone operator (even discounting the cost of the
10 * constructor). This class is for that optimization. We may want to
11 * consider porting this to PHP 4 by virtue of the fact it makes the code
12 * easier to read. Other then that, there's not much point as we don't
13 * maintain parallel HTMLPurifier_Token hierarchies (the main reason why
14 * you'd want to use an abstract factory).
16 class HTMLPurifier_TokenFactory
19 /**
20 * Prototypes that will be cloned.
21 * @private
23 // p stands for prototype
24 private $p_start, $p_end, $p_empty, $p_text, $p_comment;
26 /**
27 * Generates blank prototypes for cloning.
29 public function __construct() {
30 $this->p_start = new HTMLPurifier_Token_Start('', array());
31 $this->p_end = new HTMLPurifier_Token_End('');
32 $this->p_empty = new HTMLPurifier_Token_Empty('', array());
33 $this->p_text = new HTMLPurifier_Token_Text('');
34 $this->p_comment= new HTMLPurifier_Token_Comment('');
37 /**
38 * Creates a HTMLPurifier_Token_Start.
39 * @param $name Tag name
40 * @param $attr Associative array of attributes
41 * @return Generated HTMLPurifier_Token_Start
43 public function createStart($name, $attr = array()) {
44 $p = clone $this->p_start;
45 $p->HTMLPurifier_Token_Tag($name, $attr);
46 return $p;
49 /**
50 * Creates a HTMLPurifier_Token_End.
51 * @param $name Tag name
52 * @return Generated HTMLPurifier_Token_End
54 public function createEnd($name) {
55 $p = clone $this->p_end;
56 $p->HTMLPurifier_Token_Tag($name);
57 return $p;
60 /**
61 * Creates a HTMLPurifier_Token_Empty.
62 * @param $name Tag name
63 * @param $attr Associative array of attributes
64 * @return Generated HTMLPurifier_Token_Empty
66 public function createEmpty($name, $attr = array()) {
67 $p = clone $this->p_empty;
68 $p->HTMLPurifier_Token_Tag($name, $attr);
69 return $p;
72 /**
73 * Creates a HTMLPurifier_Token_Text.
74 * @param $data Data of text token
75 * @return Generated HTMLPurifier_Token_Text
77 public function createText($data) {
78 $p = clone $this->p_text;
79 $p->HTMLPurifier_Token_Text($data);
80 return $p;
83 /**
84 * Creates a HTMLPurifier_Token_Comment.
85 * @param $data Data of comment token
86 * @return Generated HTMLPurifier_Token_Comment
88 public function createComment($data) {
89 $p = clone $this->p_comment;
90 $p->HTMLPurifier_Token_Comment($data);
91 return $p;