-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMaterialColors.php
More file actions
131 lines (111 loc) · 3.89 KB
/
MaterialColors.php
File metadata and controls
131 lines (111 loc) · 3.89 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
<?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\Material;
/**
* @method string red(int|string $shade = 500)
* @method string pink(int|string $shade = 500)
* @method string purple(int|string $shade = 500)
* @method string deepPurple(int|string $shade = 500)
* @method string indigo(int|string $shade = 500)
* @method string blue(int|string $shade = 500)
* @method string lightBlue(int|string $shade = 500)
* @method string cyan(int|string $shade = 500)
* @method string teal(int|string $shade = 500)
* @method string green(int|string $shade = 500)
* @method string lightGreen(int|string $shade = 500)
* @method string lime(int|string $shade = 500)
* @method string yellow(int|string $shade = 500)
* @method string amber(int|string $shade = 500)
* @method string orange(int|string $shade = 500)
* @method string deepOrange(int|string $shade = 500)
* @method string brown(int|string $shade = 500)
* @method string gray(int|string $shade = 500)
* @method string blueGray(int|string $shade = 500)
*
* @implements \IteratorAggregate<string, array<int|string, string>>
*/
final class MaterialColors extends \stdClass implements \IteratorAggregate, \Countable
{
public static function colors(): self
{
/** @var array<string, array<int|string, string>> $colors */
$colors = require __DIR__.'/Resources/colors.php';
return new self($colors);
}
/**
* @param array<string, array<int|string, string>> $colors
*/
private function __construct(private readonly array $colors)
{
}
/**
* @return list<string>
*/
public function getNames(): array
{
return array_keys($this->colors);
}
/**
* @return list<int|string>
*/
public function getShades(?string $color = null): array
{
$color ??= $this->getNames()[0];
return array_keys($this->colors[$color]);
}
public function get(string $color, int|string $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 "%s" 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);
}
public function count(): int
{
return count($this->colors, COUNT_RECURSIVE);
}
/**
* @return \ArrayIterator<string, array<int|string, 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]) && !\is_string($arguments[0])) {
throw new \InvalidArgumentException(sprintf('The first argument of "%s" must be an integer or string, "%s" given.', $name, get_debug_type($arguments[0])));
}
$shade = isset($arguments[0]) ? (\is_int($arguments[0]) || \is_string($arguments[0]) ? $arguments[0] : 500) : 500;
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('MaterialColors are read-only.');
}
}