1 | <?php |
||
10 | class GraphQLLanguageContext { |
||
11 | |||
12 | /** |
||
13 | * Indicates if the GraphQL context language is currently active. |
||
14 | * |
||
15 | * @var bool |
||
16 | */ |
||
17 | protected $isActive; |
||
18 | |||
19 | /** |
||
20 | * The current language context. |
||
21 | * |
||
22 | * @var string |
||
23 | */ |
||
24 | protected $currentLanguage; |
||
25 | |||
26 | /** |
||
27 | * The language manager service. |
||
28 | * |
||
29 | * @var \Drupal\Core\Language\LanguageManagerInterface |
||
30 | */ |
||
31 | protected $languageManager; |
||
32 | |||
33 | /** |
||
34 | * GraphQLLanguageContext constructor. |
||
35 | * |
||
36 | * @param \Drupal\Core\Language\LanguageManagerInterface $languageManager |
||
37 | * The language manager service. |
||
38 | */ |
||
39 | public function __construct(LanguageManagerInterface $languageManager) { |
||
42 | |||
43 | /** |
||
44 | * Set the current context language. |
||
45 | * |
||
46 | * @param string $langcode |
||
47 | * The language to be set. |
||
48 | */ |
||
49 | protected function setCurrentLanguage($langcode) { |
||
54 | |||
55 | /** |
||
56 | * Retrieve the current language. |
||
57 | * |
||
58 | * @return string|null |
||
59 | * The current language code, or null if the context is not active. |
||
60 | */ |
||
61 | public function getCurrentLanguage() { |
||
66 | |||
67 | /** |
||
68 | * Executes a callable in a defined language context. |
||
69 | * |
||
70 | * @param callable $callable |
||
71 | * The callable to be executed. |
||
72 | * @param string $language |
||
73 | * The langcode to be set. |
||
74 | * |
||
75 | * @return mixed |
||
76 | * The callables result. |
||
77 | * |
||
78 | * @throws \Exception |
||
79 | * Any exception caught while executing the callable. |
||
80 | */ |
||
81 | public function executeInLanguageContext(callable $callable, $language) { |
||
95 | |||
96 | /** |
||
97 | * Reset the context.. |
||
98 | */ |
||
99 | public function reset() { |
||
104 | |||
105 | } |
||
106 |