// Import SPL stuff
use \DirectoryIterator;
use \InvalidArgumentException;
+use \SplFileInfo;
/**
* A class for directory reading and getting its contents, no recursion!
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();
}
* @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)) {
*
* @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());
* 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) {
*
* @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();
* @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;
}
*
* @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
* @param $iteratorInstance An instanceof a DirectoryIterator class
* @return void
*/
- protected final function unsetDirectoryIteratorInstance () {
+ protected final function unsetDirectoryIteratorInstance (): void {
// "Unset" the instance
$this->iteratorInstance = NULL;
}
* @param $pathName The new path name
* @return void
*/
- protected final function setPathName (string $pathName) {
+ protected final function setPathName (string $pathName): void {
$this->pathName = $pathName;
}
*
* @return $pathName The current path name
*/
- public final function getPathName () {
+ public final function getPathName (): string {
return $this->pathName;
}
* @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();
*
* @return $selfInstance An instance of this class
*/
- public static final function getSelfInstance () {
+ public static final function getSelfInstance (): ManageableLanguage {
return self::$selfInstance;
}
* @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;
}
* @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);
}
*
* @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.
*
* @return $langCode The language code for the current application
*/
- public final function getLanguageCode () {
+ public final function getLanguageCode (): string {
return $this->langCode;
}
* @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
// Import framework stuff
use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
+// Import SPL stuff
+use \DirectoryIterator;
+use \SplFileInfo;
+
/**
* An interface for directorties
*
*
* @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
*
* @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;
}