]> git.mxchange.org Git - core.git/blobdiff - framework/main/classes/language/class_LanguageSystem.php
Continued:
[core.git] / framework / main / classes / language / class_LanguageSystem.php
index c8cc07a08309ea3f48ac2b95a158e5b9fb05d342..44e8801f9b844a986e70737aa4a63709c4420b65 100644 (file)
@@ -4,11 +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;
@@ -19,7 +20,7 @@ use \InvalidArgumentException;
  *
  * @author             Roland Haeder <webmaster@shipsimu.org>
  * @version            0.0.0
- * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2020 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
  *
@@ -62,7 +63,7 @@ class LanguageSystem extends BaseFrameworkSystem implements ManageableLanguage,
         *
         * @return      void
         */
-       protected function __construct () {
+       private function __construct () {
                // Call parent constructor
                parent::__construct(__CLASS__);
        }
@@ -87,19 +88,19 @@ 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/',
                                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');
+                       throw new InvalidArgumentException('languageBasePath is still empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
                } elseif (!is_dir($languageBasePath)) {
                        // Is not a path
                        throw new InvalidArgumentException(sprintf('languageBasePath=%s not found', $languageBasePath), self::EXCEPTION_INVALID_PATH_NAME);
@@ -141,7 +142,7 @@ class LanguageSystem extends BaseFrameworkSystem implements ManageableLanguage,
         */
        protected final function setLanguageBasePath (string $languageBasePath) {
                // And set it
-               $this->languageBasePath = (string) $languageBasePath;
+               $this->languageBasePath = $languageBasePath;
        }
 
        /**
@@ -167,7 +168,7 @@ class LanguageSystem extends BaseFrameworkSystem implements ManageableLanguage,
                 *
                 * Origin: StatusNet's lib/language.php
                 */
-               $localeCategories = array(
+               foreach ([
                        'LC_CTYPE',
                        'LC_NUMERIC',
                        'LC_TIME',
@@ -175,16 +176,13 @@ 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');
@@ -215,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;