| Total Lines | 22 |
| Code Lines | 9 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 10 | public static function setDefault(TranslatorInterface|callable $translator, bool $compose = true): void |
||
| 11 | { |
||
| 12 | if ($translator instanceof TranslatorInterface) { |
||
| 13 | self::$translator = $translator; |
||
| 14 | } else { |
||
| 15 | self::$translator = new class($translator) implements TranslatorInterface { |
||
| 16 | private $callback; |
||
| 17 | |||
| 18 | public function __construct(callable $callback) |
||
| 19 | { |
||
| 20 | $this->callback = $callback; |
||
| 21 | } |
||
| 22 | |||
| 23 | public function translate(string $message, ...$args): ?string |
||
| 24 | { |
||
| 25 | return call_user_func_array($this->callback, [$message, ...$args]); |
||
| 26 | } |
||
| 27 | }; |
||
| 28 | } |
||
| 29 | |||
| 30 | if ($compose) { |
||
| 31 | self::$translator = new CompositeTranslator(self::$translator, self::createDefault()); |
||
| 32 | } |
||
| 59 |