ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilLanguageDetectorFactory.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
27 {
28  private const DEFAULT_DETECTOR = 1;
29  private const HTTP_REQUEST_DETECTOR = 2;
30 
32  protected array $request_information = array();
33  protected ilSetting $settings;
34 
35  public function __construct()
36  {
37  global $DIC;
38 
39  $this->client_ini = $DIC->clientIni();
40  $this->request_information = $_SERVER;
41  $this->settings = $DIC->settings();
42  }
43 
47  public function getValidInstances(): array
48  {
49  $detectors = array(
50  $this->createDetectorByType(self::DEFAULT_DETECTOR)
51  );
52 
53  if ($this->settings->get("lang_detection") &&
55  array_key_exists('HTTP_ACCEPT_LANGUAGE', $this->request_information)
56  ) {
57  $detectors[] = $this->createDetectorByType(self::HTTP_REQUEST_DETECTOR);
58  }
59 
60  return $detectors;
61  }
62 
66  public function createDetectorByType(int $type)
67  {
68  switch ($type) {
69  case self::HTTP_REQUEST_DETECTOR:
70  return new ilHttpRequestsLanguageDetector($this->request_information["HTTP_ACCEPT_LANGUAGE"]);
71 
72  case self::DEFAULT_DETECTOR:
73  return new ilDefaultLanguageDetector($this->client_ini);
74  }
75 
76  throw new ilLanguageException(__METHOD__ . sprintf("Cannot create language detector instance for type %s!", $type));
77  }
78 }
static usesHTTP()
Uses HTTP aka browser.
Class ilLanguageDetectorFactory.
Class for language related exception handling in ILIAS.
Class ilDefaultLanguageDetector.
$_SERVER['HTTP_HOST']
Definition: raiseError.php:26
global $DIC
Definition: shib_login.php:26
Class ilHttpRequestsLanguageDetector.