3 * The language sub-system for handling language strings being used in the
4 * application and whole framework
6 class LanguageSystem extends BaseFrameworkSystem implements ManageableLanguage {
8 * The full-qualified base path for the language include files
10 private $basePath = "";
13 * The 2-char language code
15 private $langCode = "xx"; // This will later be overwritten!
18 * The array-object for all language strings
20 private $langStrings = null;
23 * An instance of this class
25 private static $thisInstance = null;
32 private final function __construct () {
33 // Call parent constructor
34 parent::constructor(__CLASS__);
36 // Set part description
37 $this->setPartDescr("Sprachsystem");
39 // Create unique ID number
40 $this->createUniqueID();
43 $this->removeNumberFormaters();
44 $this->removeSystemArray();
48 * Creates an instance of the class LanguageSystem and prepares it for usage
50 * @param $basePath The local base path for all language strings
51 * @return $langInstance An instance of LanguageSystem
52 * @throws LanguagePathIsEmptyException If the provided $basePath is empty
53 * @throws InvalidLanguagePathStringException If $basePath is no string
54 * @throws LanguagePathIsNoDirectoryException If $basePath is no
55 * directory or not found
56 * @throws LanguagePathReadProtectedException If $basePath is
59 public final static function createLanguageSystem ($basePath) {
61 $langInstance = new LanguageSystem();
63 // Is the base path valid?
64 if (empty($basePath)) {
65 // Language path is empty
66 throw new LanguagePathIsEmptyException($langInstance, self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
67 } elseif (!is_string($basePath)) {
69 throw new InvalidLanguagePathStringException(array($langInstance, $basePath), self::EXCEPTION_INVALID_STRING);
70 } elseif (!is_dir($basePath)) {
72 throw new LanguagePathIsNoDirectoryException(array($langInstance, $basePath), self::EXCEPTION_INVALID_PATH_NAME);
73 } elseif (!is_readable($basePath)) {
75 throw new LanguagePathReadProtectedException(array($langInstance, $basePath), self::EXCEPTION_READ_PROTECED_PATH);
79 $langInstance->setBasePath($basePath);
81 // Initialize the variable stack
82 $langInstance->initLanguageStrings();
84 // Set language code from default config
85 $langInstance->setLanguageCode($langInstance->getConfigInstance()->readConfig("default_lang"));
87 // Remember this instance
88 self::$thisInstance = $langInstance;
90 // Return the prepared instance
95 * Singleton getter for this instance
97 * @return $thisInstance An instance of this class
99 public final static function getInstance () {
100 return self::$thisInstance;
104 * Initialize the array-object for all later language strings
108 public function initLanguageStrings () {
109 $this->langStrings = new FrameworkArrayObject();
113 * Setter for base path
115 * @param $basePath The local base path for all templates
118 public final function setBasePath ($basePath) {
120 $basePath = (string) $basePath;
123 $this->basePath = $basePath;
127 * Getter for language code
129 * @return $langCode The language code for the current application
131 public final function getLanguageCode () {
132 return $this->langCode;
136 * Setter for language code
138 * @param $langCode The language code for the current application
141 public final function setLanguageCode ($langCode) {
143 $langCode = (string) $langCode;
145 // And set it (only 2 chars)
146 $this->langCode = substr($langCode, 0, 2);