1 | <?php |
||
11 | class LocaleResolver |
||
12 | { |
||
13 | const PATTERN_PARAMETER = 'parameter'; // pass the locale the normal way, ie. http://acme.dn/fr |
||
14 | const PATTERN_DOMAIN = 'domain'; |
||
15 | |||
16 | public $localePattern; |
||
17 | protected $localeDomainConfig; |
||
18 | protected $availableLocales; |
||
19 | public $defaultLocale; |
||
20 | public $defaultDomain; |
||
21 | |||
22 | /** |
||
23 | * Constructor. |
||
24 | * |
||
25 | * @param string $localePattern What is the strategy to resolve locale |
||
26 | * @param array $localeDomainConfig The locale domain config |
||
27 | * @param string $defaultLocale The default local app |
||
28 | * @param string $availableLocales The list of available locales |
||
29 | */ |
||
30 | public function __construct($localePattern, array $localeDomainConfig, $defaultLocale, $availableLocales) |
||
44 | |||
45 | /** |
||
|
|||
46 | * set the local depending on patterns |
||
47 | * it also set the victoire_locale wich is the locale of the application admin. |
||
48 | */ |
||
49 | public function resolve(Request $request) |
||
61 | |||
62 | /** |
||
63 | * @param Request $request |
||
64 | * |
||
65 | * @throws \Exception |
||
66 | * |
||
67 | * @return string |
||
68 | * |
||
69 | * resolves the locale from httpHost or host |
||
70 | */ |
||
71 | public function resolveFromDomain(Request $request) |
||
91 | |||
92 | /** |
||
93 | * @return string |
||
94 | * |
||
95 | * This method resolves the domain from locale |
||
96 | */ |
||
97 | public function resolveDomainForLocale($locale) |
||
107 | |||
108 | /** |
||
109 | * Return available locales. |
||
110 | * |
||
111 | * @return array |
||
112 | */ |
||
113 | public function getAvailableLocales() |
||
117 | |||
118 | /** |
||
119 | * return domain config. |
||
120 | * |
||
121 | * @return array |
||
122 | */ |
||
123 | public function getDomainConfig() |
||
127 | } |
||
128 |