ILIAS  release_4-4 Revision
All Data Structures Namespaces Files Functions Variables Modules Pages
Length.php
Go to the documentation of this file.
1 <?php
2 
7 {
8 
9  protected $min, $max;
10 
15  public function __construct($min = null, $max = null) {
16  $this->min = $min !== null ? HTMLPurifier_Length::make($min) : null;
17  $this->max = $max !== null ? HTMLPurifier_Length::make($max) : null;
18  }
19 
20  public function validate($string, $config, $context) {
21  $string = $this->parseCDATA($string);
22 
23  // Optimizations
24  if ($string === '') return false;
25  if ($string === '0') return '0';
26  if (strlen($string) === 1) return false;
27 
28  $length = HTMLPurifier_Length::make($string);
29  if (!$length->isValid()) return false;
30 
31  if ($this->min) {
32  $c = $length->compareTo($this->min);
33  if ($c === false) return false;
34  if ($c < 0) return false;
35  }
36  if ($this->max) {
37  $c = $length->compareTo($this->max);
38  if ($c === false) return false;
39  if ($c > 0) return false;
40  }
41 
42  return $length->toString();
43  }
44 
45 }
46 
47 // vim: et sw=4 sts=4
__construct($min=null, $max=null)
Definition: Length.php:15
Base class for all validating attribute definitions.
Definition: AttrDef.php:13
Represents a Length as defined by CSS.
Definition: Length.php:6
static make($s)
Definition: Length.php:46
validate($string, $config, $context)
Definition: Length.php:20
parseCDATA($string)
Convenience method that parses a string as if it were CDATA.
Definition: AttrDef.php:58