Composite.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. /**
  3. * Allows multiple validators to attempt to validate attribute.
  4. *
  5. * Composite is just what it sounds like: a composite of many validators.
  6. * This means that multiple HTMLPurifier_AttrDef objects will have a whack
  7. * at the string. If one of them passes, that's what is returned. This is
  8. * especially useful for CSS values, which often are a choice between
  9. * an enumerated set of predefined values or a flexible data type.
  10. */
  11. class HTMLPurifier_AttrDef_CSS_Composite extends HTMLPurifier_AttrDef
  12. {
  13. /**
  14. * List of HTMLPurifier_AttrDef objects that may process strings
  15. * @todo Make protected
  16. */
  17. public $defs;
  18. /**
  19. * @param $defs List of HTMLPurifier_AttrDef objects
  20. */
  21. public function __construct($defs) {
  22. $this->defs = $defs;
  23. }
  24. public function validate($string, $config, $context) {
  25. foreach ($this->defs as $i => $def) {
  26. $result = $this->defs[$i]->validate($string, $config, $context);
  27. if ($result !== false) return $result;
  28. }
  29. return false;
  30. }
  31. }
  32. // vim: et sw=4 sts=4