ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
Multiple.php
Go to the documentation of this file.
1 <?php
2 
15 {
21  public $single;
22 
27  public $max;
28 
33  public function __construct($single, $max = 4)
34  {
35  $this->single = $single;
36  $this->max = $max;
37  }
38 
45  public function validate($string, $config, $context)
46  {
47  $string = $this->mungeRgb($this->parseCDATA($string));
48  if ($string === '') {
49  return false;
50  }
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;
57  }
58  $result = $this->single->validate($parts[$i], $config, $context);
59  if ($result !== false) {
60  $final .= $result . ' ';
61  $num++;
62  }
63  }
64  if ($final === '') {
65  return false;
66  }
67  return rtrim($final);
68  }
69 }
70 
71 // vim: et sw=4 sts=4
__construct($single, $max=4)
Definition: Multiple.php:33
Base class for all validating attribute definitions.
Definition: AttrDef.php:13
$single
Instance of component definition to defer validation to.
Definition: Multiple.php:21
$result
$max
Max number of values allowed.
Definition: Multiple.php:27
parseCDATA($string)
Convenience method that parses a string as if it were CDATA.
Definition: AttrDef.php:60
mungeRgb($string)
Removes spaces from rgb(0, 0, 0) so that shorthand CSS properties work properly.
Definition: AttrDef.php:87
$i
Definition: disco.tpl.php:19
Framework class for strings that involve multiple values.
Definition: Multiple.php:14
validate($string, $config, $context)
Definition: Multiple.php:45