-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBootstrapColors.php
More file actions
133 lines (112 loc) · 3.48 KB
/
BootstrapColors.php
File metadata and controls
133 lines (112 loc) · 3.48 KB
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
<?php
declare(strict_types=1);
/*
* This file is part of the PHPColor library.
*
* (c) Simon André & Raphaël Geffroy
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace PhpColor\Colors\Bootstrap;
/**
* @method string blue(int $shade = 500)
* @method string indigo(int $shade = 500)
* @method string purple(int $shade = 500)
* @method string pink(int $shade = 500)
* @method string red(int $shade = 500)
* @method string orange(int $shade = 500)
* @method string yellow(int $shade = 500)
* @method string green(int $shade = 500)
* @method string teal(int $shade = 500)
* @method string cyan(int $shade = 500)
* @method string gray(int $shade = 500)
*
* @implements \IteratorAggregate<string, array<int, string>>
*/
final class BootstrapColors extends \stdClass implements \IteratorAggregate, \Countable
{
public static function colors(): self
{
/** @var array<string, array<int, string>> $colors */
$colors = require __DIR__.'/Resources/colors.php';
return new self($colors);
}
/**
* @param array<string, array<int, string>> $colors
*/
private function __construct(private readonly array $colors)
{
}
/**
* @return list<string>
*/
public function getNames(): array
{
return array_keys($this->colors);
}
/**
* @return list<int>
*/
public function getShades(?string $color = null): array
{
$color ??= $this->getNames()[0];
return array_keys($this->colors[$color]);
}
public function get(string $color, int $shade = 500): string
{
if (!isset($this->colors[$color])) {
throw new \InvalidArgumentException(sprintf('The color "%s" does not exist.', $color));
}
if (!isset($this->colors[$color][$shade])) {
throw new \InvalidArgumentException(sprintf('The shade "%d" does not exist for the color "%s".', $shade, $color));
}
return $this->colors[$color][$shade];
}
public function has(string $name): bool
{
return \in_array($name, $this->getNames(), true);
}
/**
* @return int<0, max>
*/
public function count(): int
{
$total = count($this->colors, COUNT_RECURSIVE) - count($this->colors);
assert($total >= 0);
return $total;
}
/**
* @return \ArrayIterator<string, array<int, string>>
*/
public function getIterator(): \ArrayIterator
{
return new \ArrayIterator($this->colors);
}
/**
* @param array<mixed> $arguments
*/
public function __call(string $name, array $arguments): mixed
{
if (!$this->has($name)) {
throw new \BadMethodCallException(sprintf('The method "%s" does not exist.', $name));
}
if (isset($arguments[0]) && !\is_int($arguments[0])) {
throw new \InvalidArgumentException(sprintf('The first argument of "%s" must be an integer, "%s" given.', $name, get_debug_type($arguments[0])));
}
$shade = 500;
if (isset($arguments[0])) {
assert(\is_int($arguments[0]));
$shade = $arguments[0];
}
return $this->get($name, $shade);
}
public function __get(string $name): string
{
return $this->get($name);
}
public function __set(string $name, mixed $value): void
{
throw new \BadMethodCallException('BootstrapColors are read-only.');
}
}