|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Kint\Object; |
|
4
|
|
|
|
|
5
|
|
|
use InvalidArgumentException; |
|
6
|
|
|
use LogicException; |
|
7
|
|
|
|
|
8
|
|
|
class ColorObject extends BlobObject |
|
|
|
|
|
|
9
|
|
|
{ |
|
10
|
|
|
public static $color_map = array( |
|
|
|
|
|
|
11
|
|
|
'aliceblue' => 'f0f8ff', |
|
12
|
|
|
'antiquewhite' => 'faebd7', |
|
13
|
|
|
'aqua' => '00ffff', |
|
14
|
|
|
'aquamarine' => '7fffd4', |
|
15
|
|
|
'azure' => 'f0ffff', |
|
16
|
|
|
'beige' => 'f5f5dc', |
|
17
|
|
|
'bisque' => 'ffe4c4', |
|
18
|
|
|
'black' => '000000', |
|
19
|
|
|
'blanchedalmond' => 'ffebcd', |
|
20
|
|
|
'blue' => '0000ff', |
|
21
|
|
|
'blueviolet' => '8a2be2', |
|
22
|
|
|
'brown' => 'a52a2a', |
|
23
|
|
|
'burlywood' => 'deb887', |
|
24
|
|
|
'cadetblue' => '5f9ea0', |
|
25
|
|
|
'chartreuse' => '7fff00', |
|
26
|
|
|
'chocolate' => 'd2691e', |
|
27
|
|
|
'coral' => 'ff7f50', |
|
28
|
|
|
'cornflowerblue' => '6495ed', |
|
29
|
|
|
'cornsilk' => 'fff8dc', |
|
30
|
|
|
'crimson' => 'dc143c', |
|
31
|
|
|
'cyan' => '00ffff', |
|
32
|
|
|
'darkblue' => '00008b', |
|
33
|
|
|
'darkcyan' => '008b8b', |
|
34
|
|
|
'darkgoldenrod' => 'b8860b', |
|
35
|
|
|
'darkgray' => 'a9a9a9', |
|
36
|
|
|
'darkgreen' => '006400', |
|
37
|
|
|
'darkgrey' => 'a9a9a9', |
|
38
|
|
|
'darkkhaki' => 'bdb76b', |
|
39
|
|
|
'darkmagenta' => '8b008b', |
|
40
|
|
|
'darkolivegreen' => '556b2f', |
|
41
|
|
|
'darkorange' => 'ff8c00', |
|
42
|
|
|
'darkorchid' => '9932cc', |
|
43
|
|
|
'darkred' => '8b0000', |
|
44
|
|
|
'darksalmon' => 'e9967a', |
|
45
|
|
|
'darkseagreen' => '8fbc8f', |
|
46
|
|
|
'darkslateblue' => '483d8b', |
|
47
|
|
|
'darkslategray' => '2f4f4f', |
|
48
|
|
|
'darkslategrey' => '2f4f4f', |
|
49
|
|
|
'darkturquoise' => '00ced1', |
|
50
|
|
|
'darkviolet' => '9400d3', |
|
51
|
|
|
'deeppink' => 'ff1493', |
|
52
|
|
|
'deepskyblue' => '00bfff', |
|
53
|
|
|
'dimgray' => '696969', |
|
54
|
|
|
'dimgrey' => '696969', |
|
55
|
|
|
'dodgerblue' => '1e90ff', |
|
56
|
|
|
'firebrick' => 'b22222', |
|
57
|
|
|
'floralwhite' => 'fffaf0', |
|
58
|
|
|
'forestgreen' => '228b22', |
|
59
|
|
|
'fuchsia' => 'ff00ff', |
|
60
|
|
|
'gainsboro' => 'dcdcdc', |
|
61
|
|
|
'ghostwhite' => 'f8f8ff', |
|
62
|
|
|
'gold' => 'ffd700', |
|
63
|
|
|
'goldenrod' => 'daa520', |
|
64
|
|
|
'gray' => '808080', |
|
65
|
|
|
'green' => '008000', |
|
66
|
|
|
'greenyellow' => 'adff2f', |
|
67
|
|
|
'grey' => '808080', |
|
68
|
|
|
'honeydew' => 'f0fff0', |
|
69
|
|
|
'hotpink' => 'ff69b4', |
|
70
|
|
|
'indianred' => 'cd5c5c', |
|
71
|
|
|
'indigo' => '4b0082', |
|
72
|
|
|
'ivory' => 'fffff0', |
|
73
|
|
|
'khaki' => 'f0e68c', |
|
74
|
|
|
'lavender' => 'e6e6fa', |
|
75
|
|
|
'lavenderblush' => 'fff0f5', |
|
76
|
|
|
'lawngreen' => '7cfc00', |
|
77
|
|
|
'lemonchiffon' => 'fffacd', |
|
78
|
|
|
'lightblue' => 'add8e6', |
|
79
|
|
|
'lightcoral' => 'f08080', |
|
80
|
|
|
'lightcyan' => 'e0ffff', |
|
81
|
|
|
'lightgoldenrodyellow' => 'fafad2', |
|
82
|
|
|
'lightgray' => 'd3d3d3', |
|
83
|
|
|
'lightgreen' => '90ee90', |
|
84
|
|
|
'lightgrey' => 'd3d3d3', |
|
85
|
|
|
'lightpink' => 'ffb6c1', |
|
86
|
|
|
'lightsalmon' => 'ffa07a', |
|
87
|
|
|
'lightseagreen' => '20b2aa', |
|
88
|
|
|
'lightskyblue' => '87cefa', |
|
89
|
|
|
'lightslategray' => '778899', |
|
90
|
|
|
'lightslategrey' => '778899', |
|
91
|
|
|
'lightsteelblue' => 'b0c4de', |
|
92
|
|
|
'lightyellow' => 'ffffe0', |
|
93
|
|
|
'lime' => '00ff00', |
|
94
|
|
|
'limegreen' => '32cd32', |
|
95
|
|
|
'linen' => 'faf0e6', |
|
96
|
|
|
'magenta' => 'ff00ff', |
|
97
|
|
|
'maroon' => '800000', |
|
98
|
|
|
'mediumaquamarine' => '66cdaa', |
|
99
|
|
|
'mediumblue' => '0000cd', |
|
100
|
|
|
'mediumorchid' => 'ba55d3', |
|
101
|
|
|
'mediumpurple' => '9370db', |
|
102
|
|
|
'mediumseagreen' => '3cb371', |
|
103
|
|
|
'mediumslateblue' => '7b68ee', |
|
104
|
|
|
'mediumspringgreen' => '00fa9a', |
|
105
|
|
|
'mediumturquoise' => '48d1cc', |
|
106
|
|
|
'mediumvioletred' => 'c71585', |
|
107
|
|
|
'midnightblue' => '191970', |
|
108
|
|
|
'mintcream' => 'f5fffa', |
|
109
|
|
|
'mistyrose' => 'ffe4e1', |
|
110
|
|
|
'moccasin' => 'ffe4b5', |
|
111
|
|
|
'navajowhite' => 'ffdead', |
|
112
|
|
|
'navy' => '000080', |
|
113
|
|
|
'oldlace' => 'fdf5e6', |
|
114
|
|
|
'olive' => '808000', |
|
115
|
|
|
'olivedrab' => '6b8e23', |
|
116
|
|
|
'orange' => 'ffa500', |
|
117
|
|
|
'orangered' => 'ff4500', |
|
118
|
|
|
'orchid' => 'da70d6', |
|
119
|
|
|
'palegoldenrod' => 'eee8aa', |
|
120
|
|
|
'palegreen' => '98fb98', |
|
121
|
|
|
'paleturquoise' => 'afeeee', |
|
122
|
|
|
'palevioletred' => 'db7093', |
|
123
|
|
|
'papayawhip' => 'ffefd5', |
|
124
|
|
|
'peachpuff' => 'ffdab9', |
|
125
|
|
|
'peru' => 'cd853f', |
|
126
|
|
|
'pink' => 'ffc0cb', |
|
127
|
|
|
'plum' => 'dda0dd', |
|
128
|
|
|
'powderblue' => 'b0e0e6', |
|
129
|
|
|
'purple' => '800080', |
|
130
|
|
|
'rebeccapurple' => '663399', |
|
131
|
|
|
'red' => 'ff0000', |
|
132
|
|
|
'rosybrown' => 'bc8f8f', |
|
133
|
|
|
'royalblue' => '4169e1', |
|
134
|
|
|
'saddlebrown' => '8b4513', |
|
135
|
|
|
'salmon' => 'fa8072', |
|
136
|
|
|
'sandybrown' => 'f4a460', |
|
137
|
|
|
'seagreen' => '2e8b57', |
|
138
|
|
|
'seashell' => 'fff5ee', |
|
139
|
|
|
'sienna' => 'a0522d', |
|
140
|
|
|
'silver' => 'c0c0c0', |
|
141
|
|
|
'skyblue' => '87ceeb', |
|
142
|
|
|
'slateblue' => '6a5acd', |
|
143
|
|
|
'slategray' => '708090', |
|
144
|
|
|
'slategrey' => '708090', |
|
145
|
|
|
'snow' => 'fffafa', |
|
146
|
|
|
'springgreen' => '00ff7f', |
|
147
|
|
|
'steelblue' => '4682b4', |
|
148
|
|
|
'tan' => 'd2b48c', |
|
149
|
|
|
'teal' => '008080', |
|
150
|
|
|
'thistle' => 'd8bfd8', |
|
151
|
|
|
'tomato' => 'ff6347', |
|
152
|
|
|
'turquoise' => '40e0d0', |
|
153
|
|
|
'violet' => 'ee82ee', |
|
154
|
|
|
'wheat' => 'f5deb3', |
|
155
|
|
|
'white' => 'ffffff', |
|
156
|
|
|
'whitesmoke' => 'f5f5f5', |
|
157
|
|
|
'yellow' => 'ffff00', |
|
158
|
|
|
'yellowgreen' => '9acd32', |
|
159
|
|
|
); |
|
160
|
|
|
|
|
161
|
|
|
public $hints = array('color'); |
|
162
|
|
|
public $color = null; |
|
163
|
|
|
|
|
164
|
|
|
public function __construct($color) |
|
165
|
|
|
{ |
|
166
|
|
|
parent::__construct(); |
|
167
|
|
|
|
|
168
|
|
|
$this->color = $color; |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
/** |
|
172
|
|
|
* Turns HSL color to RGB. Black magic. |
|
173
|
|
|
* |
|
174
|
|
|
* @param float $h Hue |
|
175
|
|
|
* @param float $s Saturation |
|
176
|
|
|
* @param float $l Lightness |
|
177
|
|
|
* |
|
178
|
|
|
* @return array RGB array |
|
|
|
|
|
|
179
|
|
|
*/ |
|
180
|
|
|
public static function hslToRgb($h, $s, $l) |
|
|
|
|
|
|
181
|
|
|
{ |
|
182
|
|
|
if (min($h, $s, $l) < 0) { |
|
183
|
|
|
throw new InvalidArgumentException('The parameters for hslToRgb should be no less than 0'); |
|
184
|
|
|
} elseif ($h > 360 || max($s, $l) > 100) { |
|
185
|
|
|
throw new InvalidArgumentException('The parameters for hslToRgb should be no more than 360, 100, and 100 respectively'); |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
$h /= 360; |
|
189
|
|
|
$s /= 100; |
|
190
|
|
|
$l /= 100; |
|
191
|
|
|
|
|
192
|
|
|
$m2 = ($l <= 0.5) ? $l * ($s + 1) : $l + $s - $l * $s; |
|
|
|
|
|
|
193
|
|
|
$m1 = $l * 2 - $m2; |
|
|
|
|
|
|
194
|
|
|
|
|
195
|
|
|
$out = array( |
|
196
|
|
|
round(self::hueToRgb($m1, $m2, $h + 1 / 3) * 255), |
|
197
|
|
|
round(self::hueToRgb($m1, $m2, $h) * 255), |
|
198
|
|
|
round(self::hueToRgb($m1, $m2, $h - 1 / 3) * 255), |
|
199
|
|
|
); |
|
200
|
|
|
|
|
201
|
|
|
if (max($out) > 255) { |
|
202
|
|
|
throw new LogicException('hslToRbg return value should not contain values above 255'); |
|
203
|
|
|
} else { |
|
204
|
|
|
return $out; |
|
205
|
|
|
} |
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
|
|
/** |
|
209
|
|
|
* Helper function for hslToRgb. Even blacker magic. |
|
210
|
|
|
* |
|
211
|
|
|
* @return float Color value |
|
212
|
|
|
*/ |
|
213
|
|
|
private static function hueToRgb($m1, $m2, $hue) |
|
|
|
|
|
|
214
|
|
|
{ |
|
215
|
|
|
$hue = ($hue < 0) ? $hue + 1 : (($hue > 1) ? $hue - 1 : $hue); |
|
|
|
|
|
|
216
|
|
View Code Duplication |
if ($hue * 6 < 1) { |
|
|
|
|
|
|
217
|
|
|
return $m1 + ($m2 - $m1) * $hue * 6; |
|
218
|
|
|
} |
|
219
|
|
|
if ($hue * 2 < 1) { |
|
220
|
|
|
return $m2; |
|
221
|
|
|
} |
|
222
|
|
View Code Duplication |
if ($hue * 3 < 2) { |
|
|
|
|
|
|
223
|
|
|
return $m1 + ($m2 - $m1) * (0.66666 - $hue) * 6; |
|
224
|
|
|
} |
|
225
|
|
|
|
|
226
|
|
|
return $m1; |
|
227
|
|
|
} |
|
228
|
|
|
|
|
229
|
|
|
/** |
|
230
|
|
|
* Converts RGB to HSL. Color inversion of previous black magic is white magic? |
|
231
|
|
|
* |
|
232
|
|
|
* @param float $red Red |
|
233
|
|
|
* @param float $green Green |
|
234
|
|
|
* @param float $blue Blue |
|
235
|
|
|
* |
|
236
|
|
|
* @return array HSL array |
|
|
|
|
|
|
237
|
|
|
*/ |
|
238
|
|
|
public static function rgbToHsl($red, $green, $blue) |
|
239
|
|
|
{ |
|
240
|
|
|
if (min($red, $green, $blue) < 0) { |
|
241
|
|
|
throw new InvalidArgumentException('The parameters for rgbToHsl should be no less than 0'); |
|
242
|
|
|
} elseif (max($red, $green, $blue) > 255) { |
|
243
|
|
|
throw new InvalidArgumentException('The parameters for rgbToHsl should be no more than 255'); |
|
244
|
|
|
} |
|
245
|
|
|
|
|
246
|
|
|
$clrMin = min($red, $green, $blue); |
|
247
|
|
|
$clrMax = max($red, $green, $blue); |
|
248
|
|
|
$deltaMax = $clrMax - $clrMin; |
|
249
|
|
|
|
|
250
|
|
|
$L = ($clrMax + $clrMin) / 510; |
|
|
|
|
|
|
251
|
|
|
|
|
252
|
|
|
if (0 == $deltaMax) { |
|
253
|
|
|
$H = 0; |
|
|
|
|
|
|
254
|
|
|
$S = 0; |
|
|
|
|
|
|
255
|
|
|
} else { |
|
256
|
|
|
if (0.5 > $L) { |
|
|
|
|
|
|
257
|
|
|
$S = $deltaMax / ($clrMax + $clrMin); |
|
|
|
|
|
|
258
|
|
|
} else { |
|
259
|
|
|
$S = $deltaMax / (510 - $clrMax - $clrMin); |
|
|
|
|
|
|
260
|
|
|
} |
|
261
|
|
|
|
|
262
|
|
|
if ($clrMax == $red) { |
|
263
|
|
|
$H = ($green - $blue) / (6.0 * $deltaMax); |
|
|
|
|
|
|
264
|
|
|
} elseif ($clrMax == $green) { |
|
265
|
|
|
$H = 1 / 3 + ($blue - $red) / (6.0 * $deltaMax); |
|
|
|
|
|
|
266
|
|
|
} else { |
|
267
|
|
|
$H = 2 / 3 + ($red - $green) / (6.0 * $deltaMax); |
|
|
|
|
|
|
268
|
|
|
} |
|
269
|
|
|
|
|
270
|
|
|
if (0 > $H) { |
|
|
|
|
|
|
271
|
|
|
$H += 1; |
|
|
|
|
|
|
272
|
|
|
} |
|
273
|
|
|
if (1 < $H) { |
|
|
|
|
|
|
274
|
|
|
$H -= 1; |
|
|
|
|
|
|
275
|
|
|
} |
|
276
|
|
|
} |
|
277
|
|
|
|
|
278
|
|
|
return array( |
|
279
|
|
|
(round($H * 360) % 360 + 360) % 360, |
|
|
|
|
|
|
280
|
|
|
round($S * 100), |
|
|
|
|
|
|
281
|
|
|
round($L * 100), |
|
|
|
|
|
|
282
|
|
|
); |
|
283
|
|
|
} |
|
284
|
|
|
} |
|
285
|
|
|
|
This check marks property names that have not been written in camelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes
databaseConnectionString.