PSR-2 reformatting PHPDoc corrections
[htmlpurifier.git] / library / HTMLPurifier / AttrDef / CSS / Length.php
blobf12453a04a74b21e44d7954fe504a96dba85ba7e
1 <?php
3 /**
4 * Represents a Length as defined by CSS.
5 */
6 class HTMLPurifier_AttrDef_CSS_Length extends HTMLPurifier_AttrDef
9 /**
10 * @type HTMLPurifier_Length|string
12 protected $min;
14 /**
15 * @type HTMLPurifier_Length|string
17 protected $max;
19 /**
20 * @param HTMLPurifier_Length|string $min Minimum length, or null for no bound. String is also acceptable.
21 * @param HTMLPurifier_Length|string $max Maximum length, or null for no bound. String is also acceptable.
23 public function __construct($min = null, $max = null)
25 $this->min = $min !== null ? HTMLPurifier_Length::make($min) : null;
26 $this->max = $max !== null ? HTMLPurifier_Length::make($max) : null;
29 /**
30 * @param string $string
31 * @param HTMLPurifier_Config $config
32 * @param HTMLPurifier_Context $context
33 * @return bool|string
35 public function validate($string, $config, $context)
37 $string = $this->parseCDATA($string);
39 // Optimizations
40 if ($string === '') {
41 return false;
43 if ($string === '0') {
44 return '0';
46 if (strlen($string) === 1) {
47 return false;
50 $length = HTMLPurifier_Length::make($string);
51 if (!$length->isValid()) {
52 return false;
55 if ($this->min) {
56 $c = $length->compareTo($this->min);
57 if ($c === false) {
58 return false;
60 if ($c < 0) {
61 return false;
64 if ($this->max) {
65 $c = $length->compareTo($this->max);
66 if ($c === false) {
67 return false;
69 if ($c > 0) {
70 return false;
73 return $length->toString();
77 // vim: et sw=4 sts=4