You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 line
1.3KB

  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 objects that may process strings.
  15. * @type HTMLPurifier_AttrDef[]
  16. * @todo Make protected
  17. */
  18. public $defs;
  19. /**
  20. * @param HTMLPurifier_AttrDef[] $defs List of HTMLPurifier_AttrDef objects
  21. */
  22. public function __construct($defs)
  23. {
  24. $this->defs = $defs;
  25. }
  26. /**
  27. * @param string $string
  28. * @param HTMLPurifier_Config $config
  29. * @param HTMLPurifier_Context $context
  30. * @return bool|string
  31. */
  32. public function validate($string, $config, $context)
  33. {
  34. foreach ($this->defs as $i => $def) {
  35. $result = $this->defs[$i]->validate($string, $config, $context);
  36. if ($result !== false) {
  37. return $result;
  38. }
  39. }
  40. return false;
  41. }
  42. }
  43. // vim: et sw=4 sts=4