Translated using Weblate (Russian)
[phpmyadmin.git] / src / IndexColumn.php
blob1201d6684c921f8b3339ba20018473b8060b83f0
1 <?php
3 declare(strict_types=1);
5 namespace PhpMyAdmin;
7 use function __;
9 /**
10 * Index column wrapper
12 class IndexColumn
14 /** @var string The column name */
15 private string $name = '';
17 /** @var int The column sequence number in the index, starting with 1. */
18 private int $seqInIndex = 1;
20 /** @var string|null How the column is sorted in the index. "A" (Ascending) or NULL (Not sorted) */
21 private string|null $collation = null;
23 /**
24 * The number of indexed characters if the column is only partly indexed,
25 * NULL if the entire column is indexed.
27 private int|null $subPart = null;
29 /**
30 * Contains YES if the column may contain NULL.
31 * If not, the column contains NO.
33 private string $null = '';
35 /**
36 * An estimate of the number of unique values in the index. This is updated
37 * by running ANALYZE TABLE or myisamchk -a. Cardinality is counted based on
38 * statistics stored as integers, so the value is not necessarily exact even
39 * for small tables. The higher the cardinality, the greater the chance that
40 * MySQL uses the index when doing joins.
42 private int|null $cardinality = null;
44 /**
45 * If the Index uses an expression and not a name
47 private string|null $expression = null;
49 /** @param mixed[] $params an array containing the parameters of the index column */
50 public function __construct(array $params = [])
52 $this->set($params);
55 /**
56 * If the Index has an expression
58 public function hasExpression(): bool
60 return $this->expression !== null;
63 /**
64 * The Index expression if it has one
66 public function getExpression(): string|null
68 return $this->expression;
71 /**
72 * Sets parameters of the index column
74 * @param mixed[] $params an array containing the parameters of the index column
76 public function set(array $params): void
78 if (isset($params['Column_name'])) {
79 $this->name = $params['Column_name'];
82 if (isset($params['Seq_in_index'])) {
83 $this->seqInIndex = (int) $params['Seq_in_index'];
86 if (isset($params['Collation'])) {
87 $this->collation = $params['Collation'];
90 if (isset($params['Cardinality'])) {
91 $this->cardinality = (int) $params['Cardinality'];
94 if (isset($params['Sub_part'])) {
95 $this->subPart = (int) $params['Sub_part'];
98 if (isset($params['Expression'])) {
99 $this->expression = $params['Expression'];
102 if (! isset($params['Null'])) {
103 return;
106 $this->null = $params['Null'];
110 * Returns the column name
112 * @return string column name
114 public function getName(): string
116 return $this->name;
120 * Return the column collation
122 * @return string|null column collation
124 public function getCollation(): string|null
126 return $this->collation;
130 * Returns the cardinality of the column
132 * @return int|null cardinality of the column
134 public function getCardinality(): int|null
136 return $this->cardinality;
140 * Returns whether the column is nullable
142 * @param bool $asText whether to returned the string representation
144 * @return string nullability of the column. True/false or Yes/No depending
145 * on the value of the $as_text parameter
147 public function getNull(bool $asText = false): string
149 if ($asText) {
150 if ($this->null === '' || $this->null === 'NO') {
151 return __('No');
154 return __('Yes');
157 return $this->null;
161 * Returns the sequence number of the column in the index
163 * @return int sequence number of the column in the index
165 public function getSeqInIndex(): int
167 return $this->seqInIndex;
171 * Returns the number of indexed characters if the column is only
172 * partly indexed
174 * @return int|null the number of indexed characters
176 public function getSubPart(): int|null
178 return $this->subPart;
182 * Gets the properties in an array for comparison purposes
184 * @return array<string, int|string|null>
185 * @psalm-return array{
186 * Column_name: string,
187 * Seq_in_index: int,
188 * Collation: string|null,
189 * Sub_part: int|null,
190 * Null: string
193 public function getCompareData(): array
195 return [
196 'Column_name' => $this->name,
197 'Seq_in_index' => $this->seqInIndex,
198 'Collation' => $this->collation,
199 'Sub_part' => $this->subPart,
200 'Null' => $this->null,