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";
00035
00039 private $langStrings = null;
00040
00044 private static $thisInstance = null;
00045
00051 protected function __construct () {
00052
00053 parent::__construct(__CLASS__);
00054
00055
00056 $this->removeNumberFormaters();
00057 $this->removeSystemArray();
00058 }
00059
00072 public final static function createLanguageSystem ($basePath) {
00073
00074 $langInstance = new LanguageSystem();
00075
00076
00077 if (empty($basePath)) {
00078
00079 throw new LanguagePathIsEmptyException($langInstance, self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
00080 } elseif (!is_string($basePath)) {
00081
00082 throw new InvalidLanguagePathStringException(array($langInstance, $basePath), self::EXCEPTION_INVALID_STRING);
00083 } elseif (!is_dir($basePath)) {
00084
00085 throw new LanguagePathIsNoDirectoryException(array($langInstance, $basePath), self::EXCEPTION_INVALID_PATH_NAME);
00086 } elseif (!is_readable($basePath)) {
00087
00088 throw new LanguagePathReadProtectedException(array($langInstance, $basePath), self::EXCEPTION_READ_PROTECED_PATH);
00089 }
00090
00091
00092 $langInstance->setBasePath($basePath);
00093
00094
00095 $langInstance->initLanguageStrings();
00096
00097
00098 $langInstance->setLanguageCode(FrameworkConfiguration::getInstance()->readConfig('default_lang'));
00099
00100
00101 self::$thisInstance = $langInstance;
00102
00103
00104 return $langInstance;
00105 }
00106
00112 public final static function getInstance () {
00113 return self::$thisInstance;
00114 }
00115
00122 protected final function setBasePath ($basePath) {
00123
00124 $this->basePath = (string) $basePath;
00125 }
00126
00133 protected final function setLanguageCode ($langCode) {
00134
00135 $langCode = (string) $langCode;
00136
00137
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
00167 $messageText = sprintf("!%s!",
00168 $messageId
00169 );
00170
00171
00172 if ($this->langStrings->offsetExists($messageId)) {
00173
00174 $messageText = $this->langStrings->offsetGet($messageId);
00175 }
00176
00177
00178 return $messageText;
00179 }
00180 }
00181
00182
00183 ?>