| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
namespace Carbon; |
| 15 |
|
| 16 |
use Carbon\Exceptions\ImmutableException; |
| 17 |
use Symfony\Component\Config\ConfigCacheFactoryInterface; |
| 18 |
use Symfony\Component\Translation\Formatter\MessageFormatterInterface; |
| 19 |
|
| 20 |
class TranslatorImmutable extends Translator |
| 21 |
{ |
| 22 |
private bool $constructed = false; |
| 23 |
|
| 24 |
public function __construct($locale, ?MessageFormatterInterface $formatter = null, $cacheDir = null, $debug = false) |
| 25 |
{ |
| 26 |
parent::__construct($locale, $formatter, $cacheDir, $debug); |
| 27 |
$this->constructed = true; |
| 28 |
} |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
public function setDirectories(array $directories): static |
| 34 |
{ |
| 35 |
$this->disallowMutation(__METHOD__); |
| 36 |
|
| 37 |
return parent::setDirectories($directories); |
| 38 |
} |
| 39 |
|
| 40 |
public function setLocale($locale): void |
| 41 |
{ |
| 42 |
$this->disallowMutation(__METHOD__); |
| 43 |
|
| 44 |
parent::setLocale($locale); |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
public function setMessages(string $locale, array $messages): static |
| 51 |
{ |
| 52 |
$this->disallowMutation(__METHOD__); |
| 53 |
|
| 54 |
return parent::setMessages($locale, $messages); |
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
public function setTranslations(array $messages): static |
| 61 |
{ |
| 62 |
$this->disallowMutation(__METHOD__); |
| 63 |
|
| 64 |
return parent::setTranslations($messages); |
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
public function setConfigCacheFactory(ConfigCacheFactoryInterface $configCacheFactory): void |
| 71 |
{ |
| 72 |
$this->disallowMutation(__METHOD__); |
| 73 |
|
| 74 |
parent::setConfigCacheFactory($configCacheFactory); |
| 75 |
} |
| 76 |
|
| 77 |
public function resetMessages(?string $locale = null): bool |
| 78 |
{ |
| 79 |
$this->disallowMutation(__METHOD__); |
| 80 |
|
| 81 |
return parent::resetMessages($locale); |
| 82 |
} |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
public function setFallbackLocales(array $locales): void |
| 88 |
{ |
| 89 |
$this->disallowMutation(__METHOD__); |
| 90 |
|
| 91 |
parent::setFallbackLocales($locales); |
| 92 |
} |
| 93 |
|
| 94 |
private function disallowMutation($method) |
| 95 |
{ |
| 96 |
if ($this->constructed) { |
| 97 |
throw new ImmutableException($method.' not allowed on '.static::class); |
| 98 |
} |
| 99 |
} |
| 100 |
} |