public function addIndex($type, ...$columns) {
        if (empty($columns)) {
            throw new \InvalidArgumentException("An index must contain at least one column.", 500);
        }

        $type = strtolower($type);

        // Look for a current index row.
        $currentIndex = null;
        foreach ($this->indexes as $i => $index) {
            if ($type !== $index['type']) {
                continue;
            }

            if ($type === Db::INDEX_PK || array_diff($index['columns'], $columns) == []) {
                $currentIndex =& $this->indexes[$i];
                break;
            }
        }

        if ($currentIndex) {
            $currentIndex['columns'] = $columns;
        } else {
            $indexDef = [
                'type' => $type,
                'columns' => $columns,
            ];
            $this->indexes[] = $indexDef;
        }

        return $this;
    }
public function addIndex($type, ...$columns) {
        if (empty($columns)) {
            throw new \InvalidArgumentException("An index must contain at least one column.", 500);
        }

        $type = strtolower($type);

        // Look for a current index row.
        $currentIndex = null;
        foreach ($this->indexes as $i => $index) {
            if ($type !== $index['type']) {
                continue;
            }

            if ($type === Db::INDEX_PK || array_diff($index['columns'], $columns) == []) {
                $currentIndex =& $this->indexes[$i];
                break;
            }
        }

        if ($currentIndex) {
            $currentIndex['columns'] = $columns;
        } else {
            $indexDef = [
                'type' => $type,
                'columns' => $columns,
            ];
            $this->indexes[] = $indexDef;
        }

        return $this;
    }
public function addIndex ( $ type , ... $ columns ) { if ( empty ( $ columns ) ) { throw new \ InvalidArgumentException ( "An index must contain at least one column." , 500 ) ; } $ type = strtolower ( $ type ) ; // Look for a current index row. $ currentIndex = null ; foreach ( $ this -> indexes as $ i => $ index ) { if ( $ type !== $ index [ 'type' ] ) { continue ; } if ( $ type === Db :: INDEX_PK || array_diff ( $ index [ 'columns' ] , $ columns ) == [ ] ) { $ currentIndex = & $ this -> indexes [ $ i ] ; break ; } } if ( $ currentIndex ) { $ currentIndex [ 'columns' ] = $ columns ; } else { $ indexDef = [ 'type' => $ type , 'columns' => $ columns , ] ; $ this -> indexes [ ] = $ indexDef ; } return $ this ; }
Add or update an index.

@param string $type One of the `Db::INDEX_*` constants.
@param string ...$columns The columns in the index.
@return $this
Add or update an index .