Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ListAbstract.php « classes « libraries - github.com/phpmyadmin/phpmyadmin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d8c8fe3dbcbf5ba72ed4d9f59ca697742a02895e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php

declare(strict_types=1);

namespace PhpMyAdmin;

use ArrayObject;
use PhpMyAdmin\Query\Utilities;

use function in_array;

/**
 * @extends ArrayObject<int, string>
 */
abstract class ListAbstract extends ArrayObject
{
    /** @var mixed   empty item */
    protected $itemEmpty = '';

    /**
     * defines what is an empty item (0, '', false or null)
     *
     * @return mixed   an empty item
     */
    public function getEmpty()
    {
        return $this->itemEmpty;
    }

    /**
     * checks if the given db names exists in the current list, if there is
     * missing at least one item it returns false otherwise true
     *
     * @param mixed[] ...$params params
     */
    public function exists(...$params): bool
    {
        $this_elements = $this->getArrayCopy();
        foreach ($params as $result) {
            if (! in_array($result, $this_elements)) {
                return false;
            }
        }

        return true;
    }

    /**
     * @return array<int, array<string, bool|string>>
     */
    public function getList(): array
    {
        $selected = $this->getDefault();

        $list = [];
        foreach ($this as $eachItem) {
            if (Utilities::isSystemSchema($eachItem)) {
                continue;
            }

            $list[] = [
                'name' => $eachItem,
                'is_selected' => $selected === $eachItem,
            ];
        }

        return $list;
    }

    /**
     * returns default item
     *
     * @return string  default item
     */
    public function getDefault()
    {
        return $this->getEmpty();
    }

    /**
     * builds up the list
     */
    abstract public function build(): void;
}