forked from sofascore/purgatory-bundle
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompoundValues.php
More file actions
67 lines (55 loc) · 1.61 KB
/
CompoundValues.php
File metadata and controls
67 lines (55 loc) · 1.61 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
<?php
declare(strict_types=1);
namespace Sofascore\PurgatoryBundle\Attribute\RouteParamValue;
use Sofascore\PurgatoryBundle\Attribute\PurgeOn;
use Sofascore\PurgatoryBundle\Exception\InvalidArgumentException;
final class CompoundValues extends AbstractValues
{
/**
* @var non-empty-list<ValuesInterface>
*/
private readonly array $values;
/**
* @param string|non-empty-list<string>|ValuesInterface $value
* @param string|non-empty-list<string>|ValuesInterface ...$values
*/
public function __construct(
string|array|ValuesInterface $value,
string|array|ValuesInterface ...$values,
) {
$values = [$value, ...$values];
/** @var non-empty-list<ValuesInterface> $normalized */
$normalized = [];
foreach ($values as $value) {
if ($value instanceof self) {
throw new InvalidArgumentException(\sprintf('An argument cannot be an instance of "%s".', self::class));
}
$normalized[] = PurgeOn::normalizeValue($value);
}
$this->values = $normalized;
}
/**
* @return list<ValuesInterface>
*/
public function getValues(): array
{
return $this->values;
}
/**
* {@inheritDoc}
*/
public function toArray(): array
{
return [
'type' => self::type(),
'values' => array_map(
static fn (ValuesInterface $values): array => $values->toArray(),
$this->values,
),
];
}
public static function type(): string
{
return 'compound';
}
}