ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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
Represents a Length as defined by CSS.
Definition: Length.php:7
__construct($min=null, $max=null)
Definition: Length.php:23
$max
@type HTMLPurifier_Length|string
Definition: Length.php:17
$min
@type HTMLPurifier_Length|string
Definition: Length.php:12
validate($string, $config, $context)
Definition: Length.php:35
Base class for all validating attribute definitions.
Definition: AttrDef.php:14
parseCDATA($string)
Convenience method that parses a string as if it were CDATA.
Definition: AttrDef.php:60
static make($s)
Definition: Length.php:52