19 declare(strict_types=1);
41 abstract public function value(): string;
45 return $this->
value();
48 public static function fromString(
string $string): static
51 return $brick->apply(self::definition($brick), $string)->except(
static fn ():
Result => (
52 new Error(
'Given string is no valid language tag.')
66 $language = $brick->
either([
69 $brick->
repeat(0, 1, $brick->
sequence([
'-',
'extlang' => $extlang])),
84 $variant = $brick->
either([
85 $brick->
repeat(5, 8, $alphanum),
89 $singleton = $brick->
either([
91 $brick->
range(0x41, 0x57),
92 $brick->
range(0x59, 0x5A),
93 $brick->
range(0x61, 0x77),
94 $brick->
range(0x79, 0x7A),
107 $new =
static fn (
string $class) =>
new Custom(
static fn (
string $arg) =>
new $class($arg));
109 $privateuse = $brick->
transformation($new(PrivateUse::class), $privateuse);
111 $irregular = $brick->
either([
131 $regular = $brick->
either([
143 $grandfathered = $brick->
either([
150 $from[
'language'][
'lang'],
151 $from[
'language'][
'extlang'] ??
null,
152 $from[
'script'] ?? null,
153 $from[
'region'] ?? null,
154 $from[
'variant'] ?? null,
155 $from[
'extension'] ?? null,
156 $from[
'privateuse'] ?? null,
159 'language' => $language,
160 $brick->
repeat(0, 1, $brick->
sequence([
'-',
'script' => $script])),
161 $brick->
repeat(0, 1, $brick->
sequence([
'-',
'region' => $region])),
162 $brick->
repeat(0, null, $brick->
sequence([
'-',
'variant' => $variant])),
163 $brick->
repeat(0, null, $brick->
sequence([
'-',
'extension' => $extension])),
164 $brick->
repeat(0, 1, $brick->
sequence([
'-',
'privateuse' => $privateuse])),
168 return $brick->
either([$langtag, $privateuse, $grandfathered]);
static fromString(string $string)
transformation(Transformation $transformation, Closure $parse)
This class represents a valid language tag that should be used instead of plain strings.
repeat(int $min, ?int $max, $parse)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
static definition(Brick $brick)
This definition is directly translated from the ABNF definition on https://www.ietf.org/rfc/bcp/bcp47.txt.
range(int $start, int $end)
-type Continuation Closure(Result<Intermediate>): Result<Intermediate> -type Parser Closure(Intermedi...