1 | <?php |
||
19 | abstract class AbstractLanguageResolver implements APILanguageResolver |
||
20 | { |
||
21 | /** @var bool */ |
||
22 | private $defaultUseAlwaysAvailable; |
||
23 | |||
24 | /** @var bool */ |
||
25 | private $defaultShowAllTranslations; |
||
26 | |||
27 | /** |
||
28 | * Values typically provided by user context, will need to be set depending on your own custom logic using setter. |
||
29 | * |
||
30 | * E.g. Backend UI might expose a language selector for the whole backend that should be reflected on both |
||
31 | * UI strings as well as default languages to prioritize for repository objects. |
||
32 | * |
||
33 | * If set, this will have priority over configured languages. |
||
34 | * |
||
35 | * @var string|null |
||
36 | */ |
||
37 | private $contextLanguage; |
||
38 | |||
39 | /** |
||
40 | * @param bool $defaultUseAlwaysAvailable |
||
41 | * @param bool $defaultShowAllTranslations |
||
42 | */ |
||
43 | public function __construct( |
||
50 | |||
51 | /** |
||
52 | * Get list of languages configured via dedicated layer. |
||
53 | * |
||
54 | * @return string[] |
||
55 | */ |
||
56 | abstract protected function getConfiguredLanguages(): array; |
||
57 | |||
58 | /** |
||
59 | * For use by custom events / logic setting language for all retrieved objects from repository. |
||
60 | * |
||
61 | * User language will, if set, will have prepended before configured languages. But in cases PHP API consumer |
||
62 | * specifies languages to retrieve repository objects in it will instead be appended as a fallback. |
||
63 | * |
||
64 | * If set, this will have priority over configured languages. |
||
65 | * |
||
66 | * @param string|null $contextLanguage |
||
67 | */ |
||
68 | final public function setContextLanguage(?string $contextLanguage): void |
||
72 | |||
73 | /** |
||
74 | * Get context language currently set by custom logic. |
||
75 | * |
||
76 | * @return null|string |
||
77 | */ |
||
78 | final public function getContextLanguage(): ?string |
||
82 | |||
83 | /** |
||
84 | * Get prioritized languages taking into account forced and context languages. |
||
85 | * |
||
86 | * @param array|null $forcedLanguages Optional, typically arguments provided to API, will be used first if set. |
||
87 | * |
||
88 | * @return array |
||
89 | */ |
||
90 | final public function getPrioritizedLanguages(?array $forcedLanguages = null): array |
||
110 | |||
111 | /** |
||
112 | * For use by event listening to config resolver scope changes (or other event changing configured languages). |
||
113 | * |
||
114 | * @param bool $defaultUseAlwaysAvailable |
||
115 | */ |
||
116 | final public function setDefaultUseAlwaysAvailable(bool $defaultUseAlwaysAvailable): void |
||
120 | |||
121 | /** |
||
122 | * Get currently set UseAlwaysAvailable. |
||
123 | * |
||
124 | * @param bool|null $forcedUseAlwaysAvailable Optional, if set will be used instead of configured value, |
||
125 | * typically arguments provided to API. |
||
126 | * |
||
127 | * @return bool |
||
128 | */ |
||
129 | final public function getUseAlwaysAvailable(?bool $forcedUseAlwaysAvailable = null): bool |
||
137 | |||
138 | /** |
||
139 | * For use by event listening to config resolver scope changes (or other event changing configured languages). |
||
140 | * |
||
141 | * @param bool $defaultShowAllTranslations |
||
142 | */ |
||
143 | final public function setShowAllTranslations(bool $defaultShowAllTranslations): void |
||
147 | |||
148 | /** |
||
149 | * Get currently set showAllTranslations. |
||
150 | * |
||
151 | * @param bool|null $forcedShowAllTranslations Optional, if set will be used instead of configured value, |
||
152 | * typically arguments provided to API. |
||
153 | * |
||
154 | * @return bool |
||
155 | */ |
||
156 | final public function getShowAllTranslations(?bool $forcedShowAllTranslations = null): bool |
||
164 | } |
||
165 |