ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
HTMLPurifier_AttrDef_Enum Class Reference

Validates a keyword against a list of valid values. More...

+ Inheritance diagram for HTMLPurifier_AttrDef_Enum:
+ Collaboration diagram for HTMLPurifier_AttrDef_Enum:

Public Member Functions

 __construct ($valid_values=array(), $case_sensitive=false)
 
 validate ($string, $config, $context)
 
 make ($string)
 
- Public Member Functions inherited from HTMLPurifier_AttrDef
 validate ($string, $config, $context)
 Validates and cleans passed string according to a definition. More...
 
 parseCDATA ($string)
 Convenience method that parses a string as if it were CDATA. More...
 
 make ($string)
 Factory method for creating this class from a string. More...
 

Data Fields

 $valid_values = array()
 Lookup table of valid values. More...
 
- Data Fields inherited from HTMLPurifier_AttrDef
 $minimized = false
 Tells us whether or not an HTML attribute is minimized. More...
 
 $required = false
 Tells us whether or not an HTML attribute is required. More...
 

Protected Attributes

 $case_sensitive = false
 Bool indicating whether or not enumeration is case sensitive. More...
 

Additional Inherited Members

- Protected Member Functions inherited from HTMLPurifier_AttrDef
 mungeRgb ($string)
 Removes spaces from rgb(0, 0, 0) so that shorthand CSS properties work properly. More...
 
 expandCSSEscape ($string)
 Parses a possibly escaped CSS string and returns the "pure" version of it. More...
 

Detailed Description

Validates a keyword against a list of valid values.

Warning
The case-insensitive compare of this function uses PHP's built-in strtolower and ctype_lower functions, which may cause problems with international comparisons

Definition at line 10 of file Enum.php.

Constructor & Destructor Documentation

◆ __construct()

HTMLPurifier_AttrDef_Enum::__construct (   $valid_values = array(),
  $case_sensitive = false 
)
Parameters
array$valid_valuesList of valid values
bool$case_sensitiveWhether or not case sensitive

Definition at line 30 of file Enum.php.

References $case_sensitive, and $valid_values.

31  {
32  $this->valid_values = array_flip($valid_values);
33  $this->case_sensitive = $case_sensitive;
34  }
$case_sensitive
Bool indicating whether or not enumeration is case sensitive.
Definition: Enum.php:24
$valid_values
Lookup table of valid values.
Definition: Enum.php:18

Member Function Documentation

◆ make()

HTMLPurifier_AttrDef_Enum::make (   $string)
Parameters
string$stringIn form of comma-delimited list of case-insensitive valid values. Example: "foo,bar,baz". Prepend "s:" to make case sensitive
Returns
HTMLPurifier_AttrDef_Enum

Definition at line 60 of file Enum.php.

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  }
Validates a keyword against a list of valid values.
Definition: Enum.php:10

◆ validate()

HTMLPurifier_AttrDef_Enum::validate (   $string,
  $config,
  $context 
)
Parameters
string$string
HTMLPurifier_Config$config
HTMLPurifier_Context$context
Returns
bool|string

Definition at line 42 of file Enum.php.

References $result.

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  }
$result

Field Documentation

◆ $case_sensitive

HTMLPurifier_AttrDef_Enum::$case_sensitive = false
protected

Bool indicating whether or not enumeration is case sensitive.

Note
In general this is always case insensitive.

Definition at line 24 of file Enum.php.

Referenced by __construct().

◆ $valid_values

HTMLPurifier_AttrDef_Enum::$valid_values = array()

Lookup table of valid values.

array

Todo:
Make protected

Definition at line 18 of file Enum.php.

Referenced by __construct().


The documentation for this class was generated from the following file: