プロパティが別のプロパティと等しくないことを検証するために、 Symfony 2カスタムクラス制約バリデーターを作成する必要があります(つまり、パスワードがユーザー名と一致しません)。
私の最初の質問は、メソッドを実装する必要がありgetDefaultOption()、何に使用されるのかということです。
/**
 * @Annotation
 */
class NotEqualTo extends Constraint
{
    /**
     * @var string
     */
    public $message = "{{ property1 }} should not be equal to {{ property2 }}.";
    /**
     * @var string
     */
    public $property1;
    /**
     * @var string
     */
    public $property2;
    /**
     * {@inheritDoc}
     */
    public function getRequiredOptions() { return ['property1', 'property2']; }
    /**
     * {@inheritDoc}
     */
    public function getTargets() { return self::CLASS_CONSTRAINT; }
}
2番目の質問は、メソッドで実際のオブジェクト(「property1」と「property2」をチェックするため)を取得するにはどうすればよいvalidate()ですか?
public function validate($value, Constraint $constraint)
{
    if(null === $value || '' === $value) {
        return;
    }
    if (!is_string($constraint->property1)) {
        throw new UnexpectedTypeException($constraint->property1, 'string');
    }
    if (!is_string($constraint->property2)) {
        throw new UnexpectedTypeException($constraint->property2, 'string');
    }
    // Get the actual value of property1 and property2 in the object
    // Check for equality
    if($object->property1 === $object->property2) {
        $this->context->addViolation($constraint->message, [
            '{{ property1 }}' => $constraint->property1,
            '{{ property2 }}' => $constraint->property2,
        ]);
    }
}