X-Git-Url: https://git.mxchange.org/?p=core.git;a=blobdiff_plain;f=framework%2Fmain%2Fclasses%2Flanguage%2Fclass_LanguageSystem.php;h=44e8801f9b844a986e70737aa4a63709c4420b65;hp=6dfbe3bb9c228121bbc01ec848cd285aeae90f5a;hb=HEAD;hpb=8d8cf621bd811811cecd83c65a4ab91f27258e79 diff --git a/framework/main/classes/language/class_LanguageSystem.php b/framework/main/classes/language/class_LanguageSystem.php index 6dfbe3bb..44e8801f 100644 --- a/framework/main/classes/language/class_LanguageSystem.php +++ b/framework/main/classes/language/class_LanguageSystem.php @@ -4,9 +4,12 @@ namespace Org\Mxchange\CoreFramework\Localization; // Import framework stuff use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap; +use Org\Mxchange\CoreFramework\Helper\Application\ApplicationHelper; +use Org\Mxchange\CoreFramework\Generic\FrameworkInterface; +use Org\Mxchange\CoreFramework\Localization\ManageableLanguage; use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem; +use Org\Mxchange\CoreFramework\ObjectArray\FrameworkArrayObject; use Org\Mxchange\CoreFramework\Registry\Registerable; -use Org\Mxchange\CoreFramework\Registry\GenericRegistry; // Import SPL stuff use \InvalidArgumentException; @@ -17,7 +20,7 @@ use \InvalidArgumentException; * * @author Roland Haeder * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2023 Core Developer Team * @license GNU GPL 3.0 or any newer version * @link http://www.shipsimu.org * @@ -60,7 +63,7 @@ class LanguageSystem extends BaseFrameworkSystem implements ManageableLanguage, * * @return void */ - protected function __construct () { + private function __construct () { // Call parent constructor parent::__construct(__CLASS__); } @@ -71,13 +74,13 @@ class LanguageSystem extends BaseFrameworkSystem implements ManageableLanguage, * @param $languageBasePath The local base path for all language strings or emty for auto-detection * @return $langInstance An instance of LanguageSystem * @throws InvalidArgumentException If languageBasePath remains empty (@TODO Get rid of that old-lost code) - * @throws InvalidLanguagePathStringException If $languageBasePath is no string - * @throws LanguagePathIsNoDirectoryException If $languageBasePath is no + * @throws InvalidArgumentException If $languageBasePath is no string + * @throws InvalidArgumentException If $languageBasePath is no * directory or not found - * @throws LanguagePathReadProtectedException If $languageBasePath is + * @throws InvalidArgumentException If $languageBasePath is * read-protected */ - public static final function createLanguageSystem ($languageBasePath = '') { + public static final function createLanguageSystem (string $languageBasePath = '') { // Get a new instance $langInstance = new LanguageSystem(); @@ -85,28 +88,25 @@ class LanguageSystem extends BaseFrameworkSystem implements ManageableLanguage, if (empty($languageBasePath)) { // No, then attempt "auto-dection": // 1) Get application - $applicationInstance = GenericRegistry::getRegistry()->getInstance('application'); + $applicationInstance = ApplicationHelper::getSelfInstance(); // 2) Try to build it $languageBasePath = sprintf('%s%s/language/', - $langInstance->getConfigInstance()->getConfigEntry('application_base_path'), + FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('application_base_path'), $applicationInstance->getAppShortName() ); - } // END - if + } // Is the base path valid? if (empty($languageBasePath)) { // Language path is empty - throw new InvalidArgumentException('languageBasePath is still empty'); - } elseif (!is_string($languageBasePath)) { - // Is not a string - throw new InvalidLanguagePathStringException(array($langInstance, $languageBasePath), self::EXCEPTION_INVALID_STRING); + throw new InvalidArgumentException('languageBasePath is still empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); } elseif (!is_dir($languageBasePath)) { // Is not a path - throw new LanguagePathIsNoDirectoryException(array($langInstance, $languageBasePath), self::EXCEPTION_INVALID_PATH_NAME); + throw new InvalidArgumentException(sprintf('languageBasePath=%s not found', $languageBasePath), self::EXCEPTION_INVALID_PATH_NAME); } elseif (!is_readable($languageBasePath)) { // Is not readable - throw new LanguagePathReadProtectedException(array($langInstance, $languageBasePath), self::EXCEPTION_READ_PROTECED_PATH); + throw new InvalidArgumentException(sprintf('Cannot read from languageBasePath=%s', $languageBasePath), self::EXCEPTION_READ_PROTECED_PATH); } // Set the base path @@ -140,9 +140,9 @@ class LanguageSystem extends BaseFrameworkSystem implements ManageableLanguage, * @param $languageBasePath The relative base path for all language files * @return void */ - protected final function setLanguageBasePath ($languageBasePath) { + protected final function setLanguageBasePath (string $languageBasePath) { // And set it - $this->languageBasePath = (string) $languageBasePath; + $this->languageBasePath = $languageBasePath; } /** @@ -151,10 +151,7 @@ class LanguageSystem extends BaseFrameworkSystem implements ManageableLanguage, * @param $langCode The language code for the current application * @return void */ - protected final function setLanguageCode ($langCode) { - // Cast it - $langCode = (string) $langCode; - + protected final function setLanguageCode (string $langCode) { // And set it (only 2 chars) $this->langCode = substr($langCode, 0, 2); } @@ -171,7 +168,7 @@ class LanguageSystem extends BaseFrameworkSystem implements ManageableLanguage, * * Origin: StatusNet's lib/language.php */ - $localeCategories = array( + foreach ([ 'LC_CTYPE', 'LC_NUMERIC', 'LC_TIME', @@ -179,17 +176,15 @@ class LanguageSystem extends BaseFrameworkSystem implements ManageableLanguage, 'LC_MONETARY', 'LC_MESSAGES', 'LC_ALL' - ); - - // Set all, if not defined - foreach ($localeCategories as $key => $name) { + ] as $key => $name) { // Is it set? if (!defined($name)) { // No, then set it define($name, $key); - } // END - if - } // END - foreach + } + } + // Init language strings array $this->langStrings = new FrameworkArrayObject('FakedLanguageStrings'); } @@ -208,7 +203,7 @@ class LanguageSystem extends BaseFrameworkSystem implements ManageableLanguage, * @param $messageId The message id we shall find in the cache variable * @return $messageText The plain message text */ - public function getMessage ($messageId) { + public function getMessage (string $messageId) { // Default is missing message text $messageText = sprintf('!%s!', $messageId @@ -218,7 +213,7 @@ class LanguageSystem extends BaseFrameworkSystem implements ManageableLanguage, if ($this->langStrings->offsetExists($messageId)) { // Return the message string $messageText = $this->langStrings->offsetGet($messageId); - } // END - if + } // Return the text return $messageText;