ILIAS  release_4-4 Revision
HTMLPurifier_AttrDef_Integer Class Reference

Validates an integer. More...

+ Inheritance diagram for HTMLPurifier_AttrDef_Integer:
+ Collaboration diagram for HTMLPurifier_AttrDef_Integer:

Public Member Functions

 __construct ( $negative=true, $zero=true, $positive=true)
 
 validate ($integer, $config, $context)
 
- 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...
 

Protected Attributes

 $negative = true
 Bool indicating whether or not negative values are allowed. More...
 
 $zero = true
 Bool indicating whether or not zero is allowed. More...
 
 $positive = true
 Bool indicating whether or not positive values are allowed. More...
 

Additional Inherited Members

- 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 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 an integer.

Note
While this class was modeled off the CSS definition, no currently allowed CSS uses this type. The properties that do are: widows, orphans, z-index, counter-increment, counter-reset. Some of the HTML attributes, however, find use for a non-negative version of this.

Definition at line 10 of file Integer.php.

Constructor & Destructor Documentation

◆ __construct()

HTMLPurifier_AttrDef_Integer::__construct (   $negative = true,
  $zero = true,
  $positive = true 
)
Parameters
$negativeBool indicating whether or not negative values are allowed
$zeroBool indicating whether or not zero is allowed
$positiveBool indicating whether or not positive values are allowed

Definition at line 33 of file Integer.php.

References $negative, $positive, and $zero.

35  {
36  $this->negative = $negative;
37  $this->zero = $zero;
38  $this->positive = $positive;
39  }
$negative
Bool indicating whether or not negative values are allowed.
Definition: Integer.php:16
$positive
Bool indicating whether or not positive values are allowed.
Definition: Integer.php:26
$zero
Bool indicating whether or not zero is allowed.
Definition: Integer.php:21

Member Function Documentation

◆ validate()

HTMLPurifier_AttrDef_Integer::validate (   $integer,
  $config,
  $context 
)

Definition at line 41 of file Integer.php.

References HTMLPurifier_AttrDef\parseCDATA().

41  {
42 
43  $integer = $this->parseCDATA($integer);
44  if ($integer === '') return false;
45 
46  // we could possibly simply typecast it to integer, but there are
47  // certain fringe cases that must not return an integer.
48 
49  // clip leading sign
50  if ( $this->negative && $integer[0] === '-' ) {
51  $digits = substr($integer, 1);
52  if ($digits === '0') $integer = '0'; // rm minus sign for zero
53  } elseif( $this->positive && $integer[0] === '+' ) {
54  $digits = $integer = substr($integer, 1); // rm unnecessary plus
55  } else {
56  $digits = $integer;
57  }
58 
59  // test if it's numeric
60  if (!ctype_digit($digits)) return false;
61 
62  // perform scope tests
63  if (!$this->zero && $integer == 0) return false;
64  if (!$this->positive && $integer > 0) return false;
65  if (!$this->negative && $integer < 0) return false;
66 
67  return $integer;
68 
69  }
parseCDATA($string)
Convenience method that parses a string as if it were CDATA.
Definition: AttrDef.php:58
+ Here is the call graph for this function:

Field Documentation

◆ $negative

HTMLPurifier_AttrDef_Integer::$negative = true
protected

Bool indicating whether or not negative values are allowed.

Definition at line 16 of file Integer.php.

Referenced by __construct().

◆ $positive

HTMLPurifier_AttrDef_Integer::$positive = true
protected

Bool indicating whether or not positive values are allowed.

Definition at line 26 of file Integer.php.

Referenced by __construct().

◆ $zero

HTMLPurifier_AttrDef_Integer::$zero = true
protected

Bool indicating whether or not zero is allowed.

Definition at line 21 of file Integer.php.

Referenced by __construct().


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