[ Index ]

PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008]

title

Body

[close]

/lib/htmlpurifier/HTMLPurifier/ -> TokenFactory.php (source)

   1  <?php
   2  
   3  require_once 'HTMLPurifier/Token.php';
   4  
   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).
  15   */
  16  class HTMLPurifier_TokenFactory
  17  {
  18      
  19      /**
  20       * Prototypes that will be cloned.
  21       * @private
  22       */
  23      // p stands for prototype
  24      private $p_start, $p_end, $p_empty, $p_text, $p_comment;
  25      
  26      /**
  27       * Generates blank prototypes for cloning.
  28       */
  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('');
  35      }
  36      
  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
  42       */
  43      public function createStart($name, $attr = array()) {
  44          $p = clone $this->p_start;
  45          $p->HTMLPurifier_Token_Tag($name, $attr);
  46          return $p;
  47      }
  48      
  49      /**
  50       * Creates a HTMLPurifier_Token_End.
  51       * @param $name Tag name
  52       * @return Generated HTMLPurifier_Token_End
  53       */
  54      public function createEnd($name) {
  55          $p = clone $this->p_end;
  56          $p->HTMLPurifier_Token_Tag($name);
  57          return $p;
  58      }
  59      
  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
  65       */
  66      public function createEmpty($name, $attr = array()) {
  67          $p = clone $this->p_empty;
  68          $p->HTMLPurifier_Token_Tag($name, $attr);
  69          return $p;
  70      }
  71      
  72      /**
  73       * Creates a HTMLPurifier_Token_Text.
  74       * @param $data Data of text token
  75       * @return Generated HTMLPurifier_Token_Text
  76       */
  77      public function createText($data) {
  78          $p = clone $this->p_text;
  79          $p->HTMLPurifier_Token_Text($data);
  80          return $p;
  81      }
  82      
  83      /**
  84       * Creates a HTMLPurifier_Token_Comment.
  85       * @param $data Data of comment token
  86       * @return Generated HTMLPurifier_Token_Comment
  87       */
  88      public function createComment($data) {
  89          $p = clone $this->p_comment;
  90          $p->HTMLPurifier_Token_Comment($data);
  91          return $p;
  92      }
  93      
  94  }
  95  


Generated: Wed Jan 14 11:33:29 2009 Cross-referenced by PHPXref 0.7