1 | <?php |
||
16 | class LanguageResolver |
||
17 | { |
||
18 | /** |
||
19 | * Values typically provided by configuration. |
||
20 | * |
||
21 | * These will need to change when configuration (scope) changes mid flight using setters below. |
||
22 | * |
||
23 | * @var array |
||
24 | */ |
||
25 | private $configLanguages; |
||
26 | |||
27 | /** @var bool */ |
||
28 | private $defaultUseAlwaysAvailable; |
||
29 | |||
30 | /** @var bool */ |
||
31 | private $defaultShowAllTranslations; |
||
32 | |||
33 | /** |
||
34 | * Values typically provided by user context, will need to be set depending on your own custom logic using setter. |
||
35 | * |
||
36 | * E.g. Backend UI might expose a language selector for the whole backend that should be reflected on both |
||
37 | * UI strings as well as default languages to prioritize for repository objects. |
||
38 | * |
||
39 | * If set, this will have priority over configured languages. |
||
40 | * |
||
41 | * @var string|null |
||
42 | */ |
||
43 | private $contextLanguage; |
||
44 | |||
45 | public function __construct( |
||
54 | |||
55 | /** |
||
56 | * For use by event listening to config resolver scope changes (or other event changing configured languages). |
||
57 | * |
||
58 | * @param array $configLanguages |
||
59 | */ |
||
60 | public function setConfigLanguages(array $configLanguages): void |
||
64 | |||
65 | /** |
||
66 | * For use by custom events / logic setting language for all retrieved objects from repository. |
||
67 | * |
||
68 | * User language will, if set, will have prepended before configured languages. But in cases PHP API consumer |
||
69 | * specifies languages to retrieve repository objects in it will instead be appended as a fallback. |
||
70 | * |
||
71 | * If set, this will have priority over configured languages. |
||
72 | * |
||
73 | * @param string|null $contextLanguage |
||
74 | */ |
||
75 | public function setContextLanguage(?string $contextLanguage): void |
||
79 | |||
80 | /** |
||
81 | * Get prioritized languages taking into account forced-, context- and lastly configured-languages. |
||
82 | * |
||
83 | * @param array|null $forcedLanguages Optional, typically arguments provided to API, will be used first if set. |
||
84 | * |
||
85 | * @return array |
||
86 | */ |
||
87 | public function getPrioritizedLanguages(?array $forcedLanguages): array |
||
107 | |||
108 | /** |
||
109 | * For use by event listening to config resolver scope changes (or other event changing configured languages). |
||
110 | * |
||
111 | * @param bool $defaultUseAlwaysAvailable |
||
112 | */ |
||
113 | public function setDefaultUseAlwaysAvailable(bool $defaultUseAlwaysAvailable): void |
||
117 | |||
118 | /** |
||
119 | * Get currently set UseAlwaysAvailable. |
||
120 | * |
||
121 | * @param bool|null $forcedUseAlwaysAvailable Optional, if set will be used instead of configured value, |
||
122 | * typically arguments provided to API. |
||
123 | * |
||
124 | * @return bool |
||
125 | */ |
||
126 | public function getUseAlwaysAvailable(?bool $forcedUseAlwaysAvailable = null): bool |
||
134 | |||
135 | /** |
||
136 | * For use by event listening to config resolver scope changes (or other event changing configured languages). |
||
137 | * |
||
138 | * @param bool $defaultShowAllTranslations |
||
139 | */ |
||
140 | public function setShowAllTranslations(bool $defaultShowAllTranslations): void |
||
144 | |||
145 | /** |
||
146 | * Get currently set showAllTranslations. |
||
147 | * |
||
148 | * @param bool|null $forcedShowAllTranslations Optional, if set will be used instead of configured value, |
||
149 | * typically arguments provided to API. |
||
150 | * |
||
151 | * @return bool |
||
152 | */ |
||
153 | public function getShowAllTranslations(?bool $forcedShowAllTranslations = null): bool |
||
161 | } |
||
162 |