Source for file Enum.php

Documentation is available at Enum.php

  1. <?php
  2.  
  3. // Enum = Enumerated
  4. /**
  5.  * Validates a keyword against a list of valid values.
  6.  * @warning The case-insensitive compare of this function uses PHP's
  7.  *           built-in strtolower and ctype_lower functions, which may
  8.  *           cause problems with international comparisons
  9.  */
  10. {
  11.     
  12.     /**
  13.      * Lookup table of valid values.
  14.      * @todo Make protected
  15.      */
  16.     public $valid_values   = array();
  17.     
  18.     /**
  19.      * Bool indicating whether or not enumeration is case sensitive.
  20.      * @note In general this is always case insensitive.
  21.      */
  22.     protected $case_sensitive = false// values according to W3C spec
  23.     
  24.     /**
  25.      * @param $valid_values List of valid values
  26.      * @param $case_sensitive Bool indicating whether or not case sensitive
  27.      */
  28.     public function __construct(
  29.         $valid_values array()$case_sensitive false
  30.     {
  31.         $this->valid_values = array_flip($valid_values);
  32.         $this->case_sensitive = $case_sensitive;
  33.     }
  34.     
  35.     public function validate($string$config$context{
  36.         $string trim($string);
  37.         if (!$this->case_sensitive{
  38.             // we may want to do full case-insensitive libraries
  39.             $string ctype_lower($string$string strtolower($string);
  40.         }
  41.         $result = isset($this->valid_values[$string]);
  42.         
  43.         return $result $string false;
  44.     }
  45.     
  46.     /**
  47.      * @param $string In form of comma-delimited list of case-insensitive
  48.      *       valid values. Example: "foo,bar,baz". Prepend "s:" to make
  49.      *       case sensitive
  50.      */
  51.     public function make($string{
  52.         if (strlen($string&& $string[0== 's' && $string[1== ':'{
  53.             $string substr($string2);
  54.             $sensitive true;
  55.         else {
  56.             $sensitive false;
  57.         }
  58.         $values explode(','$string);
  59.         return new HTMLPurifier_AttrDef_Enum($values$sensitive);
  60.     }
  61.     
  62. }

Documentation generated on Thu, 19 Jun 2008 18:49:09 -0400 by phpDocumentor 1.4.2