Completed
Push — master ( 14d45a...b068a0 )
by Maurício
07:49
created

ServerCollationsController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 27
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 27
rs 9.7998
c 0
b 0
f 0
cc 1
nc 1
nop 6
1
<?php
2
/* vim: set expandtab sw=4 ts=4 sts=4: */
3
/**
4
 * Holds the PhpMyAdmin\Controllers\Server\ServerCollationsController
5
 *
6
 * @package PhpMyAdmin\Controllers
7
 */
8
declare(strict_types=1);
9
10
namespace PhpMyAdmin\Controllers\Server;
11
12
use PhpMyAdmin\Charsets;
13
use PhpMyAdmin\Controllers\Controller;
14
use PhpMyAdmin\DatabaseInterface;
15
use PhpMyAdmin\Response;
16
17
/**
18
 * Handles viewing character sets and collations
19
 *
20
 * @package PhpMyAdmin\Controllers
21
 */
22
class ServerCollationsController extends Controller
23
{
24
    /**
25
     * @var array|null
26
     */
27
    private $charsets;
28
29
    /**
30
     * @var array|null
31
     */
32
    private $charsetsDescriptions;
33
34
    /**
35
     * @var array|null
36
     */
37
    private $collations;
38
39
    /**
40
     * @var array|null
41
     */
42
    private $defaultCollations;
43
44
    /**
45
     * ServerCollationsController constructor.
46
     *
47
     * @param Response          $response             Response object
48
     * @param DatabaseInterface $dbi                  DatabaseInterface object
49
     * @param array|null        $charsets             Array of charsets
50
     * @param array|null        $charsetsDescriptions Array of charsets descriptions
51
     * @param array|null        $collations           Array of collations
52
     * @param array|null        $defaultCollations    Array of default collations
53
     */
54
    public function __construct(
55
        $response,
56
        $dbi,
57
        ?array $charsets = null,
58
        ?array $charsetsDescriptions = null,
59
        ?array $collations = null,
60
        ?array $defaultCollations = null
61
    ) {
62
        global $cfg;
63
64
        parent::__construct($response, $dbi);
65
66
        $this->charsets = $charsets ?? Charsets::getMySQLCharsets(
67
            $this->dbi,
68
            $cfg['Server']['DisableIS']
69
        );
70
        $this->charsetsDescriptions = $charsetsDescriptions ?? Charsets::getMySQLCharsetsDescriptions(
71
            $this->dbi,
72
            $cfg['Server']['DisableIS']
73
        );
74
        $this->collations = $collations ?? Charsets::getMySQLCollations(
75
            $this->dbi,
76
            $cfg['Server']['DisableIS']
77
        );
78
        $this->defaultCollations = $defaultCollations ?? Charsets::getMySQLCollationsDefault(
79
            $this->dbi,
80
            $cfg['Server']['DisableIS']
81
        );
82
    }
83
84
    /**
85
     * Index action
86
     *
87
     * @return string HTML
88
     */
89
    public function indexAction(): string
90
    {
91
        include_once ROOT_PATH . 'libraries/server_common.inc.php';
92
93
        $charsets = [];
94
        foreach ($this->charsets as $charset) {
95
            $charsetCollations = [];
96
            foreach ($this->collations[$charset] as $collation) {
97
                $charsetCollations[] = [
98
                    'name' => $collation,
99
                    'description' => Charsets::getCollationDescr($collation),
100
                    'is_default' => $collation === $this->defaultCollations[$charset],
101
                ];
102
            }
103
104
            $charsets[] = [
105
                'name' => $charset,
106
                'description' => $this->charsetsDescriptions[$charset] ?? '',
107
                'collations' => $charsetCollations,
108
            ];
109
        }
110
111
        return $this->template->render('server/collations/index', [
112
            'charsets' => $charsets,
113
        ]);
114
    }
115
}
116