ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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
Base class for all validating attribute definitions.
Definition: AttrDef.php:13
$result
validate($string, $config, $context)
Definition: Enum.php:42
__construct($valid_values=array(), $case_sensitive=false)
Definition: Enum.php:30
$case_sensitive
Bool indicating whether or not enumeration is case sensitive.
Definition: Enum.php:24
Create styles array
The data for the language used.
$valid_values
Lookup table of valid values.
Definition: Enum.php:18
Validates a keyword against a list of valid values.
Definition: Enum.php:10