. */ /** * Tests against a list of values. * * @since 4.6.0 * @package Validator */ namespace Textpattern\Validator; class ChoiceConstraint extends Constraint { /** * Constructor. * * @param mixed $value * @param array $options */ public function __construct($value, $options = array()) { $options = lAtts(array('choices' => array(), 'allow_blank' => false, 'message' => 'unknown_choice'), $options, false); parent::__construct($value, $options); } /** * Validates. * * @return bool */ public function validate() { return ($this->options['allow_blank'] && ('' === $this->value)) || in_array($this->value, $this->options['choices']); } }