--- /dev/null
+<?php
+/**
+ * The language sub-system for handling language strings being used in the
+ * application and whole framework
+ */
+class LanguageSystem extends BaseFrameworkSystem implements ManageableLanguage {
+ /**
+ * The full-qualified base path for the language include files
+ */
+ private $basePath = "";
+
+ /**
+ * The 2-char language code
+ */
+ private $langCode = "xx"; // This will later be overwritten!
+
+ /**
+ * The array-object for all language strings
+ */
+ private $langStrings = null;
+
+ /**
+ * An instance of this class
+ */
+ private static $thisInstance = null;
+
+ /**
+ * Private constructor
+ *
+ * @return void
+ */
+ private final function __construct () {
+ // Call parent constructor
+ parent::constructor(__CLASS__);
+
+ // Set part description
+ $this->setPartDescr("Sprachsystem");
+
+ // Create unique ID number
+ $this->createUniqueID();
+
+ // Clean up a little
+ $this->removeNumberFormaters();
+ $this->removeSystemArray();
+ }
+
+ /**
+ * Creates an instance of the class LanguageSystem and prepares it for usage
+ *
+ * @param $basePath The local base path for all language strings
+ * @return $langInstance An instance of LanguageSystem
+ * @throws LanguagePathIsEmptyException If the provided $basePath is empty
+ * @throws InvalidLanguagePathStringException If $basePath is no string
+ * @throws LanguagePathIsNoDirectoryException If $basePath is no
+ * directory or not found
+ * @throws LanguagePathReadProtectedException If $basePath is
+ * read-protected
+ */
+ public final static function createLanguageSystem ($basePath) {
+ // Get a new instance
+ $langInstance = new LanguageSystem();
+
+ // Is the base path valid?
+ if (empty($basePath)) {
+ // Language path is empty
+ throw new LanguagePathIsEmptyException($langInstance, self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
+ } elseif (!is_string($basePath)) {
+ // Is not a string
+ throw new InvalidLanguagePathStringException(array($langInstance, $basePath), self::EXCEPTION_INVALID_STRING);
+ } elseif (!is_dir($basePath)) {
+ // Is not a path
+ throw new LanguagePathIsNoDirectoryException(array($langInstance, $basePath), self::EXCEPTION_INVALID_PATH_NAME);
+ } elseif (!is_readable($basePath)) {
+ // Is not readable
+ throw new LanguagePathReadProtectedException(array($langInstance, $basePath), self::EXCEPTION_READ_PROTECED_PATH);
+ }
+
+ // Set the base path
+ $langInstance->setBasePath($basePath);
+
+ // Initialize the variable stack
+ $langInstance->initLanguageStrings();
+
+ // Set language code from default config
+ $langInstance->setLanguageCode($langInstance->getConfigInstance()->readConfig("default_lang"));
+
+ // Remember this instance
+ self::$thisInstance = $langInstance;
+
+ // Return the prepared instance
+ return $langInstance;
+ }
+
+ /**
+ * Singleton getter for this instance
+ *
+ * @return $thisInstance An instance of this class
+ */
+ public final static function getInstance () {
+ return self::$thisInstance;
+ }
+
+ /**
+ * Initialize the array-object for all later language strings
+ *
+ * @return void
+ */
+ public function initLanguageStrings () {
+ $this->langStrings = new FrameworkArrayObject();
+ }
+
+ /**
+ * Setter for base path
+ *
+ * @param $basePath The local base path for all templates
+ * @return void
+ */
+ public final function setBasePath ($basePath) {
+ // Cast it
+ $basePath = (string) $basePath;
+
+ // And set it
+ $this->basePath = $basePath;
+ }
+
+ /**
+ * Getter for language code
+ *
+ * @return $langCode The language code for the current application
+ */
+ public final function getLanguageCode () {
+ return $this->langCode;
+ }
+
+ /**
+ * Setter for language code
+ *
+ * @param $langCode The language code for the current application
+ * @return void
+ */
+ public final function setLanguageCode ($langCode) {
+ // Cast it
+ $langCode = (string) $langCode;
+
+ // And set it (only 2 chars)
+ $this->langCode = substr($langCode, 0, 2);
+ }
+}
+
+// [EOF]
+?>