public function createUniqueConstraint($label, $property, $removeIndexIfExist = false)
    {
        $statements = [];
        $identifier = strtolower($label);
        if (is_array($property)) {
            foreach ($property as $prop) {
                $statements[] = 'CREATE CONSTRAINT ON ('.$identifier.':'.$label.') ASSERT '.$identifier.'.'.$prop.' IS UNIQUE';
            }
        } else {
            $statements[] = 'CREATE CONSTRAINT ON ('.$identifier.':'.$label.') ASSERT '.$identifier.'.'.$property.' IS UNIQUE';
        }
        foreach ($statements as $statement) {
            try {
                $this->sendCypherQuery($statement);
            } catch (Neo4jException $e) {
                if (true === $removeIndexIfExist && 8000 === $e->getCode() && !is_array($property)) {
                    $this->dropIndex($label, $property);

                    return $this->createUniqueConstraint($label, $property);
                }
                throw($e);
            }
        }

        return true;
    }
public function createUniqueConstraint($label, $property, $removeIndexIfExist = false)
    {
        $statements = [];
        $identifier = strtolower($label);
        if (is_array($property)) {
            foreach ($property as $prop) {
                $statements[] = 'CREATE CONSTRAINT ON ('.$identifier.':'.$label.') ASSERT '.$identifier.'.'.$prop.' IS UNIQUE';
            }
        } else {
            $statements[] = 'CREATE CONSTRAINT ON ('.$identifier.':'.$label.') ASSERT '.$identifier.'.'.$property.' IS UNIQUE';
        }
        foreach ($statements as $statement) {
            try {
                $this->sendCypherQuery($statement);
            } catch (Neo4jException $e) {
                if (true === $removeIndexIfExist && 8000 === $e->getCode() && !is_array($property)) {
                    $this->dropIndex($label, $property);

                    return $this->createUniqueConstraint($label, $property);
                }
                throw($e);
            }
        }

        return true;
    }
public function createUniqueConstraint ( $ label , $ property , $ removeIndexIfExist = false ) { $ statements = [ ] ; $ identifier = strtolower ( $ label ) ; if ( is_array ( $ property ) ) { foreach ( $ property as $ prop ) { $ statements [ ] = 'CREATE CONSTRAINT ON (' . $ identifier . ':' . $ label . ') ASSERT ' . $ identifier . '.' . $ prop . ' IS UNIQUE' ; } } else { $ statements [ ] = 'CREATE CONSTRAINT ON (' . $ identifier . ':' . $ label . ') ASSERT ' . $ identifier . '.' . $ property . ' IS UNIQUE' ; } foreach ( $ statements as $ statement ) { try { $ this -> sendCypherQuery ( $ statement ) ; } catch ( Neo4jException $ e ) { if ( true === $ removeIndexIfExist && 8000 === $ e -> getCode ( ) && ! is_array ( $ property ) ) { $ this -> dropIndex ( $ label , $ property ) ; return $ this -> createUniqueConstraint ( $ label , $ property ) ; } throw ( $ e ) ; } } return true ; }
Create a unique constraint on a label.

@param string       $label
@param string|array $property

@return bool
Create a unique constraint on a label .