-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCompoundID.php
43 lines (37 loc) · 1.23 KB
/
CompoundID.php
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
<?php
declare(strict_types=1);
namespace PrinsFrank\Transliteration\Syntax\FormalId;
use PrinsFrank\Transliteration\Syntax\Enum\Literal;
use PrinsFrank\Transliteration\Exception\InvalidArgumentException;
use PrinsFrank\Transliteration\Syntax\FormalId\Components\Filter;
/**
* @internal
*
* @see https://unicode-org.github.io/icu/userguide/transforms/general/#formal-id-syntax
*/
final class CompoundID implements ID
{
/**
* @param list<SingleID> $singleIds
* @throws InvalidArgumentException
*/
public function __construct(
public readonly array $singleIds,
public readonly Filter|null $globalFilter = null,
) {
foreach ($this->singleIds as $singleId) {
$singleId instanceof SingleID === true || throw new InvalidArgumentException('Param $singleIds should be an array of "' . SingleID::class . '"');
}
}
public function __toString()
{
$string = '';
if ($this->globalFilter !== null) {
$string .= $this->globalFilter->__toString() . Literal::Semicolon->value;
}
foreach ($this->singleIds as $singleId) {
$string .= $singleId->__toString() . Literal::Semicolon->value;
}
return $string;
}
}