yii\db\mysql\Schema::findUniqueIndexes PHP Method

findUniqueIndexes() public method

Each array element is of the following structure: php [ 'IndexName1' => ['col1' [, ...]], 'IndexName2' => ['col2' [, ...]], ]
public findUniqueIndexes ( yii\db\TableSchema $table ) : array
$table yii\db\TableSchema the table metadata
return array all unique indexes for the given table.
    public function findUniqueIndexes($table)
    {
        $sql = $this->getCreateTableSql($table);
        $uniqueIndexes = [];
        $regexp = '/UNIQUE KEY\\s+([^\\(\\s]+)\\s*\\(([^\\(\\)]+)\\)/mi';
        if (preg_match_all($regexp, $sql, $matches, PREG_SET_ORDER)) {
            foreach ($matches as $match) {
                $indexName = str_replace('`', '', $match[1]);
                $indexColumns = array_map('trim', explode(',', str_replace('`', '', $match[2])));
                $uniqueIndexes[$indexName] = $indexColumns;
            }
        }
        return $uniqueIndexes;
    }