API / Minn\I18n / PluralRule

PluralRule final readonly class

Minn\I18n\PluralRule · public/minn/src/Minn/I18n/PluralRule.php · 69 lines

A language's plural rule from its Plural-Forms header: how many forms it has and which form a number takes. A file without the header follows English (two forms, n != 1); an expression that does not parse sends every number to the first form, as the reference does.

Used by 1

Constants and properties

propreadonly int $count

Promoted from the constructor.

propreadonly string $expression

Promoted from the constructor.

privatereadonly ?array $tree

Promoted from the constructor.

Public

new__construct(int $count, string $expression, ?array $tree)#
$treearray<int, mixed>|null
staticenglish(): self#

English: one form for 1, the other for everything else.

staticfromHeader(?string $header): self#

The rule a Plural-Forms header states.

staticfromExpression(int $count, string $expression): self#

A rule from a form count and an expression in n.

staticparenthesized(string $expression): string#

An expression with each ternary's branches parenthesized, as parenthesize_plural_exression() writes it: "?" becomes " ? (", ":" becomes ") : (", the open parentheses closed at each ";" and at the end, trailing semicolons dropped.

methodindex(int $n): int#

The form a number takes.

methodpair(): array#

The form count and the expression, as nplurals_and_expression_from_header() answers them. @return array{0: int, 1: string}

@return array{0: int, 1: string}
methodchooser(): Closure#

The form a number takes, as the function make_plural_form_function() hands back. @return \Closure(mixed): int

@return \Closure(mixed): int