Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
75.00% |
3 / 4 |
|
75.00% |
3 / 4 |
CRAP | |
0.00% |
0 / 1 |
| CounterFormat | |
75.00% |
3 / 4 |
|
75.00% |
3 / 4 |
4.25 | |
0.00% |
0 / 1 |
| registry | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| format | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| marker | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| isKnown | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Phpdftk\HtmlToPdf\Layout; |
| 6 | |
| 7 | /** |
| 8 | * Static facade over the predefined CSS Counter Styles 3 catalogue, used by |
| 9 | * list-marker painting (`<ol type="i">`, `list-style-type: lower-roman`), |
| 10 | * `content: counter(n, <style>)` and `@page` `counter(page, <style>)`. |
| 11 | * |
| 12 | * The algorithms and the style table live in {@see CounterStyleRegistry}; |
| 13 | * this is the no-author-`@counter-style` entry point, so that call sites |
| 14 | * which never see a stylesheet (the page-margin painter) still format |
| 15 | * every predefined style correctly. |
| 16 | */ |
| 17 | final class CounterFormat |
| 18 | { |
| 19 | private static ?CounterStyleRegistry $registry = null; |
| 20 | |
| 21 | private static function registry(): CounterStyleRegistry |
| 22 | { |
| 23 | return self::$registry ??= new CounterStyleRegistry(); |
| 24 | } |
| 25 | |
| 26 | /** |
| 27 | * The counter REPRESENTATION for `$value` — symbols and negative sign, |
| 28 | * with no `prefix` / `suffix`. This is what `counter()` substitutes. |
| 29 | * |
| 30 | * Returns the decimal string when `$style` names no known counter style, |
| 31 | * the same fallback browsers apply to an unknown `list-style-type`. |
| 32 | */ |
| 33 | public static function format(int $value, string $style): string |
| 34 | { |
| 35 | return self::registry()->representation($value, $style); |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * The full MARKER string for `$value`: `prefix` + representation + |
| 40 | * `suffix`. `suffix` defaults to `". "` but is `"、"` for the CJK styles |
| 41 | * and `" "` for the bullet families, which is why markers cannot simply |
| 42 | * be {@see format()} with a full stop stuck on the end. |
| 43 | */ |
| 44 | public static function marker(int $value, string $style): string |
| 45 | { |
| 46 | return self::registry()->marker($value, $style); |
| 47 | } |
| 48 | |
| 49 | /** Is `$style` a counter style this build knows how to format? */ |
| 50 | public static function isKnown(string $style): bool |
| 51 | { |
| 52 | return self::registry()->has($style); |
| 53 | } |
| 54 | } |