Validator/Constraint/UniqueDocumentValidator.php
public function isValid($value, Constraint $constraint)
    {
        $document = $this->parseDocument($value);
        $fields = $this->parseFields($constraint->fields);
        $caseInsensitive = $this->parseCaseInsensitive($constraint->caseInsensitive);

        $query = $this->createQuery($document, $fields, $caseInsensitive);
        $numberResults = $query->count();

        if (0 === $numberResults) {
            return true;
        }

        if (1 === $numberResults) {
            $result = $query->one();
            if ($result === $document) {
                return true;
            }
        }

        if ($this->context) {
            $this->addFieldViolation($fields[0], $constraint->message);
        }

        return false;
    }
public function isValid($value, Constraint $constraint)
    {
        $document = $this->parseDocument($value);
        $fields = $this->parseFields($constraint->fields);
        $caseInsensitive = $this->parseCaseInsensitive($constraint->caseInsensitive);

        $query = $this->createQuery($document, $fields, $caseInsensitive);
        $numberResults = $query->count();

        if (0 === $numberResults) {
            return true;
        }

        if (1 === $numberResults) {
            $result = $query->one();
            if ($result === $document) {
                return true;
            }
        }

        if ($this->context) {
            $this->addFieldViolation($fields[0], $constraint->message);
        }

        return false;
    }
public function isValid ( $ value , Constraint $ constraint ) { $ document = $ this -> parseDocument ( $ value ) ; $ fields = $ this -> parseFields ( $ constraint -> fields ) ; $ caseInsensitive = $ this -> parseCaseInsensitive ( $ constraint -> caseInsensitive ) ; $ query = $ this -> createQuery ( $ document , $ fields , $ caseInsensitive ) ; $ numberResults = $ query -> count ( ) ; if ( 0 === $ numberResults ) { return true ; } if ( 1 === $ numberResults ) { $ result = $ query -> one ( ) ; if ( $ result === $ document ) { return true ; } } if ( $ this -> context ) { $ this -> addFieldViolation ( $ fields [ 0 ] , $ constraint -> message ) ; } return false ; }
Validates the document uniqueness.

@param value      $value   The document.
@param Constraint $constraint The constraint.

@return Boolean Whether or not the document is unique.
Validates the document uniqueness .