ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Length.php
Go to the documentation of this file.
1 <?php
2 
7 {
8 
12  protected $min;
13 
17  protected $max;
18 
23  public function __construct($min = null, $max = null)
24  {
25  $this->min = $min !== null ? HTMLPurifier_Length::make($min) : null;
26  $this->max = $max !== null ? HTMLPurifier_Length::make($max) : null;
27  }
28 
35  public function validate($string, $config, $context)
36  {
37  $string = $this->parseCDATA($string);
38 
39  // Optimizations
40  if ($string === '') {
41  return false;
42  }
43  if ($string === '0') {
44  return '0';
45  }
46  if (strlen($string) === 1) {
47  return false;
48  }
49 
50  $length = HTMLPurifier_Length::make($string);
51  if (!$length->isValid()) {
52  return false;
53  }
54 
55  if ($this->min) {
56  $c = $length->compareTo($this->min);
57  if ($c === false) {
58  return false;
59  }
60  if ($c < 0) {
61  return false;
62  }
63  }
64  if ($this->max) {
65  $c = $length->compareTo($this->max);
66  if ($c === false) {
67  return false;
68  }
69  if ($c > 0) {
70  return false;
71  }
72  }
73  return $length->toString();
74  }
75 }
76 
77 // vim: et sw=4 sts=4
__construct($min=null, $max=null)
Definition: Length.php:23
$context
Definition: webdav.php:25
Base class for all validating attribute definitions.
Definition: AttrDef.php:13
$config
Definition: bootstrap.php:15
$max
HTMLPurifier_Length|string
Definition: Length.php:17
Represents a Length as defined by CSS.
Definition: Length.php:6
static make($s)
Definition: Length.php:54
$min
HTMLPurifier_Length|string
Definition: Length.php:12
validate($string, $config, $context)
Definition: Length.php:35
parseCDATA($string)
Convenience method that parses a string as if it were CDATA.
Definition: AttrDef.php:60