ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5
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
 Whether or not negative values are allowed. More...
 
 $zero = true
 Whether or not zero is allowed. More...
 
 $positive = true
 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 36 of file Integer.php.

References $negative, $positive, and $zero.

37  {
38  $this->negative = $negative;
39  $this->zero = $zero;
40  $this->positive = $positive;
41  }
$negative
Whether or not negative values are allowed.
Definition: Integer.php:17
$positive
Whether or not positive values are allowed.
Definition: Integer.php:29
$zero
Whether or not zero is allowed.
Definition: Integer.php:23

Member Function Documentation

◆ validate()

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

Definition at line 49 of file Integer.php.

References HTMLPurifier_AttrDef\parseCDATA().

50  {
51  $integer = $this->parseCDATA($integer);
52  if ($integer === '') {
53  return false;
54  }
55 
56  // we could possibly simply typecast it to integer, but there are
57  // certain fringe cases that must not return an integer.
58 
59  // clip leading sign
60  if ($this->negative && $integer[0] === '-') {
61  $digits = substr($integer, 1);
62  if ($digits === '0') {
63  $integer = '0';
64  } // rm minus sign for zero
65  } elseif ($this->positive && $integer[0] === '+') {
66  $digits = $integer = substr($integer, 1); // rm unnecessary plus
67  } else {
68  $digits = $integer;
69  }
70 
71  // test if it's numeric
72  if (!ctype_digit($digits)) {
73  return false;
74  }
75 
76  // perform scope tests
77  if (!$this->zero && $integer == 0) {
78  return false;
79  }
80  if (!$this->positive && $integer > 0) {
81  return false;
82  }
83  if (!$this->negative && $integer < 0) {
84  return false;
85  }
86 
87  return $integer;
88  }
parseCDATA($string)
Convenience method that parses a string as if it were CDATA.
Definition: AttrDef.php:60
+ Here is the call graph for this function:

Field Documentation

◆ $negative

HTMLPurifier_AttrDef_Integer::$negative = true
protected

Whether or not negative values are allowed.

bool

Definition at line 17 of file Integer.php.

Referenced by __construct().

◆ $positive

HTMLPurifier_AttrDef_Integer::$positive = true
protected

Whether or not positive values are allowed.

bool

Definition at line 29 of file Integer.php.

Referenced by __construct().

◆ $zero

HTMLPurifier_AttrDef_Integer::$zero = true
protected

Whether or not zero is allowed.

bool

Definition at line 23 of file Integer.php.

Referenced by __construct().


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