symfony “not” Validator

One of the projects that I’m currently working on for a client is being built in symfony, the PHP5 framework. I am working in version 1.1 of the framework, which has a new Forms handling system that uses the concept of widgets and validators to handle interacting with most form elements. I had a need to ensure that certain fields did not contain certain values. Although this could be done with the regular expression validator that comes bundled with symfony (sfValidatorRegex), I decided to write my own validator specifically for this purpose.

This validator may be used in conjunction with sfValidatorAnd() or other constructs, and just allows you to quickly and easily ensure that a field does not contain a value (or an array of values).

/**
 * validatorNot verifies that an input value is NOT some other value.
 *
 * @author     Beau Lebens <beau@dentedreality.com.au>
 */
class validatorNot extends sfValidatorBase {
  protected $not;

  /**
	 * Configures the validator
	 * 
	 * Available Options:
	 * 
	 *  * not: The value or array of values that the input value should NOT be.
	 * 
	 * Available Error Codes:
	 * 
	 *  * not
	 * 
	 * @param $options Array of options
	 * @param $messages Array of error messages
	 * 
	 * @see sfValidatorBase
	 *
	 */
  protected function configure($options = array(), $messages = array()) {
    parent::configure($options, $messages);
  	$this->addRequiredOption('not');
    $this->addMessage('not', '\'%not%\' is not allowed.');
    $this->not = $options['not'];
  }

  /**
   * Compares $value to the restricted/denied value
   *
   * @param  mixed $value  The input value
   *
   * @return mixed The cleaned value
   *
   * @throws sfValidatorError
   */
	protected function doClean($value) {
		if (!is_array($this->not)) {
      $not = array($this->not);
		} else {
			$not = $this->not;
		}
		foreach ($not as $n) {
			if ($value == $n) {
				throw new sfValidatorError($this, 'not', array('not'=>$n));
			}
		}
		return $value;
	}

	/**
	 * Access the "not" value
	 *
	 * @return mixed value this field may not equal
	 */
	public function getNot() {
		return $this->not;
	}
}