getReducedIndexName($type, $columns, self::MAX_FRAGMENT_INDEX_LEGNTH); return str_replace(['-', '.'], '_', $index); } private function getReducedIndexName($type, array $columns, int $fragmentLength) { $table = null; foreach($columns as $key => $value) { $column = null; foreach(explode('_', $value) as $explode) { $column .= substr($explode, 0, $fragmentLength) . '_'; } $columns[$key] = rtrim($column, '_'); } foreach(explode('_', $this->table) as $explode) { $table .= substr($explode, 0, $fragmentLength) . '_'; } $index = strtolower($this->prefix.rtrim($table, '_').'_'.implode('_', $columns).'_'.$type); if (strlen($index) > self::MAX_INDEX_NAME_LENGTH) { $newFragmentLength = $fragmentLength - 1; if ($newFragmentLength < self::MIN_FRAGMENT_INDEX_LEGNTH) { throw new \Exception("An error has occurred while reducing the length of the index. " . "Please, name it manually.\nThe last try result in: {$index}."); } return $this->getReducedIndexName($type, $columns, $newFragmentLength); } return $index; } }