Combu Server  3.1.1
PHP API Documentation
ErrorMessage.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Combu;
4 
10 class ErrorMessage {
11 
16  private static $instance = NULL;
17 
18  private $language;
19  private $folder;
20  private $messages;
21 
22 
27  public static function Initialize($language = "en") {
28  // Instantiate the singleton instance
29  self::$instance = new self();
30  self::$instance->folder = (defined("ERRORS_FOLDER") && ERRORS_FOLDER ? ERRORS_FOLDER : "");
31  self::$instance->messages = array();
32  if (!file_exists(self::$instance->folder) || !is_dir(self::$instance->folder)) {
33  self::$instance->folder = FALSE;
34  }
35  if (self::$instance->folder) {
36  // Load the english language to be sure all errors are defined, even if the other languages miss some errors
37  self::$instance->LoadLanguage("en");
38  // Load the favorite language
39  if ($language) {
40  self::$instance->LoadLanguage($language);
41  }
42  }
43  }
44 
49  private static function LoadLanguage($language) {
50  $filename = self::$instance->folder . "errors_" . $language . ".php";
51  if (self::$instance->language != $language && file_exists($filename)) {
52  // Set the current language
53  self::$instance->language = $language;
54  // Initialize the errors array and include the language file
55  $errors = array();
56  include_once $filename;
57  // Load the custom language file if exists
58  $filename = self::$instance->folder . "errors_" . $language . "_custom.php";
59  if (file_exists($filename))
60  include_once $filename;
61  if (isset($errors) && is_array($errors)) {
62  self::$instance->messages = array_merge(self::$instance->messages, $errors);
63  }
64  }
65  }
66 
73  public static function Get($errorName) {
74  if (array_key_exists($errorName, self::$instance->messages)) {
75  return self::$instance->messages[$errorName];
76  }
77  return "";
78  }
79 
84  public static function GetLanguage() {
85  return self::$instance->language;
86  }
87 }
static Get($errorName)
Definition: Account.php:3
static Initialize($language="en")