ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
Enum.php
Go to the documentation of this file.
1 <?php
2 
3 // Enum = Enumerated
11 {
12 
18  public $valid_values = array();
19 
24  protected $case_sensitive = false; // values according to W3C spec
25 
30  public function __construct($valid_values = array(), $case_sensitive = false)
31  {
32  $this->valid_values = array_flip($valid_values);
33  $this->case_sensitive = $case_sensitive;
34  }
35 
42  public function validate($string, $config, $context)
43  {
44  $string = trim($string);
45  if (!$this->case_sensitive) {
46  // we may want to do full case-insensitive libraries
47  $string = ctype_lower($string) ? $string : strtolower($string);
48  }
49  $result = isset($this->valid_values[$string]);
50 
51  return $result ? $string : false;
52  }
53 
60  public function make($string)
61  {
62  if (strlen($string) > 2 && $string[0] == 's' && $string[1] == ':') {
63  $string = substr($string, 2);
64  $sensitive = true;
65  } else {
66  $sensitive = false;
67  }
68  $values = explode(',', $string);
69  return new HTMLPurifier_AttrDef_Enum($values, $sensitive);
70  }
71 }
72 
73 // vim: et sw=4 sts=4