/** * @param IndexInterface $index * @return $this */ public function &addIndex(IndexInterface $index) { if (empty($this->indexes[$index->getName()])) { $this->indexes[$index->getName()] = $index; } else { throw new InvalidArgumentException("Index '" . $index->getName() . "' already exists in this type"); } return $this; }
/** * Prepare index statement. * * @param IndexInterface $index * @return string */ public function prepareIndexStatement(IndexInterface $index) { switch ($index->getIndexType()) { case IndexInterface::PRIMARY: $result = 'PRIMARY KEY'; break; case IndexInterface::UNIQUE: $result = 'UNIQUE ' . $this->getConnection()->escapeFieldName($index->getName()); break; case IndexInterface::FULLTEXT: $result = 'FULLTEXT ' . $this->getConnection()->escapeFieldName($index->getName()); break; default: $result = 'INDEX ' . $this->getConnection()->escapeFieldName($index->getName()); break; } return $result . ' (' . implode(', ', array_map(function ($field_name) { return $this->getConnection()->escapeFieldName($field_name); }, $index->getFields())) . ')'; }