1 | <?php |
||
9 | class LanguageComponent implements Component |
||
10 | { |
||
11 | protected $request; |
||
12 | protected $parameters; |
||
13 | |||
14 | protected $defaultLanguage = 'en'; |
||
15 | protected $acceptedLanguages = null; |
||
16 | protected $languageParameterName = 'language'; |
||
17 | protected $forceRedirect = false; |
||
18 | protected $sessionValues; |
||
19 | |||
20 | /** |
||
21 | * Component constructor. |
||
22 | * |
||
23 | * @param $template |
||
24 | * @param Request $request |
||
25 | * @param $parameters |
||
26 | * @param $matchedSitemapItem |
||
27 | */ |
||
28 | public function __construct($template, Request $request, $parameters, $matchedSitemapItem) |
||
48 | |||
49 | /** |
||
50 | * Checks to see if any parameters are given from the configuration in the CMS |
||
51 | */ |
||
52 | private function checkParameters() |
||
71 | |||
72 | /** |
||
73 | * @return array |
||
74 | */ |
||
75 | public function getParameters() |
||
79 | |||
80 | |||
81 | /** |
||
82 | * Check if the found language is allowed and |
||
83 | * if an action is to be taken. |
||
84 | * |
||
85 | * @param $lang |
||
86 | * @param Request $request |
||
87 | */ |
||
88 | private function detectLanguage($lang, $request) |
||
89 | { |
||
90 | $lang = $this->setLanguagInSession($lang); |
||
91 | |||
92 | $this->sessionValues = $_SESSION['LanguageComponent']; |
||
93 | |||
94 | $this->checkForceRedirect($lang, $request); |
||
95 | } |
||
96 | |||
97 | /** |
||
98 | * Detect if the language is switched manually |
||
99 | * |
||
100 | * @param Request $request |
||
101 | */ |
||
102 | private function checkLanguageSwitch($request) |
||
103 | { |
||
104 | if (isset($request::$get['langSwitch'])) { |
||
105 | $this->forceRedirect = true; |
||
106 | $this->detectLanguage($request::$get['langSwitch'], $request); |
||
107 | } |
||
108 | } |
||
109 | |||
110 | public function render() |
||
113 | |||
114 | public function get() |
||
117 | |||
118 | /** |
||
119 | * @param Storage $storage |
||
120 | */ |
||
121 | function run(Storage $storage) |
||
125 | |||
126 | /** |
||
127 | * @param $lang |
||
128 | * @param $request |
||
129 | */ |
||
130 | private function checkForceRedirect($lang, $request) |
||
145 | |||
146 | /** |
||
147 | * @param $lang |
||
148 | * @return string |
||
149 | */ |
||
150 | private function setLanguagInSession($lang) |
||
163 | } |
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.