PSR-2 reformatting PHPDoc corrections
[htmlpurifier.git] / library / HTMLPurifier / TokenFactory.php
blobdea2446b93af15c0db39a1d3e263024881aa9cf2
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
16 // p stands for prototype
18 /**
19 * @type HTMLPurifier_Token_Start
21 private $p_start;
23 /**
24 * @type HTMLPurifier_Token_End
26 private $p_end;
28 /**
29 * @type HTMLPurifier_Token_Empty
31 private $p_empty;
33 /**
34 * @type HTMLPurifier_Token_Text
36 private $p_text;
38 /**
39 * @type HTMLPurifier_Token_Comment
41 private $p_comment;
43 /**
44 * Generates blank prototypes for cloning.
46 public function __construct()
48 $this->p_start = new HTMLPurifier_Token_Start('', array());
49 $this->p_end = new HTMLPurifier_Token_End('');
50 $this->p_empty = new HTMLPurifier_Token_Empty('', array());
51 $this->p_text = new HTMLPurifier_Token_Text('');
52 $this->p_comment = new HTMLPurifier_Token_Comment('');
55 /**
56 * Creates a HTMLPurifier_Token_Start.
57 * @param string $name Tag name
58 * @param array $attr Associative array of attributes
59 * @return HTMLPurifier_Token_Start Generated HTMLPurifier_Token_Start
61 public function createStart($name, $attr = array())
63 $p = clone $this->p_start;
64 $p->__construct($name, $attr);
65 return $p;
68 /**
69 * Creates a HTMLPurifier_Token_End.
70 * @param string $name Tag name
71 * @return HTMLPurifier_Token_End Generated HTMLPurifier_Token_End
73 public function createEnd($name)
75 $p = clone $this->p_end;
76 $p->__construct($name);
77 return $p;
80 /**
81 * Creates a HTMLPurifier_Token_Empty.
82 * @param string $name Tag name
83 * @param array $attr Associative array of attributes
84 * @return HTMLPurifier_Token_Empty Generated HTMLPurifier_Token_Empty
86 public function createEmpty($name, $attr = array())
88 $p = clone $this->p_empty;
89 $p->__construct($name, $attr);
90 return $p;
93 /**
94 * Creates a HTMLPurifier_Token_Text.
95 * @param string $data Data of text token
96 * @return HTMLPurifier_Token_Text Generated HTMLPurifier_Token_Text
98 public function createText($data)
100 $p = clone $this->p_text;
101 $p->__construct($data);
102 return $p;
106 * Creates a HTMLPurifier_Token_Comment.
107 * @param string $data Data of comment token
108 * @return HTMLPurifier_Token_Comment Generated HTMLPurifier_Token_Comment
110 public function createComment($data)
112 $p = clone $this->p_comment;
113 $p->__construct($data);
114 return $p;
118 // vim: et sw=4 sts=4