|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by Gorlum 04.10.2017 8:55 |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
namespace DBAL; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Class DbIndexDescription |
|
10
|
|
|
* @package DBAL |
|
11
|
|
|
* |
|
12
|
|
|
* Objects of this class contains MySql index description |
|
13
|
|
|
*/ |
|
14
|
|
|
class DbIndexDescription { |
|
15
|
|
|
public $Key_name = ''; // Key_name - The name of the index. If the index is the primary key, the name is always PRIMARY. |
|
16
|
|
|
public $Non_unique = 1; // 0 if the index cannot contain duplicates, 1 if it can. |
|
17
|
|
|
|
|
18
|
|
|
public $Packed = null; // Indicates how the key is packed. NULL if it is not. |
|
19
|
|
|
public $Index_type = 'BTREE'; // The index method used (BTREE, FULLTEXT, HASH, RTREE). |
|
20
|
|
|
public $Comment = ''; // Information about the index not described in its own column, such as disabled if the index is disabled. |
|
21
|
|
|
public $Index_comment = ''; // Any comment provided for the index with a COMMENT attribute when the index was created. |
|
22
|
|
|
public $Visible; // Whether the index is visible to the optimizer. See Section 8.3.12, “Invisible Indexes”. |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var DbIndexField[] |
|
26
|
|
|
*/ |
|
27
|
|
|
public $fields = []; |
|
28
|
|
|
|
|
29
|
|
|
protected $sorted = true; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @param array $indexField |
|
33
|
|
|
* |
|
34
|
|
|
* @return $this |
|
35
|
|
|
*/ |
|
36
|
|
|
public function addField($indexField) { |
|
37
|
|
|
$this->Key_name = isset($indexField['Key_name']) ? $indexField['Key_name'] : null; |
|
38
|
|
|
$this->Non_unique = isset($indexField['Non_unique']) ? $indexField['Non_unique'] : null; |
|
39
|
|
|
$this->Packed = isset($indexField['Packed']) ? $indexField['Packed'] : null; |
|
40
|
|
|
$this->Index_type = isset($indexField['Index_type']) ? $indexField['Index_type'] : null; |
|
41
|
|
|
$this->Comment = isset($indexField['Comment']) ? $indexField['Comment'] : null; |
|
42
|
|
|
$this->Index_comment = isset($indexField['Index_comment']) ? $indexField['Index_comment'] : null; |
|
43
|
|
|
$this->Visible = isset($indexField['Visible']) ? $indexField['Visible'] : null; |
|
44
|
|
|
|
|
45
|
|
|
if (isset($indexField['Column_name']) || isset($indexField['Expression'])) { |
|
46
|
|
|
$fullName = $indexField['Column_name'] . |
|
47
|
|
|
(!empty($indexField['Expression']) ? '|' . $indexField['Expression'] : ''); |
|
48
|
|
|
|
|
49
|
|
|
$this->fields[$fullName] = new DbIndexField($indexField); |
|
50
|
|
|
$this->sorted = false; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
return $this; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @return string |
|
58
|
|
|
*/ |
|
59
|
|
|
public function signature() { |
|
60
|
|
|
$this->sort(); |
|
61
|
|
|
|
|
62
|
|
|
|
|
63
|
|
|
return implode(',', array_keys($this->fields)); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
protected function sort() { |
|
67
|
|
|
if (!$this->sorted) { |
|
68
|
|
|
asort($this->fields, function (DbIndexField $a, DbIndexField $b) { |
|
|
|
|
|
|
69
|
|
|
return $a->Seq_in_index - $b->Seq_in_index; |
|
70
|
|
|
}); |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
} |
|
75
|
|
|
|