public function addIndex($index)
    {
        if ($index instanceof Index) {
            if ($this->hasIndex($index->getName())) {
                throw new InvalidArgumentException(sprintf('Index "%s" already exist.', $index->getName()));
            }
            if (!$index->getColumns()) {
                throw new InvalidArgumentException(sprintf('Index "%s" has no columns.', $index->getName()));
            }
            $index->setTable($this);
            // force the name to be created if empty.
            $this->indices[] = $index;

            return $index;
        }

        $idx = new Index();
        $idx->loadMapping($index);
        foreach((array)@$index['columns'] as $column) {
            $idx->addColumn($column);
        }

        return $this->addIndex($idx);
    }
public function addIndex($index)
    {
        if ($index instanceof Index) {
            if ($this->hasIndex($index->getName())) {
                throw new InvalidArgumentException(sprintf('Index "%s" already exist.', $index->getName()));
            }
            if (!$index->getColumns()) {
                throw new InvalidArgumentException(sprintf('Index "%s" has no columns.', $index->getName()));
            }
            $index->setTable($this);
            // force the name to be created if empty.
            $this->indices[] = $index;

            return $index;
        }

        $idx = new Index();
        $idx->loadMapping($index);
        foreach((array)@$index['columns'] as $column) {
            $idx->addColumn($column);
        }

        return $this->addIndex($idx);
    }
public function addIndex ( $ index ) { if ( $ index instanceof Index ) { if ( $ this -> hasIndex ( $ index -> getName ( ) ) ) { throw new InvalidArgumentException ( sprintf ( 'Index "%s" already exist.' , $ index -> getName ( ) ) ) ; } if ( ! $ index -> getColumns ( ) ) { throw new InvalidArgumentException ( sprintf ( 'Index "%s" has no columns.' , $ index -> getName ( ) ) ) ; } $ index -> setTable ( $ this ) ; // force the name to be created if empty. $ this -> indices [ ] = $ index ; return $ index ; } $ idx = new Index ( ) ; $ idx -> loadMapping ( $ index ) ; foreach ( ( array ) @ $ index [ 'columns' ] as $ column ) { $ idx -> addColumn ( $ column ) ; } return $ this -> addIndex ( $ idx ) ; }
Adds a new index to the indices list and set the
parent table of the column to the current table.

@param  Index|array $index
@return Index

@throw  InvalidArgumentException
Adds a new index to the indices list and set the parent table of the column to the current table .