LazyRecord\TableParser\SqliteTableDefinitionParser::tryParseTableConstraints PHP Method

tryParseTableConstraints() protected method

protected tryParseTableConstraints ( )
    protected function tryParseTableConstraints()
    {
        $tableConstraints = null;
        while ($tableConstraintKeyword = $this->tryParseKeyword(['PRIMARY', 'UNIQUE', 'CONSTRAINT', 'CHECK', 'FOREIGN'])) {
            $tableConstraint = new stdClass();
            if (in_array($tableConstraintKeyword->val, ['PRIMARY', 'FOREIGN'])) {
                $this->skipSpaces();
                $this->tryParseKeyword(['KEY']);
            }
            if ($tableConstraintKeyword->val == 'PRIMARY') {
                if ($indexColumns = $this->tryParseIndexColumns()) {
                    $tableConstraint->primaryKey = $indexColumns;
                }
            } elseif ($tableConstraintKeyword->val == 'UNIQUE') {
                if ($indexColumns = $this->tryParseIndexColumns()) {
                    $tableConstraint->unique = $indexColumns;
                }
            } elseif ($tableConstraintKeyword->val == 'CONSTRAINT') {
                $this->skipSpaces();
                $constraintName = $this->tryParseIdentifier();
                $tableConstraint->name = $constraintName->val;
            } elseif ($tableConstraintKeyword->val == 'FOREIGN') {
                if ($this->cur() == '(') {
                    $this->advance('(');
                    $tableConstraint->foreignKey = $this->parseColumnNames();
                    if ($this->cur() == ')') {
                        $this->advance(')');
                    } else {
                        throw new Exception('Unexpected token: ' . $this->currentWindow());
                    }
                } else {
                    throw new Exception('Unexpected token: ' . $this->currentWindow());
                }
            }
            $tableConstraints[] = $tableConstraint;
        }
        return $tableConstraints;
    }