Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
134 lines (115 loc) · 3.56 KB

File metadata and controls

134 lines (115 loc) · 3.56 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php
declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Components;
use PhpMyAdmin\SqlParser\Component;
use function array_merge_recursive;
use function implode;
use function is_array;
use function strcasecmp;
final class OptionsArray implements Component
{
/**
* @param array<int, string|array<string, string|bool|null>> $options $options The array of options.
* Options that have a value must be an array with at least two keys `name` and `expr` or `value`.
* @psalm-param array<int, string|array{
* name: string,
* equals: bool,
* expr: string|Expression,
* value: string|null
* }> $options
*/
public function __construct(public array $options = [])
{
}
public function build(): string
{
if ($this->options === []) {
return '';
}
$options = [];
foreach ($this->options as $option) {
if (! is_array($option)) {
$options[] = $option;
} else {
$options[] = $option['name']
. ($option['equals'] ? '=' : ' ')
. ($option['expr'] !== '' ? $option['expr'] : ($option['value'] ?? ''));
}
}
return implode(' ', $options);
}
public function has(string $key): bool
{
foreach ($this->options as $option) {
if (is_array($option)) {
if (strcasecmp($key, $option['name']) === 0) {
return ($option['value'] ?? '') !== '';
}
} elseif (strcasecmp($key, $option) === 0) {
return true;
}
}
return false;
}
/**
* Checks if it has the specified option and returns its value.
*
* @param string $key the key to be checked
* @param bool $getExpr Gets the expression instead of the value.
* The value is the processed form of the expression.
*/
public function get(string $key, bool $getExpr = false): string|Expression
{
foreach ($this->options as $option) {
if (is_array($option)) {
if (strcasecmp($key, $option['name']) === 0) {
return $getExpr ? $option['expr'] : ($option['value'] ?? '');
}
} elseif (strcasecmp($key, $option) === 0) {
return $option;
}
}
return '';
}
/**
* Removes the option from the array.
*
* @param string $key the key to be removed
*
* @return bool whether the key was found and deleted or not
*/
public function remove(string $key): bool
{
foreach ($this->options as $idx => $option) {
if (is_array($option)) {
if (strcasecmp($key, $option['name']) === 0) {
unset($this->options[$idx]);
return true;
}
} elseif (strcasecmp($key, $option) === 0) {
unset($this->options[$idx]);
return true;
}
}
return false;
}
/**
* Merges the specified options with these ones. Values with same ID will be
* replaced.
*/
public function merge(OptionsArray $options): void
{
$this->options = array_merge_recursive($this->options, $options->options);
}
/**
* Checks tf there are no options set.
*/
public function isEmpty(): bool
{
return $this->options === [];
}
public function __toString(): string
{
return $this->build();
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.