]> git.mxchange.org Git - core.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Thu, 21 Aug 2025 22:57:29 +0000 (00:57 +0200)
committerRoland Häder <roland@mxchange.org>
Thu, 21 Aug 2025 22:57:29 +0000 (00:57 +0200)
- added more type-hints
- copied all public function to interface ManageableLanguage
- introduced new function isDirectoryIteratorInstanceSet() to avoid "abusive"
  invocations of getter

framework/main/classes/file_directories/directory/class_FrameworkDirectoryPointer.php
framework/main/classes/language/class_LanguageSystem.php
framework/main/interfaces/io/directory/class_FrameworkDirectory.php
framework/main/interfaces/iterator/registry/class_IteratableRegistry.php
framework/main/interfaces/language/class_ManageableLanguage.php

index f080e3281e1107430d23f36ea77135f7df59bc9c..7e628ccf1cb3ce6d75432d73089704958e5e2d5c 100644 (file)
@@ -14,6 +14,7 @@ use Org\Mxchange\CoreFramework\Deprecated\PathIsNoDirectoryException;
 // Import SPL stuff
 use \DirectoryIterator;
 use \InvalidArgumentException;
+use \SplFileInfo;
 
 /**
  * A class for directory reading and getting its contents, no recursion!
@@ -62,7 +63,7 @@ class FrameworkDirectoryPointer extends BaseFrameworkSystem implements Framework
        public function __destruct() {
                // Is there a resource pointer? Then we have to close the directory here!
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('FRAMEWORK-DIRECTORY-POINTER: DESTRUCTED!');
-               if ($this->getDirectoryIteratorInstance() instanceof DirectoryIterator) {
+               if ($this->isDirectoryIteratorInstanceSet()) {
                        // Try to close a directory
                        $this->closeDirectory();
                }
@@ -85,7 +86,7 @@ class FrameworkDirectoryPointer extends BaseFrameworkSystem implements Framework
         * @throws      PathIsNoDirectoryException      If the provided path name is not valid
         * @throws      PathReadProtectedException      If the provided path name is read-protected
         */
-       public static final function createFrameworkDirectoryPointer (string $pathName) {
+       public static final function createFrameworkDirectoryPointer (string $pathName): FrameworkDirectory {
                // Some pre-sanity checks...
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('FRAMEWORK-DIRECTORY-POINTER: pathName=%s - CALLED!', $pathName));
                if (empty($pathName)) {
@@ -122,7 +123,7 @@ class FrameworkDirectoryPointer extends BaseFrameworkSystem implements Framework
         *
         * @return      $currentEntry   Current entry from encapsulated iterator
         */
-       public function readRawDirectory () {
+       public function readRawDirectory (): mixed {
                // Can the next entry be read?
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('DIRECTORY-POINTER: CALLED!');
                assert($this->getDirectoryIteratorInstance()->valid());
@@ -139,10 +140,10 @@ class FrameworkDirectoryPointer extends BaseFrameworkSystem implements Framework
         * Read lines from the current directory pointer except some parts
         *
         * @param       $except         Some parts of a directory we want to ignore. Valid: directory and file names, other values will be silently ignored
-        * @return      SplFileInfo             An instance of a SplFileInfo class
+        * @return      SplFileInfo             An instance of a SplFileInfo class or NULL when no more entries are left
         * @throws      InvalidArgumentException        If a parameter has an invalid value
         */
-       public function readDirectoryExcept (array $except = []) {
+       public function readDirectoryExcept (array $except = []): ?SplFileInfo {
                // No exceptions given?
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('DIRECTORY-POINTER: except()=%d - CALLED!', count($except)));
                if (count($except) == 0) {
@@ -190,7 +191,7 @@ class FrameworkDirectoryPointer extends BaseFrameworkSystem implements Framework
         *
         * @return      void
         */
-       public function closeDirectory () {
+       public function closeDirectory (): void {
                // Close the directory by unsetting it
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('DIRECTORY-POINTER: CALLED!');
                $this->unsetDirectoryIteratorInstance();
@@ -206,7 +207,7 @@ class FrameworkDirectoryPointer extends BaseFrameworkSystem implements Framework
         * @param       $iteratorInstance       An instanceof a DirectoryIterator class
         * @return      void
         */
-       protected final function setDirectoryIteratorInstance (DirectoryIterator $iteratorInstance) {
+       protected final function setDirectoryIteratorInstance (DirectoryIterator $iteratorInstance): void {
                // Set instance
                $this->iteratorInstance = $iteratorInstance;
        }
@@ -216,10 +217,19 @@ class FrameworkDirectoryPointer extends BaseFrameworkSystem implements Framework
         *
         * @return      $iteratorInstance       The directory pointer which shall be a valid directory resource
         */
-       public final function getDirectoryIteratorInstance () {
+       public final function getDirectoryIteratorInstance (): DirectoryIterator {
                return $this->iteratorInstance;
        }
 
+       /**
+        * Checks if a DirectoryIterator instance is set
+        *
+        * @return<>$isset<>Whether a DirectoryIterator instance is set
+        */
+       public final function isDirectoryIteratorInstanceSet (): bool {
+               return ($this->iteratorInstance instanceof DirectoryIterator);
+       }
+
        /**
         * Remove directory iterator instance (effectively closing it) by setting
         * it to NULL. This will trigger a call on the destructor which will then
@@ -228,7 +238,7 @@ class FrameworkDirectoryPointer extends BaseFrameworkSystem implements Framework
         * @param       $iteratorInstance       An instanceof a DirectoryIterator class
         * @return      void
         */
-       protected final function unsetDirectoryIteratorInstance () {
+       protected final function unsetDirectoryIteratorInstance (): void {
                // "Unset" the instance
                $this->iteratorInstance = NULL;
        }
@@ -239,7 +249,7 @@ class FrameworkDirectoryPointer extends BaseFrameworkSystem implements Framework
         * @param       $pathName       The new path name
         * @return      void
         */
-       protected final function setPathName (string $pathName) {
+       protected final function setPathName (string $pathName): void {
                $this->pathName = $pathName;
        }
 
@@ -248,7 +258,7 @@ class FrameworkDirectoryPointer extends BaseFrameworkSystem implements Framework
         *
         * @return      $pathName       The current path name
         */
-       public final function getPathName () {
+       public final function getPathName (): string {
                return $this->pathName;
        }
 
index 44e8801f9b844a986e70737aa4a63709c4420b65..f46e8ed21a14d424a5df9318f1e3e1ec2e7a7fbe 100644 (file)
@@ -80,7 +80,7 @@ class LanguageSystem extends BaseFrameworkSystem implements ManageableLanguage,
         * @throws      InvalidArgumentException        If $languageBasePath is
         *                                                                              read-protected
         */
-       public static final function createLanguageSystem (string $languageBasePath = '') {
+       public static final function createLanguageSystem (string $languageBasePath = ''): ManageableLanguage {
                // Get a new instance
                $langInstance = new LanguageSystem();
 
@@ -130,7 +130,7 @@ class LanguageSystem extends BaseFrameworkSystem implements ManageableLanguage,
         *
         * @return      $selfInstance   An instance of this class
         */
-       public static final function getSelfInstance () {
+       public static final function getSelfInstance (): ManageableLanguage {
                return self::$selfInstance;
        }
 
@@ -140,7 +140,7 @@ class LanguageSystem extends BaseFrameworkSystem implements ManageableLanguage,
         * @param       $languageBasePath       The relative base path for all language files
         * @return      void
         */
-       protected final function setLanguageBasePath (string $languageBasePath) {
+       protected final function setLanguageBasePath (string $languageBasePath): void {
                // And set it
                $this->languageBasePath = $languageBasePath;
        }
@@ -151,7 +151,7 @@ class LanguageSystem extends BaseFrameworkSystem implements ManageableLanguage,
         * @param       $langCode       The language code for the current application
         * @return      void
         */
-       protected final function setLanguageCode (string $langCode) {
+       protected final function setLanguageCode (string $langCode): void {
                // And set it (only 2 chars)
                $this->langCode = substr($langCode, 0, 2);
        }
@@ -161,7 +161,7 @@ class LanguageSystem extends BaseFrameworkSystem implements ManageableLanguage,
         *
         * @return      void
         */
-       public function initLanguageStrings () {
+       public function initLanguageStrings (): void {
                /*
                 * Locale category constants are usually predefined, but may not be
                 * on some systems such as Win32.
@@ -193,7 +193,7 @@ class LanguageSystem extends BaseFrameworkSystem implements ManageableLanguage,
         *
         * @return      $langCode       The language code for the current application
         */
-       public final function getLanguageCode () {
+       public final function getLanguageCode (): string {
                return $this->langCode;
        }
 
@@ -203,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 (string $messageId) {
+       public function getMessage (string $messageId): string {
                // Default is missing message text
                $messageText = sprintf('!%s!',
                        $messageId
index 7c50bea77fdbc9d9dcf2868d222d9720ce4b722c..8c99c9290d551a2c46bdcaa7eafdf2026bf50168 100644 (file)
@@ -5,6 +5,10 @@ namespace Org\Mxchange\CoreFramework\Filesystem;
 // Import framework stuff
 use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
 
+// Import SPL stuff
+use \DirectoryIterator;
+use \SplFileInfo;
+
 /**
  * An interface for directorties
  *
@@ -33,15 +37,15 @@ interface FrameworkDirectory extends FrameworkInterface {
         *
         * @return      $currentEntry   Current entry from encapsulated iterator
         */
-       function readRawDirectory ();
+       function readRawDirectory (): mixed;
 
        /**
         * Read lines from the current directory pointer except some parts
         *
         * @param       $except         Some parts of a directory we want to ignore. Valid: directory and file names, other values will be silently ignored
-        * @return      SplFileInfo             An instance of a SplFileInfo class
+        * @return      SplFileInfo             An instance of a SplFileInfo class or NULL when no more entries are left
         */
-       function readDirectoryExcept (array $except = []);
+       function readDirectoryExcept (array $except = []): ?SplFileInfo;
 
        /**
         * Close a directory source and set it's instance to null and the path name
@@ -49,20 +53,27 @@ interface FrameworkDirectory extends FrameworkInterface {
         *
         * @return      void
         */
-       function closeDirectory ();
+       function closeDirectory (): void;
 
        /**
         * Getter for the directory pointer
         *
         * @return      $iteratorInstance       The directory pointer which shall be a valid directory resource
         */
-       function getDirectoryIteratorInstance ();
+       function getDirectoryIteratorInstance (): DirectoryIterator;
+
+       /**
+        * Checks if a DirectoryIterator instance is set
+        *
+        * @return      $isset  Whether a DirectoryIterator instance is set
+        */
+       function isDirectoryIteratorInstanceSet (): bool;
 
        /**
         * Getter for path name
         *
         * @return      $pathName       The current path name
         */
-       function getPathName ();
+       function getPathName (): string;
 
 }
index b3155197b456763dc36f1db6f3136432321183e3..4ffd58e9c99ff99974f4dc3d863882081da55e83 100644 (file)
@@ -40,6 +40,6 @@ interface IteratableRegistry extends FrameworkInterface, Iterator {
         * @throws      LogicException  If a registry entry does not implement Registerable
         * @throws      NullPointerException    If criteriaKey or criteriaMethod is not set but a call-back instance is set
         */
-       function initIterator (array $onlyRegistries = []);
+       function initIterator (array $onlyRegistries = []): void;
 
 }
index 06677c4be228c6de9592525d025c7582514e3386..95e9197cb8f83abfd619f4d1a6e5ce0c79c89e78 100644 (file)
@@ -33,6 +33,21 @@ interface ManageableLanguage extends FrameworkInterface {
         *
         * @return      void
         */
-       function initLanguageStrings();
+       function initLanguageStrings(): void;
+
+       /**
+        * Getter for language code
+        *
+        * @return      $langCode       The language code for the current application
+        */
+       function getLanguageCode (): string;
+
+       /**
+        * Get the plain message from the cache variable for the given message id
+        *
+        * @param       $messageId              The message id we shall find in the cache variable
+        * @return      $messageText    The plain message text
+        */
+       function getMessage (string $messageId): string;
 
 }