class_LanguageSystem.php

Go to the documentation of this file.
00001 <?php
00025 class LanguageSystem extends BaseFrameworkSystem implements ManageableLanguage {
00029         private $basePath = "";
00030 
00034         private $langCode = "xx"; // This will later be overwritten!
00035 
00039         private $langStrings = null;
00040 
00044         private static $thisInstance = null;
00045 
00051         protected function __construct () {
00052                 // Call parent constructor
00053                 parent::__construct(__CLASS__);
00054 
00055                 // Clean up a little
00056                 $this->removeNumberFormaters();
00057                 $this->removeSystemArray();
00058         }
00059 
00072         public final static function createLanguageSystem ($basePath) {
00073                 // Get a new instance
00074                 $langInstance = new LanguageSystem();
00075 
00076                 // Is the base path valid?
00077                 if (empty($basePath)) {
00078                         // Language path is empty
00079                         throw new LanguagePathIsEmptyException($langInstance, self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
00080                 } elseif (!is_string($basePath)) {
00081                         // Is not a string
00082                         throw new InvalidLanguagePathStringException(array($langInstance, $basePath), self::EXCEPTION_INVALID_STRING);
00083                 } elseif (!is_dir($basePath)) {
00084                         // Is not a path
00085                         throw new LanguagePathIsNoDirectoryException(array($langInstance, $basePath), self::EXCEPTION_INVALID_PATH_NAME);
00086                 } elseif (!is_readable($basePath)) {
00087                         // Is not readable
00088                         throw new LanguagePathReadProtectedException(array($langInstance, $basePath), self::EXCEPTION_READ_PROTECED_PATH);
00089                 }
00090 
00091                 // Set the base path
00092                 $langInstance->setBasePath($basePath);
00093 
00094                 // Initialize the variable stack
00095                 $langInstance->initLanguageStrings();
00096 
00097                 // Set language code from default config
00098                 $langInstance->setLanguageCode(FrameworkConfiguration::getInstance()->readConfig('default_lang'));
00099 
00100                 // Remember this instance
00101                 self::$thisInstance = $langInstance;
00102 
00103                 // Return the prepared instance
00104                 return $langInstance;
00105         }
00106 
00112         public final static function getInstance () {
00113                 return self::$thisInstance;
00114         }
00115 
00122         protected final function setBasePath ($basePath) {
00123                 // And set it
00124                 $this->basePath = (string) $basePath;
00125         }
00126 
00133         protected final function setLanguageCode ($langCode) {
00134                 // Cast it
00135                 $langCode = (string) $langCode;
00136 
00137                 // And set it (only 2 chars)
00138                 $this->langCode = substr($langCode, 0, 2);
00139         }
00140 
00146         public function initLanguageStrings () {
00147                 $this->langStrings = new FrameworkArrayObject("FakedLanguageStrings");
00148         }
00149 
00155         public final function getLanguageCode () {
00156                 return $this->langCode;
00157         }
00158 
00165         public function getMessage ($messageId) {
00166                 // Default is missing message text
00167                 $messageText = sprintf("!%s!",
00168                         $messageId
00169                 );
00170 
00171                 // Try to look it up in the cache variable
00172                 if ($this->langStrings->offsetExists($messageId)) {
00173                         // Return the message string
00174                         $messageText = $this->langStrings->offsetGet($messageId);
00175                 }
00176 
00177                 // Return the text
00178                 return $messageText;
00179         }
00180 }
00181 
00182 // [EOF]
00183 ?>

Generated on Mon Dec 8 01:06:46 2008 for Ship-Simulator by  doxygen 1.5.6