ILIAS  Release_4_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 
17  public $valid_values = array();
18 
23  protected $case_sensitive = false; // values according to W3C spec
24 
29  public function __construct(
30  $valid_values = array(), $case_sensitive = false
31  ) {
32  $this->valid_values = array_flip($valid_values);
33  $this->case_sensitive = $case_sensitive;
34  }
35 
36  public function validate($string, $config, $context) {
37  $string = trim($string);
38  if (!$this->case_sensitive) {
39  // we may want to do full case-insensitive libraries
40  $string = ctype_lower($string) ? $string : strtolower($string);
41  }
42  $result = isset($this->valid_values[$string]);
43 
44  return $result ? $string : false;
45  }
46 
52  public function make($string) {
53  if (strlen($string) > 2 && $string[0] == 's' && $string[1] == ':') {
54  $string = substr($string, 2);
55  $sensitive = true;
56  } else {
57  $sensitive = false;
58  }
59  $values = explode(',', $string);
60  return new HTMLPurifier_AttrDef_Enum($values, $sensitive);
61  }
62 
63 }
64 
65 // vim: et sw=4 sts=4