Debian Codegraph @

lib/3rdParty/composer/nesbot/carbon/src/Carbon/TranslatorImmutable.php

raw symbols SCIP
1 <?php
2
3 declare(strict_types=1);
4
5 /**
6 * This file is part of the Carbon package.
7 *
8 * (c) Brian Nesbitt <[email protected]>
9 *
10 * For the full copyright and license information, please view the LICENSE
11 * file that was distributed with this source code.
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 * @codeCoverageIgnore
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 * @codeCoverageIgnore
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 * @codeCoverageIgnore
59 */
60 public function setTranslations(array $messages): static
61 {
62 $this->disallowMutation(__METHOD__);
63
64 return parent::setTranslations($messages);
65 }
66
67 /**
68 * @codeCoverageIgnore
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 * @codeCoverageIgnore
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 }