PSR-2 reformatting PHPDoc corrections
[htmlpurifier.git] / library / HTMLPurifier / AttrDef / CSS / Multiple.php
blob9f266cdd153859abbfaccfc5daf9a9133062e5bc
1 <?php
3 /**
4 * Framework class for strings that involve multiple values.
6 * Certain CSS properties such as border-width and margin allow multiple
7 * lengths to be specified. This class can take a vanilla border-width
8 * definition and multiply it, usually into a max of four.
10 * @note Even though the CSS specification isn't clear about it, inherit
11 * can only be used alone: it will never manifest as part of a multi
12 * shorthand declaration. Thus, this class does not allow inherit.
14 class HTMLPurifier_AttrDef_CSS_Multiple extends HTMLPurifier_AttrDef
16 /**
17 * Instance of component definition to defer validation to.
18 * @type HTMLPurifier_AttrDef
19 * @todo Make protected
21 public $single;
23 /**
24 * Max number of values allowed.
25 * @todo Make protected
27 public $max;
29 /**
30 * @param HTMLPurifier_AttrDef $single HTMLPurifier_AttrDef to multiply
31 * @param int $max Max number of values allowed (usually four)
33 public function __construct($single, $max = 4)
35 $this->single = $single;
36 $this->max = $max;
39 /**
40 * @param string $string
41 * @param HTMLPurifier_Config $config
42 * @param HTMLPurifier_Context $context
43 * @return bool|string
45 public function validate($string, $config, $context)
47 $string = $this->parseCDATA($string);
48 if ($string === '') {
49 return false;
51 $parts = explode(' ', $string); // parseCDATA replaced \r, \t and \n
52 $length = count($parts);
53 $final = '';
54 for ($i = 0, $num = 0; $i < $length && $num < $this->max; $i++) {
55 if (ctype_space($parts[$i])) {
56 continue;
58 $result = $this->single->validate($parts[$i], $config, $context);
59 if ($result !== false) {
60 $final .= $result . ' ';
61 $num++;
64 if ($final === '') {
65 return false;
67 return rtrim($final);
71 // vim: et sw=4 sts=4