PluginProbe
seQura / 4.3.3
seQura v4.3.3
4.3.4 4.3.3 4.3.2 4.3.1 trunk 2.0.0 2.0.10 2.0.11 2.0.12 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 3.0.0 3.0.2 3.0.5 3.0.6 3.0.7 3.1.0 3.1.1 3.2.0 3.2.1 3.2.2 4.0.0 All 30 releases
sequra / src / Dto / class-table-index.php

class-table-index.php in seQura 4.3.3, at src/Dto/class-table-index.php

55 lines 1.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Table Index.
4 *
5 * @package SeQura/WC
6 */
7
8 namespace SeQura\WC\Dto;
9
10 /**
11 * Table Index.
12 */
13 class Table_Index extends Dto {
14
15 /**
16 * Unique identifier
17 *
18 * @var string
19 */
20 public $name;
21
22 /**
23 * Columns to be indexed
24 *
25 * @var Table_Index_Column[]
26 */
27 public $columns;
28
29 /**
30 * Constructor
31 *
32 * @param string $name The name of the index.
33 * @param Table_Index_Column[] $columns The columns to be indexed.
34 */
35 public function __construct( string $name, array $columns ) {
36 $this->name = $name;
37 $this->columns = $columns;
38 }
39
40 /**
41 * Generate SQL definition for the index.
42 *
43 * @return string SQL statement to create the index.
44 */
45 public function to_sql() {
46 $index_name = \sanitize_key( $this->name );
47 $columns = array();
48 foreach ( $this->columns as $column ) {
49 $columns[] = '`' . \sanitize_key( $column->name ) . '`' . ( null !== $column->char_limit ? "({$column->char_limit})" : '' );
50 }
51 $columns = implode( ', ', $columns );
52 return "INDEX `{$index_name}` ({$columns})";
53 }
54 }
55