]> git.mxchange.org Git - core.git/blob - framework/main/classes/class_BaseFrameworkSystem.php
Continued:
[core.git] / framework / main / classes / class_BaseFrameworkSystem.php
1 <?php
2 // Own namespace
3 namespace Org\Mxchange\CoreFramework\Object;
4
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
7 use Org\Mxchange\CoreFramework\EntryPoint\ApplicationEntryPoint;
8 use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory;
9 use Org\Mxchange\CoreFramework\Filesystem\FileIoException;
10 use Org\Mxchange\CoreFramework\Filesystem\PathWriteProtectedException;
11 use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
12 use Org\Mxchange\CoreFramework\Generic\NullPointerException;
13 use Org\Mxchange\CoreFramework\Generic\UnsupportedOperationException;
14 use Org\Mxchange\CoreFramework\Helper\Application\ApplicationHelper;
15 use Org\Mxchange\CoreFramework\Loader\ClassLoader;
16 use Org\Mxchange\CoreFramework\Manager\ManageableApplication;
17 use Org\Mxchange\CoreFramework\Middleware\Debug\DebugMiddleware;
18 use Org\Mxchange\CoreFramework\Registry\GenericRegistry;
19 use Org\Mxchange\CoreFramework\Result\Database\CachedDatabaseResult;
20 use Org\Mxchange\CoreFramework\State\Stateable;
21 use Org\Mxchange\CoreFramework\Stream\Output\OutputStreamer;
22 use Org\Mxchange\CoreFramework\Utils\Strings\StringUtils;
23
24 // Import SPL stuff
25 use \BadMethodCallException;
26 use \InvalidArgumentException;
27 use \ReflectionClass;
28 use \SplFileInfo;
29 use \stdClass;
30
31 /**
32  * The simulator system class is the super class of all other classes. This
33  * class handles saving of games etc.
34  *
35  * @author              Roland Haeder <webmaster@shipsimu.org>
36  * @version             0.0.0
37  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2023 Core Developer Team
38  * @license             GNU GPL 3.0 or any newer version
39  * @link                http://www.shipsimu.org
40  *
41  * This program is free software: you can redistribute it and/or modify
42  * it under the terms of the GNU General Public License as published by
43  * the Free Software Foundation, either version 3 of the License, or
44  * (at your option) any later version.
45  *
46  * This program is distributed in the hope that it will be useful,
47  * but WITHOUT ANY WARRANTY; without even the implied warranty of
48  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
49  * GNU General Public License for more details.
50  *
51  * You should have received a copy of the GNU General Public License
52  * along with this program. If not, see <http://www.gnu.org/licenses/>.
53  */
54 abstract class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
55         /**
56          * Self-referencing instance
57          */
58         private static $selfInstance = NULL;
59
60         /**
61          * Debug instance
62          */
63         private static $debugInstance = NULL;
64
65         /**
66          * Stub methods
67          */
68         private static $stubMethods = [
69                 'partialStub' => true,
70                 '__call' => true,
71                 '__callStatic' => true,
72         ];
73
74         /**
75          * The real class name
76          */
77         private $realClass = __CLASS__;
78
79         /**
80          * Call-back instance
81          */
82         private $callbackInstance = NULL;
83
84         /**
85          * Generic array
86          */
87         private $genericArray = [];
88
89         /***********************
90          * Exception codes.... *
91          ***********************/
92
93         // @todo Try to clean these constants up
94         const EXCEPTION_IS_NULL_POINTER              = 0x001;
95         const EXCEPTION_IS_NO_OBJECT                 = 0x002;
96         const EXCEPTION_IS_NO_ARRAY                  = 0x003;
97         const EXCEPTION_MISSING_METHOD               = 0x004;
98         const EXCEPTION_CLASSES_NOT_MATCHING         = 0x005;
99         const EXCEPTION_INDEX_OUT_OF_BOUNDS          = 0x006;
100         const EXCEPTION_DIMENSION_ARRAY_INVALID      = 0x007;
101         const EXCEPTION_ITEM_NOT_TRADEABLE           = 0x008;
102         const EXCEPTION_ITEM_NOT_IN_PRICE_LIST       = 0x009;
103         const EXCEPTION_GENDER_IS_WRONG              = 0x00a;
104         const EXCEPTION_BIRTH_DATE_IS_INVALID        = 0x00b;
105         const EXCEPTION_EMPTY_STRUCTURES_ARRAY       = 0x00c;
106         const EXCEPTION_HAS_ALREADY_PERSONELL_LIST   = 0x00d;
107         const EXCEPTION_NOT_ENOUGTH_UNEMPLOYEES      = 0x00e;
108         const EXCEPTION_TOTAL_PRICE_NOT_CALCULATED   = 0x00f;
109         const EXCEPTION_HARBOR_HAS_NO_SHIPYARDS      = 0x010;
110         const EXCEPTION_CONTRACT_PARTNER_INVALID     = 0x011;
111         const EXCEPTION_CONTRACT_PARTNER_MISMATCH    = 0x012;
112         const EXCEPTION_CONTRACT_ALREADY_SIGNED      = 0x013;
113         const EXCEPTION_UNEXPECTED_EMPTY_STRING      = 0x014;
114         const EXCEPTION_PATH_NOT_FOUND               = 0x015;
115         const EXCEPTION_INVALID_PATH_NAME            = 0x016;
116         const EXCEPTION_READ_PROTECED_PATH           = 0x017;
117         const EXCEPTION_WRITE_PROTECED_PATH          = 0x018;
118         const EXCEPTION_DIR_POINTER_INVALID          = 0x019;
119         const EXCEPTION_FILE_POINTER_INVALID         = 0x01a;
120         const EXCEPTION_INVALID_RESOURCE             = 0x01b;
121         const EXCEPTION_UNEXPECTED_OBJECT            = 0x01c;
122         const EXCEPTION_LIMIT_ELEMENT_IS_UNSUPPORTED = 0x01d;
123         const EXCEPTION_GETTER_IS_MISSING            = 0x01e;
124         const EXCEPTION_ARRAY_EXPECTED               = 0x01f;
125         const EXCEPTION_ARRAY_HAS_INVALID_COUNT      = 0x020;
126         const EXCEPTION_ID_IS_INVALID_FORMAT         = 0x021;
127         const EXCEPTION_MD5_CHECKSUMS_MISMATCH       = 0x022;
128         const EXCEPTION_UNEXPECTED_STRING_SIZE       = 0x023;
129         const EXCEPTION_SIMULATOR_ID_INVALID         = 0x024;
130         const EXCEPTION_MISMATCHING_COMPRESSORS      = 0x025;
131         const EXCEPTION_CONTAINER_ITEM_IS_NULL       = 0x026;
132         const EXCEPTION_ITEM_IS_NO_ARRAY             = 0x027;
133         const EXCEPTION_CONTAINER_MAYBE_DAMAGED      = 0x028;
134         const EXCEPTION_INVALID_STRING               = 0x029;
135         const EXCEPTION_VARIABLE_NOT_SET             = 0x02a;
136         const EXCEPTION_ATTRIBUTES_ARE_MISSING       = 0x02b;
137         const EXCEPTION_ARRAY_ELEMENTS_MISSING       = 0x02c;
138         const EXCEPTION_TEMPLATE_ENGINE_UNSUPPORTED  = 0x02d;
139         const EXCEPTION_FACTORY_REQUIRE_PARAMETER    = 0x02e;
140         const EXCEPTION_MISSING_ELEMENT              = 0x02f;
141         const EXCEPTION_HEADERS_ALREADY_SENT         = 0x030;
142         const EXCEPTION_DEFAULT_CONTROLLER_GONE      = 0x031;
143         const EXCEPTION_CLASS_NOT_FOUND              = 0x032;
144         const EXCEPTION_REQUIRED_INTERFACE_MISSING   = 0x033;
145         const EXCEPTION_FATAL_ERROR                  = 0x034;
146         const EXCEPTION_FILE_NOT_FOUND               = 0x035;
147         const EXCEPTION_ASSERTION_FAILED             = 0x036;
148         const EXCEPTION_FILE_NOT_REACHABLE           = 0x037;
149         const EXCEPTION_FILE_CANNOT_BE_READ          = 0x038;
150         const EXCEPTION_FILE_CANNOT_BE_WRITTEN       = 0x039;
151         const EXCEPTION_PATH_CANNOT_BE_WRITTEN       = 0x03a;
152         const EXCEPTION_DATABASE_UPDATED_NOT_ALLOWED = 0x03b;
153         const EXCEPTION_FILTER_CHAIN_INTERCEPTED     = 0x03c;
154         const EXCEPTION_INVALID_SOCKET               = 0x03d;
155         const EXCEPTION_SELF_INSTANCE                = 0x03e;
156
157         /**
158          * Startup time in miliseconds
159          */
160         private static $startupTime = 0;
161
162         /**
163          * Protected super constructor
164          *
165          * @param       $className      Name of the class
166          * @return      void
167          */
168         protected function __construct (string $className) {
169                 // Set real class
170                 $this->setRealClass($className);
171
172                 // Is the startup time set? (0 cannot be true anymore)
173                 if (self::$startupTime == 0) {
174                         // Then set it
175                         self::$startupTime = microtime(true);
176                 }
177         }
178
179         /**
180          * Destructor for all classes. You should not call this method on your own.
181          *
182          * @return      void
183          */
184         public function __destruct () {
185                 // Is this object already destroyed?
186                 if ($this->__toString() != 'DestructedObject') {
187                         // Destroy all informations about this class but keep some text about it alive
188                         $this->setRealClass('DestructedObject');
189                 } elseif ((defined('DEBUG_DESTRUCTOR')) && (is_object($this->getDebugInstance()))) {
190                         // Already destructed object
191                         self::createDebugInstance(__CLASS__, __LINE__)->warningMessage(sprintf('The object <span class="object_name">%s</span> is already destroyed.',
192                                 $this->__toString()
193                         ));
194                 } else {
195                         // Do not call this twice
196                         trigger_error(__METHOD__ . ': Called twice.');
197                         exit;
198                 }
199         }
200
201         /**
202          * The __call() method where all non-implemented methods end up
203          *
204          * @param       $methodName             Name of the missing method
205          * @args        $args                   Arguments passed to the method
206          * @return      void
207          */
208         public final function __call (string $methodName, array $args = NULL) {
209                 // Set self-instance
210                 self::$selfInstance = $this;
211
212                 // Call static method
213                 self::__callStatic($methodName, $args);
214
215                 // Clear self-instance
216                 self::$selfInstance = NULL;
217         }
218
219         /**
220          * The __callStatic() method where all non-implemented static methods end up
221          *
222          * @param       $methodName             Name of the missing method
223          * @param       $args                   Arguments passed to the method
224          * @return      void
225          * @throws      InvalidArgumentException If self::$selfInstance is not a framework's own object
226          */
227         public static final function __callStatic (string $methodName, array $args = NULL) {
228                 // Init argument string and class name
229                 //* PRINT-DEBUG: */ printf('[%s:%d]: methodName=%s,args[]=%s - CALLED!' . PHP_EOL, __METHOD__, __LINE__, $methodName, gettype($args));
230                 $argsString = '';
231                 $className = 'unknown';
232
233                 // Is self-instance set?
234                 if (self::$selfInstance instanceof FrameworkInterface) {
235                         // Framework's own instance
236                         $className = self::$selfInstance->__toString();
237                 } elseif (!is_null(self::$selfInstance)) {
238                         // Invalid argument!
239                         throw new InvalidArgumentException(sprintf('self::instance[%s] is not expected.', gettype(self::$selfInstance)), self::EXCEPTION_SELF_INSTANCE);
240                 }
241
242                 // Is it NULL, empty or an array?
243                 if (is_null($args)) {
244                         // No arguments
245                         $argsString = 'NULL';
246                 } elseif (is_array($args)) {
247                         // Start braces
248                         $argsString = '(';
249
250                         // Some arguments are there
251                         foreach ($args as $arg) {
252                                 // Add data about the argument
253                                 $argsString .= gettype($arg) . ':';
254
255                                 if (is_null($arg)) {
256                                         // Found a NULL argument
257                                         $argsString .= 'NULL';
258                                 } elseif (is_string($arg)) {
259                                         // Add length for strings
260                                         $argsString .= strlen($arg);
261                                 } elseif ((is_int($arg)) || (is_float($arg))) {
262                                         // ... integer/float
263                                         $argsString .= $arg;
264                                 } elseif (is_array($arg)) {
265                                         // .. or size if array
266                                         $argsString .= count($arg);
267                                 } elseif (is_object($arg)) {
268                                         // Get reflection
269                                         $reflection = new ReflectionClass($arg);
270
271                                         // Is an other object, maybe no __toString() available
272                                         $argsString .= $reflection->getName();
273                                 } elseif ($arg === true) {
274                                         // ... is boolean 'true'
275                                         $argsString .= 'true';
276                                 } elseif ($arg === false) {
277                                         // ... is boolean 'false'
278                                         $argsString .= 'false';
279                                 }
280
281                                 // Comma for next one
282                                 $argsString .= ', ';
283                         }
284
285                         // Last comma found?
286                         if (substr($argsString, -2, 1) == ',') {
287                                 // Remove last comma
288                                 $argsString = substr($argsString, 0, -2);
289                         }
290
291                         // Close braces
292                         $argsString .= ')';
293                 }
294
295                 // Output stub message
296                 // @TODO __CLASS__ does always return BaseFrameworkSystem but not the extending (=child) class
297                 self::createDebugInstance(__CLASS__, __LINE__)->warningMessage(sprintf('[%s::%s]: Stub! Args: %s',
298                         $className,
299                         $methodName,
300                         $argsString
301                 ));
302
303                 // Return nothing
304                 return NULL;
305         }
306
307         /**
308          * Getter for $realClass
309          *
310          * @return      $realClass The name of the real class (not BaseFrameworkSystem)
311          */
312         public function __toString () {
313                 return $this->realClass;
314         }
315
316         /**
317          * Magic method to catch setting of missing but set class fields/attributes
318          *
319          * @param       $name   Name of the field/attribute
320          * @param       $value  Value to store
321          * @return      void
322          */
323         public final function __set (string $name, $value) {
324                 $this->debugBackTrace(sprintf('Tried to set a missing field. name=%s, value[%s]=%s',
325                         $name,
326                         gettype($value),
327                         print_r($value, true)
328                 ));
329         }
330
331         /**
332          * Magic method to catch getting of missing fields/attributes
333          *
334          * @param       $name   Name of the field/attribute
335          * @return      void
336          */
337         public final function __get (string $name) {
338                 $this->debugBackTrace(sprintf('Tried to get a missing field. name=%s',
339                         $name
340                 ));
341         }
342
343         /**
344          * Magic method to catch unsetting of missing fields/attributes
345          *
346          * @param       $name   Name of the field/attribute
347          * @return      void
348          */
349         public final function __unset (string $name) {
350                 $this->debugBackTrace(sprintf('Tried to unset a missing field. name=%s',
351                         $name
352                 ));
353         }
354
355         /**
356          * Magic method to catch object serialization
357          *
358          * @return      $unsupported    Unsupported method
359          * @throws      UnsupportedOperationException   Objects of this framework cannot be serialized
360          */
361         public final function __sleep () {
362                 throw new UnsupportedOperationException([$this, __FUNCTION__], FrameworkInterface::EXCEPTION_UNSPPORTED_OPERATION);
363         }
364
365         /**
366          * Magic method to catch object deserialization
367          *
368          * @return      $unsupported    Unsupported method
369          * @throws      UnsupportedOperationException   Objects of this framework cannot be serialized
370          */
371         public final function __wakeup () {
372                 throw new UnsupportedOperationException([$this, __FUNCTION__], FrameworkInterface::EXCEPTION_UNSPPORTED_OPERATION);
373         }
374
375         /**
376          * Magic method to catch calls when an object instance is called
377          *
378          * @return      $unsupported    Unsupported method
379          * @throws      UnsupportedOperationException   Objects of this framework cannot be serialized
380          */
381         public final function __invoke () {
382                 throw new UnsupportedOperationException([$this, __FUNCTION__], FrameworkInterface::EXCEPTION_UNSPPORTED_OPERATION);
383         }
384
385         /**
386          * Setter for the real class name
387          *
388          * @param       $realClass      Class name (string)
389          * @return      void
390          */
391         public final function setRealClass (string $realClass) {
392                 // Set real class
393                 $this->realClass = $realClass;
394         }
395
396         /**
397          * Setter for debug instance
398          *
399          * @param       $debugInstance  The instance for debug output class
400          * @return      void
401          */
402         public final function setDebugInstance (DebugMiddleware $debugInstance) {
403                 GenericRegistry::getRegistry()->addInstance('debug', $debugInstance);
404         }
405
406         /**
407          * Getter for debug instance
408          *
409          * @return      $debugInstance  Instance to class DebugConsoleOutput or DebugWebOutput
410          */
411         public final function getDebugInstance () {
412                 return self::$debugInstance;
413         }
414
415         /**
416          * Setter for web output instance
417          *
418          * @param       $webInstance    The instance for web output class
419          * @return      void
420          */
421         public final function setWebOutputInstance (OutputStreamer $webInstance) {
422                 GenericRegistry::getRegistry()->addInstance('web_output', $webInstance);
423         }
424
425         /**
426          * Getter for web output instance
427          *
428          * @return      $webOutputInstance - Instance to class WebOutput
429          */
430         public final function getWebOutputInstance () {
431                 return GenericRegistry::getRegistry()->getInstance('web_output');
432         }
433
434         /**
435          * Setter for call-back instance
436          *
437          * @param       $callbackInstance       An instance of a FrameworkInterface class
438          * @return      void
439          */
440         public final function setCallbackInstance (FrameworkInterface $callbackInstance) {
441                 $this->callbackInstance = $callbackInstance;
442         }
443
444         /**
445          * Getter for call-back instance
446          *
447          * @return      $callbackInstance       An instance of a FrameworkInterface class
448          */
449         protected final function getCallbackInstance () {
450                 return $this->callbackInstance;
451         }
452
453         /**
454          * Checks whether an object equals this object. You should overwrite this
455          * method to implement own equality checks
456          *
457          * @param       $objectInstance         An instance of a FrameworkInterface object
458          * @return      $equals                         Whether both objects equals
459          */
460         public function equals (FrameworkInterface $objectInstance) {
461                 // Now test it
462                 $equals = ((
463                         $this->__toString() == $objectInstance->__toString()
464                 ) && (
465                         $this->hashCode() == $objectInstance->hashCode()
466                 ));
467
468                 // Return the result
469                 return $equals;
470         }
471
472         /**
473          * Generates a generic hash code of this class. You should really overwrite
474          * this method with your own hash code generator code. But keep KISS in mind.
475          *
476          * @return      $hashCode       A generic hash code respresenting this whole class
477          */
478         public function hashCode () {
479                 // Simple hash code
480                 return crc32($this->__toString());
481         }
482
483         /**
484          * Appends a trailing slash to a string
485          *
486          * @param       $str    A string (maybe) without trailing slash
487          * @return      $str    A string with an auto-appended trailing slash
488          */
489         public final function addMissingTrailingSlash (string $str) {
490                 // Is there a trailing slash?
491                 if (substr($str, -1, 1) != '/') {
492                         $str .= '/';
493                 }
494
495                 // Return string with trailing slash
496                 return $str;
497         }
498
499         /**
500          * Debugs this instance by putting out it's full content
501          *
502          * @param       $message        Optional message to show in debug output
503          * @return      void
504          */
505         public final function debugInstance (string $message = '') {
506                 // Restore the error handler to avoid trouble with missing array elements or undeclared variables
507                 restore_error_handler();
508
509                 // Init content
510                 $content = '';
511
512                 // Is a message set?
513                 if (!empty($message)) {
514                         // Construct message
515                         $content = sprintf('<div class="debug_message">
516         Message: %s
517 </div>' . PHP_EOL, $message);
518                 }
519
520                 // Generate the output
521                 $content .= sprintf('<pre>%s</pre>',
522                         trim(
523                                 htmlentities(
524                                         print_r($this, true)
525                                 )
526                         )
527                 );
528
529                 // Output it
530                 ApplicationEntryPoint::exitApplication(sprintf('<div class="debug_header">
531         %s debug output:
532 </div>
533 <div class="debug_content">
534         %s
535 </div>
536 Loaded includes:
537 <div class="debug_include_list">
538         %s
539 </div>',
540                         $this->__toString(),
541                         $content,
542                         ClassLoader::getSelfInstance()->getPrintableIncludeList()
543                 ));
544         }
545
546         /**
547          * Output a partial stub message for the caller method
548          *
549          * @param       $message        An optional message to display
550          * @return      void
551          */
552         protected function partialStub (string $message = '') {
553                 // Init variable
554                 $stubMessage = 'Partial stub!';
555
556                 // Is an extra message given?
557                 if (!empty($message)) {
558                         // Then add it as well
559                         $stubMessage .= ' Message: ' . $message;
560                 }
561
562                 // Debug instance is there?
563                 if (!is_null($this->getDebugInstance())) {
564                         // Output stub message
565                         self::createDebugInstance(__CLASS__, __LINE__)->warningMessage($stubMessage);
566                 } else {
567                         // Trigger an error
568                         trigger_error($stubMessage);
569                         exit;
570                 }
571         }
572
573         /**
574          * Outputs a debug backtrace and stops further script execution
575          *
576          * @param       $message        An optional message to output
577          * @param       $doExit         Whether exit the program (true is default)
578          * @return      void
579          */
580         public function debugBackTrace (string $message = '', bool $doExit = true) {
581                 // Sorry, there is no other way getting this nice backtrace
582                 if (!empty($message)) {
583                         // Output message
584                         printf('Message: %s<br />' . PHP_EOL, $message);
585                 }
586
587                 print('<pre>');
588                 debug_print_backtrace();
589                 print('</pre>');
590
591                 // Exit program?
592                 if ($doExit === true) {
593                         exit();
594                 }
595         }
596
597         /**
598          * Creates an instance of a debugger instance
599          *
600          * @param       $className              Name of the class (currently unsupported)
601          * @param       $lineNumber             Line number where the call was made
602          * @return      $debugInstance  An instance of a debugger class
603          * @throws      InvalidArgumentException        If a parameter has an invalid value
604          * @deprecated  Not fully, as the new Logger facilities are not finished yet.
605          */
606         public final static function createDebugInstance (string $className, int $lineNumber = NULL) {
607                 // Validate parameter
608                 //* NOISY-DEBUG: */ printf('[%s:%d]: className=%s,lineNumber[%s]=%d - CALLED!' . PHP_EOL, __METHOD__, __LINE__, $className, gettype($lineNumber), $lineNumber);
609                 if (empty($className)) {
610                         // Throw IAE
611                         throw new InvalidArgumentException('Parameter "className" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
612                 }
613
614                 // Is the debug instance set?
615                 //* NOISY-DEBUG: */ printf('[%s:%d]: self::debugInstance[]=%s' . PHP_EOL, __METHOD__, __LINE__, gettype(self::$debugInstance));
616                 if (is_null(self::$debugInstance)) {
617                         // Init debug instance
618                         self::$debugInstance = NULL;
619
620                         // Try it
621                         try {
622                                 // Get a debugger instance
623                                 self::$debugInstance = DebugMiddleware::createDebugMiddleware(FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('debug_' . FrameworkBootstrap::getRequestTypeFromSystem() . '_class'), $className);
624                         } catch (NullPointerException $e) {
625                                 // Didn't work, no instance there
626                                 exit(sprintf('[%s:%d]: Cannot create debugInstance! Exception=%s,message=%s,className=%s,lineNumber=%d' . PHP_EOL, __METHOD__, __LINE__, $e->__toString(), $e->getMessage(), $className, $lineNumber));
627                         }
628
629                         // Empty string should be ignored and used for testing the middleware
630                         //* NOISY-DEBUG: */ printf('[%s:%d]: Invoking DebugMiddleware->selfInstance->output() ...' . PHP_EOL, __METHOD__, __LINE__);
631                         DebugMiddleware::getSelfInstance()->output('');
632                 }
633
634                 // Return it
635                 //* NOISY-DEBUG: */ printf('[%s:%d]: self::debugInstance=%s - EXIT!' . PHP_EOL, __METHOD__, __LINE__, self::$debugInstance->__toString());
636                 return self::$debugInstance;
637         }
638
639         /**
640          * Simple output of a message with line-break
641          *
642          * @param       $message        Message to output
643          * @return      void
644          */
645         public function outputLine (string $message) {
646                 // Simply output it
647                 print($message . PHP_EOL);
648         }
649
650         /**
651          * Marks up the code by adding e.g. line numbers
652          *
653          * @param       $phpCode                Unmarked PHP code
654          * @return      $markedCode             Marked PHP code
655          */
656         public function markupCode (string $phpCode) {
657                 // Init marked code
658                 $markedCode = '';
659
660                 // Get last error
661                 $errorArray = error_get_last();
662
663                 // Init the code with error message
664                 if (is_array($errorArray)) {
665                         // Get error infos
666                         $markedCode = sprintf('<div id="error_header">File: <span id="error_data">%s</span>, Line: <span id="error_data">%s</span>, Message: <span id="error_data">%s</span>, Type: <span id="error_data">%s</span></div>',
667                                 basename($errorArray['file']),
668                                 $errorArray['line'],
669                                 $errorArray['message'],
670                                 $errorArray['type']
671                         );
672                 }
673
674                 // Add line number to the code
675                 foreach (explode(chr(10), $phpCode) as $lineNo => $code) {
676                         // Add line numbers
677                         $markedCode .= sprintf('<span id="code_line">%s</span>: %s' . PHP_EOL,
678                                 ($lineNo + 1),
679                                 htmlentities($code, ENT_QUOTES)
680                         );
681                 }
682
683                 // Return the code
684                 return $markedCode;
685         }
686
687         /**
688          * "Getter" for databse entry
689          *
690          * @return      $entry  An array with database entries
691          * @throws      NullPointerException    If the database result is not found
692          * @throws      InvalidDatabaseResultException  If the database result is invalid
693          * @deprecated  Monolithic method, should be moved to proper classes
694          */
695         protected final function getDatabaseEntry () {
696                 // This method is deprecated
697                 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-FRAMEWORK-SYSTEM: CALLED!');
698                 $this->deprecationWarning('Monolithic method, should be moved to proper classes');
699
700                 // Is there an instance?
701                 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-FRAMEWORK-SYSTEM: this->resultInstance[]=%s', gettype($this->getResultInstance())));
702                 if (!$this->getResultInstance() instanceof SearchableResult) {
703                         // Throw an exception here
704                         throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
705                 }
706
707                 // Rewind it
708                 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-FRAMEWORK-SYSTEM: Invoking this->resultInstance->rewind() ...');
709                 $this->getResultInstance()->rewind();
710
711                 // Do we have an entry?
712                 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-FRAMEWORK-SYSTEM: this->resultInstance->isValid()=%d', intval($this->getResultInstance()->isValid())));
713                 if ($this->getResultInstance()->valid() === false) {
714                         // @TODO Move the constant to e.g. BaseDatabaseResult when there is a non-cached database result available
715                         throw new InvalidDatabaseResultException(array($this, $this->getResultInstance()), CachedDatabaseResult::EXCEPTION_INVALID_DATABASE_RESULT);
716                 }
717
718                 // Get next entry
719                 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-FRAMEWORK-SYSTEM: Invoking this->resultInstance->next() ...');
720                 $this->getResultInstance()->next();
721
722                 // Fetch it
723                 $entry = $this->getResultInstance()->current();
724
725                 // And return it
726                 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: entry[]=%s - EXIT!', gettype($entry)));
727                 return $entry;
728         }
729
730         /**
731          * Getter for field name
732          *
733          * @param       $fieldName              Field name which we shall get
734          * @return      $fieldValue             Field value from the user
735          * @throws      NullPointerException    If the result instance is null
736          * @throws      InvalidArgumentException        If a parameter is not valid
737          * @deprecated  Monolithic method, should be moved to proper classes
738          */
739         public final function getField (string $fieldName) {
740                 // Check parameter
741                 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: fieldName=%s - CALLED!', $fieldName));
742                 if (empty($fieldName)) {
743                         // Throw IAE
744                         throw new InvalidArgumentException('Parameter "fieldName" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
745                 }
746
747                 // This method is deprecated
748                 $this->deprecationWarning('Monolithic method, should be moved to proper classes');
749
750                 // Default field value
751                 $fieldValue = NULL;
752
753                 // Get result instance
754                 $resultInstance = $this->getResultInstance();
755
756                 // Is this instance null?
757                 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-FRAMEWORK-SYSTEM: resultInstance[]=%s', gettype($resultInstance)));
758                 if (is_null($resultInstance)) {
759                         // Then the user instance is no longer valid (expired cookies?)
760                         throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
761                 }
762
763                 // Get current array
764                 $fieldArray = $resultInstance->current();
765
766                 // Convert dashes to underscore
767                 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-FRAMEWORK-SYSTEM: fieldArray()=%d', count($fieldArray)));
768                 $fieldName2 = StringUtils::convertDashesToUnderscores($fieldName);
769
770                 // Does the field exist?
771                 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-FRAMEWORK-SYSTEM: fieldName2=%s', $fieldName2));
772                 if ($this->isFieldSet($fieldName)) {
773                         // Get it
774                         $fieldValue = $fieldArray[$fieldName2];
775                 } elseif (FrameworkBootstrap::getConfigurationInstance()->isEnabled('developer_mode')) {
776                         // Missing field entry, may require debugging
777                         self::createDebugInstance(__CLASS__, __LINE__)->warningMessage('BASE-FRAMEWORK-SYSTEM: fieldArray<pre>=' . print_r($fieldArray, true) . '</pre>,fieldName=' . $fieldName . ' not found!');
778                 } else {
779                         // Missing field entry, may require debugging
780                         self::createDebugInstance(__CLASS__, __LINE__)->warningMessage('BASE-FRAMEWORK-SYSTEM: fieldName=' . $fieldName . ' not found!');
781                 }
782
783                 // Return it
784                 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: fieldValue[]=%s - EXIT!', gettype($fieldValue)));
785                 return $fieldValue;
786         }
787
788         /**
789          * Checks if given field is set
790          *
791          * @param       $fieldName      Field name to check
792          * @return      $isSet          Whether the given field name is set
793          * @throws      NullPointerException    If the result instance is null
794          * @throws      InvalidArgumentException        If a parameter is not valid
795          */
796         public function isFieldSet (string $fieldName) {
797                 // Check parameter
798                 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: fieldName=%s - CALLED!', $fieldName));
799                 if (empty($fieldName)) {
800                         // Throw IAE
801                         throw new InvalidArgumentException('Parameter "fieldName" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
802                 }
803
804                 // Get result instance
805                 $resultInstance = $this->getResultInstance();
806
807                 // Is this instance null?
808                 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-FRAMEWORK-SYSTEM: resultInstance[]=%s', gettype($resultInstance)));
809                 if (is_null($resultInstance)) {
810                         // Then the user instance is no longer valid (expired cookies?)
811                         throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
812                 }
813
814                 // Get current array
815                 $fieldArray = $resultInstance->current();
816
817                 // Convert dashes to underscore
818                 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-FRAMEWORK-SYSTEM: fieldArray()=%d,fieldName=%s - BEFORE!', count($fieldArray), $fieldName));
819                 $fieldName = StringUtils::convertDashesToUnderscores($fieldName);
820
821                 // Determine it
822                 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-FRAMEWORK-SYSTEM: fieldName=%s - AFTER!', $fieldName));
823                 $isset = isset($fieldArray[$fieldName]);
824
825                 // Return result
826                 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: isset=%d - EXIT!', intval($isset)));
827                 return $isset;
828         }
829
830         /**
831          * Outputs a deprecation warning to the developer.
832          *
833          * @param       $message        The message we shall output to the developer
834          * @return      void
835          * @todo        Write a logging mechanism for productive mode
836          */
837         public function deprecationWarning (string $message) {
838                 // Is developer mode active?
839                 if (FrameworkBootstrap::getConfigurationInstance()->isEnabled('developer_mode')) {
840                         // Debug instance is there?
841                         if (!is_null($this->getDebugInstance())) {
842                                 // Output stub message
843                                 self::createDebugInstance(__CLASS__, __LINE__)->warningMessage($message);
844                         } else {
845                                 // Trigger an error
846                                 trigger_error($message . "<br />\n");
847                                 exit;
848                         }
849                 } else {
850                         // @TODO Finish this part!
851                         $this->partialStub('Developer mode inactive. Message:' . $message);
852                 }
853         }
854
855         /**
856          * Checks whether the given PHP extension is loaded
857          *
858          * @param       $phpExtension   The PHP extension we shall check
859          * @return      $isLoaded       Whether the PHP extension is loaded
860          * @throws      InvalidArgumentException        If a parameter is not valid
861          */
862         public final function isPhpExtensionLoaded (string $phpExtension) {
863                 // Check parameter
864                 if (empty($phpExtension)) {
865                         // Throw IAE
866                         throw new InvalidArgumentException('Parameter "phpExtension" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
867                 }
868
869                 // Is it loaded?
870                 $isLoaded = in_array($phpExtension, get_loaded_extensions());
871
872                 // Return result
873                 return $isLoaded;
874         }
875
876         /**
877          * "Getter" as a time() replacement but with milliseconds. You should use this
878          * method instead of the encapsulated getimeofday() function.
879          *
880          * @return      $milliTime      Timestamp with milliseconds
881          */
882         public function getMilliTime () {
883                 // Get the time of day as float
884                 $milliTime = gettimeofday(true);
885
886                 // Return it
887                 return $milliTime;
888         }
889
890         /**
891          * Idles (sleeps) for given milliseconds
892          *
893          * @return      $hasSlept       Whether it goes fine
894          * @throws      InvalidArgumentException        If a parameter is not valid
895          */
896         public function idle (int $milliSeconds) {
897                 // Check parameter
898                 if ($milliSeconds < 1) {
899                         // Throw IAE
900                         throw new InvalidArgumentException(sprintf('milliSeconds=%d are not a reasonable value to idle', $milliSeconds));
901                 }
902
903                 // Sleep is fine by default
904                 $hasSlept = true;
905
906                 // Idle so long with found function
907                 if (function_exists('time_sleep_until')) {
908                         // Get current time and add idle time
909                         $sleepUntil = $this->getMilliTime() + abs($milliSeconds) / 1000;
910
911                         // New PHP 5.1.0 function found, ignore errors
912                         $hasSlept = @time_sleep_until($sleepUntil);
913                 } else {
914                         /*
915                          * My Sun station doesn't have that function even with latest PHP
916                          * package. :(
917                          */
918                         usleep($milliSeconds * 1000);
919                 }
920
921                 // Return result
922                 return $hasSlept;
923         }
924
925         /**
926          * Checks whether the given encoded data was encoded with Base64
927          *
928          * @param       $encodedData    Encoded data we shall check
929          * @return      $isBase64               Whether the encoded data is Base64
930          * @throws      InvalidArgumentException        If a parameter is not valid
931          */
932         protected function isBase64Encoded (string $encodedData) {
933                 // Check parameter
934                 if (empty($encodedData)) {
935                         // Throw IAE
936                         throw new InvalidArgumentException('Parameter "encodedData" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
937                 }
938
939                 // Determine it
940                 $isBase64 = (@base64_decode($encodedData, true) !== false);
941
942                 // Return it
943                 return $isBase64;
944         }
945
946         /**
947          * Getter for startup time in miliseconds
948          *
949          * @return      $startupTime    Startup time in miliseconds
950          */
951         protected function getStartupTime () {
952                 return self::$startupTime;
953         }
954
955         /**
956          * "Getter" for a printable currently execution time in nice braces
957          *
958          * @return      $executionTime  Current execution time in nice braces
959          */
960         protected function getPrintableExecutionTime () {
961                 // Calculate execution time and pack it in nice braces
962                 $executionTime = sprintf('[ %01.5f ] ', (microtime(true) - $this->getStartupTime()));
963
964                 // And return it
965                 return $executionTime;
966         }
967
968         /**
969          * Determines if an element is set in the generic array
970          *
971          * @param       $keyGroup       Main group for the key
972          * @param       $subGroup       Sub group for the key
973          * @param       $key            Key to check
974          * @param       $element        Element to check
975          * @return      $isset          Whether the given key is set
976          * @throws      InvalidArgumentException        If a parameter is not valid
977          */
978         protected final function isGenericArrayElementSet (string $keyGroup, string $subGroup, string $key, string $element) {
979                 // Check parameter
980                 if (empty($keyGroup)) {
981                         // Throw IAE
982                         throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
983                 } elseif (empty($subGroup)) {
984                         // Throw IAE
985                         throw new InvalidArgumentException('Parameter "subGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
986                 } elseif (empty($key)) {
987                         // Throw IAE
988                         throw new InvalidArgumentException('Parameter "key" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
989                 } elseif ($element === '') {
990                         // Throw IAE
991                         throw new InvalidArgumentException('Parameter "element" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
992                 }
993
994                 // Is it there?
995                 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element);
996                 $isset = isset($this->genericArray[$keyGroup][$subGroup][$key][$element]);
997
998                 // Return it
999                 return $isset;
1000         }
1001         /**
1002          * Determines if a key is set in the generic array
1003          *
1004          * @param       $keyGroup       Main group for the key
1005          * @param       $subGroup       Sub group for the key
1006          * @param       $key            Key to check
1007          * @return      $isset          Whether the given key is set
1008          * @throws      InvalidArgumentException        If a parameter is not valid
1009          */
1010         protected final function isGenericArrayKeySet (string $keyGroup, string $subGroup, string $key) {
1011                 // Check parameter
1012                 if (empty($keyGroup)) {
1013                         // Throw IAE
1014                         throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1015                 } elseif (empty($subGroup)) {
1016                         // Throw IAE
1017                         throw new InvalidArgumentException('Parameter "subGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1018                 } elseif (empty($key)) {
1019                         // Throw IAE
1020                         throw new InvalidArgumentException('Parameter "key" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1021                 }
1022
1023                 // Is it there?
1024                 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1025                 $isset = isset($this->genericArray[$keyGroup][$subGroup][$key]);
1026
1027                 // Return it
1028                 return $isset;
1029         }
1030
1031         /**
1032          * Determines if a group is set in the generic array
1033          *
1034          * @param       $keyGroup       Main group
1035          * @param       $subGroup       Sub group
1036          * @return      $isset          Whether the given group is set
1037          * @throws      InvalidArgumentException        If a parameter is not valid
1038          */
1039         protected final function isGenericArrayGroupSet (string $keyGroup, string $subGroup) {
1040                 // Check parameter
1041                 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup);
1042                 if (empty($keyGroup)) {
1043                         // Throw IAE
1044                         throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1045                 } elseif (empty($subGroup)) {
1046                         // Throw IAE
1047                         throw new InvalidArgumentException('Parameter "subGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1048                 }
1049
1050                 // Is it there?
1051                 $isset = isset($this->genericArray[$keyGroup][$subGroup]);
1052
1053                 // Return it
1054                 return $isset;
1055         }
1056
1057         /**
1058          * Getter for sub key group
1059          *
1060          * @param       $keyGroup       Main key group
1061          * @param       $subGroup       Sub key group
1062          * @return      $array          An array with all array elements
1063          * @throws      InvalidArgumentException        If a parameter is not valid
1064          * @throws      BadMethodCallException  If key/sub group isn't there but this method is invoked
1065          */
1066         protected final function getGenericSubArray (string $keyGroup, string $subGroup) {
1067                 // Check parameter
1068                 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',value=' . print_r($this->genericArray[$keyGroup][$subGroup], true));
1069                 if (empty($keyGroup)) {
1070                         // Throw IAE
1071                         throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1072                 } elseif (empty($subGroup)) {
1073                         // Throw IAE
1074                         throw new InvalidArgumentException('Parameter "subGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1075                 } elseif (!$this->isGenericArrayGroupSet($keyGroup, $subGroup)) {
1076                         // No, then abort here
1077                         throw new BadMethodCallException(sprintf('keyGroup=%s,subGroup=%s not found.', $keyGroup, $subGroup), FrameworkInterface::EXCEPTION_BAD_METHOD_CALL);
1078                 }
1079
1080                 // Return it
1081                 return $this->genericArray[$keyGroup][$subGroup];
1082         }
1083
1084         /**
1085          * Unsets a given key in generic array
1086          *
1087          * @param       $keyGroup       Main group for the key
1088          * @param       $subGroup       Sub group for the key
1089          * @param       $key            Key to unset
1090          * @return      void
1091          * @throws      InvalidArgumentException        If a parameter is not valid
1092          */
1093         protected final function unsetGenericArrayKey (string $keyGroup, string $subGroup, string $key) {
1094                 // Check parameter
1095                 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1096                 if (empty($keyGroup)) {
1097                         // Throw IAE
1098                         throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1099                 } elseif (empty($subGroup)) {
1100                         // Throw IAE
1101                         throw new InvalidArgumentException('Parameter "subGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1102                 } elseif (empty($key)) {
1103                         // Throw IAE
1104                         throw new InvalidArgumentException('Parameter "key" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1105                 }
1106
1107                 // Remove it
1108                 unset($this->genericArray[$keyGroup][$subGroup][$key]);
1109         }
1110
1111         /**
1112          * Unsets a given element in generic array
1113          *
1114          * @param       $keyGroup       Main group for the key
1115          * @param       $subGroup       Sub group for the key
1116          * @param       $key            Key to unset
1117          * @param       $element        Element to unset
1118          * @return      void
1119          * @throws      InvalidArgumentException        If a parameter is not valid
1120          */
1121         protected final function unsetGenericArrayElement (string $keyGroup, string $subGroup, string $key, string $element) {
1122                 // Check parameter
1123                 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element);
1124                 if (empty($keyGroup)) {
1125                         // Throw IAE
1126                         throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1127                 } elseif (empty($subGroup)) {
1128                         // Throw IAE
1129                         throw new InvalidArgumentException('Parameter "subGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1130                 } elseif (empty($key)) {
1131                         // Throw IAE
1132                         throw new InvalidArgumentException('Parameter "key" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1133                 } elseif ($element === '') {
1134                         // Throw IAE
1135                         throw new InvalidArgumentException('Parameter "element" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1136                 }
1137
1138                 // Remove it
1139                 unset($this->genericArray[$keyGroup][$subGroup][$key][$element]);
1140         }
1141
1142         /**
1143          * Append a string to a given generic array key
1144          *
1145          * @param       $keyGroup       Main group for the key
1146          * @param       $subGroup       Sub group for the key
1147          * @param       $key            Key to unset
1148          * @param       $value          Value to add/append
1149          * @return      void
1150          * @throws      InvalidArgumentException        If a parameter is not valid
1151          */
1152         protected final function appendStringToGenericArrayKey (string $keyGroup, string $subGroup, $key, string $value, string $appendGlue = '') {
1153                 // Check parameter
1154                 //* NOISY-DEBUG: */ if (!is_object($value)) $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',value[' . gettype($value) . ']=' . print_r($value, true) . ',appendGlue=' . $appendGlue);
1155                 if (empty($keyGroup)) {
1156                         // Throw IAE
1157                         throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1158                 } elseif (empty($subGroup)) {
1159                         // Throw IAE
1160                         throw new InvalidArgumentException('Parameter "subGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1161                 } elseif (empty($key)) {
1162                         // Throw IAE
1163                         throw new InvalidArgumentException('Parameter "key" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1164                 }
1165
1166                 // Is it already there?
1167                 if ($this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
1168                         // Append it
1169                         $this->genericArray[$keyGroup][$subGroup][$key] .= $appendGlue . $value;
1170                 } else {
1171                         // Add it
1172                         $this->genericArray[$keyGroup][$subGroup][$key] = $value;
1173                 }
1174         }
1175
1176         /**
1177          * Append a string to a given generic array element
1178          *
1179          * @param       $keyGroup       Main group for the key
1180          * @param       $subGroup       Sub group for the key
1181          * @param       $key            Key to unset
1182          * @param       $element        Element to check
1183          * @param       $value          Value to add/append
1184          * @return      void
1185          * @throws      InvalidArgumentException        If a parameter is not valid
1186          */
1187         protected final function appendStringToGenericArrayElement (string $keyGroup, string $subGroup, string $key, string $element, string $value, string $appendGlue = '') {
1188                 // Check parameter
1189                 //* NOISY-DEBUG: */ if (!is_object($value)) $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element . ',value[' . gettype($value) . ']=' . print_r($value, true) . ',appendGlue=' . $appendGlue);
1190                 if (empty($keyGroup)) {
1191                         // Throw IAE
1192                         throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1193                 } elseif (empty($subGroup)) {
1194                         // Throw IAE
1195                         throw new InvalidArgumentException('Parameter "subGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1196                 } elseif (empty($key)) {
1197                         // Throw IAE
1198                         throw new InvalidArgumentException('Parameter "key" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1199                 } elseif ($element === '') {
1200                         // Throw IAE
1201                         throw new InvalidArgumentException('Parameter "element" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1202                 }
1203
1204                 // Is it already there?
1205                 if ($this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element)) {
1206                         // Append it
1207                         $this->genericArray[$keyGroup][$subGroup][$key][$element] .= $appendGlue . $value;
1208                 } else {
1209                         // Add it
1210                         $this->setGenericArrayElement($keyGroup, $subGroup, $key, $element, $value);
1211                 }
1212         }
1213
1214         /**
1215          * Initializes given generic array group
1216          *
1217          * @param       $keyGroup       Main group for the key
1218          * @param       $subGroup       Sub group for the key
1219          * @param       $key            Key to use
1220          * @param       $forceInit      Optionally force initialization
1221          * @return      void
1222          * @throws      InvalidArgumentException        If a parameter is not valid
1223          * @throws      BadMethodCallException  If key/sub group has already been initialized
1224          */
1225         protected final function initGenericArrayGroup (string $keyGroup, string $subGroup, bool $forceInit = false) {
1226                 // Check parameter
1227                 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',forceInit=' . intval($forceInit));
1228                 if (empty($keyGroup)) {
1229                         // Throw IAE
1230                         throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1231                 } elseif (empty($subGroup)) {
1232                         // Throw IAE
1233                         throw new InvalidArgumentException('Parameter "subGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1234                 } elseif (($forceInit === false) && ($this->isGenericArrayGroupSet($keyGroup, $subGroup))) {
1235                         // Already initialized
1236                         throw new BadMethodCallException(sprintf('keyGroup=%s,subGroup=%s already initialized.', $keyGroup, $subGroup), FrameworkInterface::EXCEPTION_BAD_METHOD_CALL);
1237                 }
1238
1239                 // Initialize it
1240                 $this->genericArray[$keyGroup][$subGroup] = [];
1241         }
1242
1243         /**
1244          * Initializes given generic array key
1245          *
1246          * @param       $keyGroup       Main group for the key
1247          * @param       $subGroup       Sub group for the key
1248          * @param       $key            Key to use
1249          * @param       $forceInit      Optionally force initialization
1250          * @return      void
1251          * @throws      InvalidArgumentException        If a parameter is not valid
1252          * @throws      BadMethodCallException  If key/sub group has already been initialized
1253          */
1254         protected final function initGenericArrayKey (string $keyGroup, string $subGroup, $key, bool $forceInit = false) {
1255                 // Check parameter
1256                 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',forceInit=' . intval($forceInit));
1257                 if (empty($keyGroup)) {
1258                         // Throw IAE
1259                         throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1260                 } elseif (empty($subGroup)) {
1261                         // Throw IAE
1262                         throw new InvalidArgumentException('Parameter "subGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1263                 } elseif (empty($key)) {
1264                         // Throw IAE
1265                         throw new InvalidArgumentException('Parameter "key" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1266                 } elseif (($forceInit === false) && ($this->isGenericArrayKeySet($keyGroup, $subGroup, $key))) {
1267                         // Already initialized
1268                         throw new BadMethodCallException(sprintf('keyGroup=%s,subGroup=%s,key[%s]=%s already initialized.', $keyGroup, $subGroup, gettype($key), $key), FrameworkInterface::EXCEPTION_BAD_METHOD_CALL);
1269                 }
1270
1271                 // Initialize it
1272                 $this->genericArray[$keyGroup][$subGroup][$key] = [];
1273         }
1274
1275         /**
1276          * Initializes given generic array element
1277          *
1278          * @param       $keyGroup       Main group for the key
1279          * @param       $subGroup       Sub group for the key
1280          * @param       $key            Key to use
1281          * @param       $element        Element to use
1282          * @param       $forceInit      Optionally force initialization
1283          * @return      void
1284          * @throws      InvalidArgumentException        If a parameter is not valid
1285          * @throws      BadMethodCallException  If key/sub group isn't there but this method is invoked
1286          */
1287         protected final function initGenericArrayElement (string $keyGroup, string $subGroup, string $key, string $element, bool $forceInit = false) {
1288                 // Check parameter
1289                 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element . ',forceInit=' . intval($forceInit));
1290                 if (empty($keyGroup)) {
1291                         // Throw IAE
1292                         throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1293                 } elseif (empty($subGroup)) {
1294                         // Throw IAE
1295                         throw new InvalidArgumentException('Parameter "subGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1296                 } elseif (empty($key)) {
1297                         // Throw IAE
1298                         throw new InvalidArgumentException('Parameter "key" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1299                 } elseif ($element === '') {
1300                         // Throw IAE
1301                         throw new InvalidArgumentException('Parameter "element" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1302                 } elseif (($forceInit === false) && ($this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element))) {
1303                         // Already initialized
1304                         throw new BadMethodCallException(sprintf('keyGroup=%s,subGroup=%s,key[%s]=%s,element[%s]=%s already initialized.', $keyGroup, $subGroup, gettype($key), $key, gettype($element), $element), FrameworkInterface::EXCEPTION_BAD_METHOD_CALL);
1305                 }
1306
1307                 // Initialize it
1308                 $this->genericArray[$keyGroup][$subGroup][$key][$element] = [];
1309         }
1310
1311         /**
1312          * Pushes an element to a generic key. If the key isn't found, it will be initialized.
1313          *
1314          * @param       $keyGroup       Main group for the key
1315          * @param       $subGroup       Sub group for the key
1316          * @param       $key            Key to use
1317          * @param       $value          Value to add/append
1318          * @return      $count          Number of array elements
1319          * @throws      InvalidArgumentException        If a parameter is not valid
1320          */
1321         protected final function pushValueToGenericArrayKey (string $keyGroup, string $subGroup, string $key, $value) {
1322                 // Check parameter
1323                 //* NOISY-DEBUG: */ if (!is_object($value)) $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',value[' . gettype($value) . ']=' . print_r($value, true));
1324                 if (empty($keyGroup)) {
1325                         // Throw IAE
1326                         throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1327                 } elseif (empty($subGroup)) {
1328                         // Throw IAE
1329                         throw new InvalidArgumentException('Parameter "subGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1330                 } elseif (empty($key)) {
1331                         // Throw IAE
1332                         throw new InvalidArgumentException('Parameter "key" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1333                 } elseif (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
1334                         // Initialize array
1335                         $this->initGenericArrayKey($keyGroup, $subGroup, $key);
1336                 }
1337
1338                 // Then push it
1339                 $count = array_push($this->genericArray[$keyGroup][$subGroup][$key], $value);
1340
1341                 // Return count
1342                 //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], true));
1343                 //* DEBUG: */ print(__METHOD__ . ': count=' . $count . PHP_EOL);
1344                 return $count;
1345         }
1346
1347         /**
1348          * Pushes an element to a generic array element. If the key isn't found, it will be initialized.
1349          *
1350          * @param       $keyGroup       Main group for the key
1351          * @param       $subGroup       Sub group for the key
1352          * @param       $key            Key to use
1353          * @param       $element        Element to check
1354          * @param       $value          Value to add/append
1355          * @return      $count          Number of array elements
1356          * @throws      InvalidArgumentException        If a parameter is not valid
1357          */
1358         protected final function pushValueToGenericArrayElement (string $keyGroup, string $subGroup, string $key, string $element, $value) {
1359                 // Check parameter
1360                 //* NOISY-DEBUG: */ if (!is_object($value)) $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element . ',value[' . gettype($value) . ']=' . print_r($value, true));
1361                 if (empty($keyGroup)) {
1362                         // Throw IAE
1363                         throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1364                 } elseif (empty($subGroup)) {
1365                         // Throw IAE
1366                         throw new InvalidArgumentException('Parameter "subGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1367                 } elseif (empty($key)) {
1368                         // Throw IAE
1369                         throw new InvalidArgumentException('Parameter "key" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1370                 } elseif ($element === '') {
1371                         // Throw IAE
1372                         throw new InvalidArgumentException('Parameter "element" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1373                 } elseif (!$this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element)) {
1374                         // Initialize array
1375                         $this->initGenericArrayElement($keyGroup, $subGroup, $key, $element);
1376                 }
1377
1378                 // Then push it
1379                 $count = array_push($this->genericArray[$keyGroup][$subGroup][$key][$element], $value);
1380
1381                 // Return count
1382                 //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], true));
1383                 //* DEBUG: */ print(__METHOD__ . ': count=' . $count . PHP_EOL);
1384                 return $count;
1385         }
1386
1387         /**
1388          * Pops an element from  a generic group
1389          *
1390          * @param       $keyGroup       Main group for the key
1391          * @param       $subGroup       Sub group for the key
1392          * @param       $key            Key to unset
1393          * @return      $value          Last "popped" value
1394          * @throws      InvalidArgumentException        If a parameter is not valid
1395          * @throws      BadMethodCallException  If key/sub group isn't there but this method is invoked
1396          */
1397         protected final function popGenericArrayElement (string $keyGroup, string $subGroup, string $key) {
1398                 // Check parameter
1399                 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1400                 if (empty($keyGroup)) {
1401                         // Throw IAE
1402                         throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1403                 } elseif (empty($subGroup)) {
1404                         // Throw IAE
1405                         throw new InvalidArgumentException('Parameter "subGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1406                 } elseif (empty($key)) {
1407                         // Throw IAE
1408                         throw new InvalidArgumentException('Parameter "key" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1409                 } elseif (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
1410                         // Not found
1411                         throw new BadMethodCallException(sprintf('keyGroup=%s,subGroup=%s,key[%s]=%s not found.', $keyGroup, $subGroup, gettype($key), $key), FrameworkInterface::EXCEPTION_BAD_METHOD_CALL);
1412                 }
1413
1414                 // Then "pop" it
1415                 $value = array_pop($this->genericArray[$keyGroup][$subGroup][$key]);
1416
1417                 // Return value
1418                 //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], true));
1419                 //* DEBUG: */ print(__METHOD__ . ': value[' . gettype($value) . ']=' . print_r($value, true) . PHP_EOL);
1420                 return $value;
1421         }
1422
1423         /**
1424          * Shifts an element from  a generic group
1425          *
1426          * @param       $keyGroup       Main group for the key
1427          * @param       $subGroup       Sub group for the key
1428          * @param       $key            Key to unset
1429          * @return      $value          Last "shifted" value
1430          * @throws      InvalidArgumentException        If a parameter is not valid
1431          * @throws      BadMethodCallException  If key/sub group isn't there but this method is invoked
1432          */
1433         protected final function shiftGenericArrayElement (string $keyGroup, string $subGroup, string $key) {
1434                 // Check parameter
1435                 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1436                 if (empty($keyGroup)) {
1437                         // Throw IAE
1438                         throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1439                 } elseif (empty($subGroup)) {
1440                         // Throw IAE
1441                         throw new InvalidArgumentException('Parameter "subGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1442                 } elseif (empty($key)) {
1443                         // Throw IAE
1444                         throw new InvalidArgumentException('Parameter "key" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1445                 } elseif (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
1446                         // Not found
1447                         throw new BadMethodCallException(sprintf('keyGroup=%s,subGroup=%s,key[%s]=%s not found.', $keyGroup, $subGroup, gettype($key), $key), FrameworkInterface::EXCEPTION_BAD_METHOD_CALL);
1448                 }
1449
1450                 // Then "shift" it
1451                 $value = array_shift($this->genericArray[$keyGroup][$subGroup][$key]);
1452
1453                 // Return value
1454                 //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], true));
1455                 //* DEBUG: */ print(__METHOD__ . ': value[' . gettype($value) . ']=' . print_r($value, true) . PHP_EOL);
1456                 return $value;
1457         }
1458
1459         /**
1460          * Count generic array group
1461          *
1462          * @param       $keyGroup       Main group for the key
1463          * @return      $count          Count of given group
1464          * @throws      InvalidArgumentException        If a parameter is not valid
1465          * @throws      BadMethodCallException  If key group isn't there but this method is invoked
1466          */
1467         protected final function countGenericArray (string $keyGroup) {
1468                 // Check parameter
1469                 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup);
1470                 if (empty($keyGroup)) {
1471                         // Throw IAE
1472                         throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1473                 } elseif (!isset($this->genericArray[$keyGroup])) {
1474                         // Not found
1475                         throw new BadMethodCallException(sprintf('keyGroup=%s not found.', $keyGroup), FrameworkInterface::EXCEPTION_BAD_METHOD_CALL);
1476                 }
1477
1478                 // Then count it
1479                 $count = count($this->genericArray[$keyGroup]);
1480
1481                 // Return it
1482                 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',count=' . $count);
1483                 return $count;
1484         }
1485
1486         /**
1487          * Count generic array sub group
1488          *
1489          * @param       $keyGroup       Main group for the key
1490          * @param       $subGroup       Sub group for the key
1491          * @return      $count          Count of given group
1492          * @throws      InvalidArgumentException        If a parameter is not valid
1493          * @throws      BadMethodCallException  If key/sub group isn't there but this method is invoked
1494          */
1495         protected final function countGenericArrayGroup (string $keyGroup, string $subGroup) {
1496                 // Check parameter
1497                 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup);
1498                 if (empty($keyGroup)) {
1499                         // Throw IAE
1500                         throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1501                 } elseif (empty($subGroup)) {
1502                         // Throw IAE
1503                         throw new InvalidArgumentException('Parameter "subGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1504                 } elseif (!$this->isGenericArrayGroupSet($keyGroup, $subGroup)) {
1505                         // Abort here
1506                         throw new BadMethodCallException(sprintf('keyGroup=%s,subGroup=%s not found.', $keyGroup, $subGroup), FrameworkInterface::EXCEPTION_BAD_METHOD_CALL);
1507                 }
1508
1509                 // Then count it
1510                 $count = count($this->genericArray[$keyGroup][$subGroup]);
1511
1512                 // Return it
1513                 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',count=' . $count);
1514                 return $count;
1515         }
1516
1517         /**
1518          * Count generic array elements
1519          *
1520          * @param       $keyGroup       Main group for the key
1521          * @param       $subGroup       Sub group for the key
1522          * @param       $key            Key to count
1523          * @return      $count          Count of given key
1524          * @throws      InvalidArgumentException        If a parameter is not valid
1525          * @throws      BadMethodCallException  If key/sub group isn't there but this method is invoked
1526          */
1527         protected final function countGenericArrayElements (string $keyGroup, string $subGroup, string $key) {
1528                 // Check parameter
1529                 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1530                 if (empty($keyGroup)) {
1531                         // Throw IAE
1532                         throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1533                 } elseif (empty($subGroup)) {
1534                         // Throw IAE
1535                         throw new InvalidArgumentException('Parameter "subGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1536                 } elseif (empty($key)) {
1537                         // Throw IAE
1538                         throw new InvalidArgumentException('Parameter "key" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1539                 } elseif (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
1540                         // Abort here
1541                         throw new BadMethodCallException(sprintf('keyGroup=%s,subGroup=%s,key[%s]=%s not found.', $keyGroup, $subGroup, gettype($key), $key), FrameworkInterface::EXCEPTION_BAD_METHOD_CALL);
1542                 } elseif (!$this->isValidGenericArrayGroup($keyGroup, $subGroup)) {
1543                         // Not valid
1544                         throw new BadMethodCallException(sprintf('keyGroup=%s,subGroup=%s is not a valid key/sub group.', $keyGroup, $subGroup), FrameworkInterface::EXCEPTION_BAD_METHOD_CALL);
1545                 }
1546
1547                 // Then count it
1548                 $count = count($this->genericArray[$keyGroup][$subGroup][$key]);
1549
1550                 // Return it
1551                 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',count=' . $count);
1552                 return $count;
1553         }
1554
1555         /**
1556          * Getter for whole generic group array
1557          *
1558          * @param       $keyGroup       Key group to get
1559          * @return      $array          Whole generic array group
1560          * @throws      InvalidArgumentException        If a parameter is not valid
1561          * @throws      BadMethodCallException  If key/sub group isn't there but this method is invoked
1562          */
1563         protected final function getGenericArray (string $keyGroup) {
1564                 // Check parameters
1565                 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup);
1566                 if (empty($keyGroup)) {
1567                         // Throw IAE
1568                         throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1569                 } elseif (!isset($this->genericArray[$keyGroup])) {
1570                         // Then abort here
1571                         throw new BadMethodCallException(sprintf('keyGroup=%s not found', $keyGroup), FrameworkInterface::EXCEPTION_BAD_METHOD_CALL);
1572                 }
1573
1574                 // Return it
1575                 return $this->genericArray[$keyGroup];
1576         }
1577
1578         /**
1579          * Setter for generic array key
1580          *
1581          * @param       $keyGroup       Key group to get
1582          * @param       $subGroup       Sub group for the key
1583          * @param       $key            Key to unset
1584          * @param       $value          Mixed value from generic array element
1585          * @return      void
1586          * @throws      InvalidArgumentException        If a parameter is not valid
1587          * @throws      BadMethodCallException  If key/sub group isn't there but this method is invoked
1588          */
1589         protected final function setGenericArrayKey (string $keyGroup, string $subGroup, string $key, $value) {
1590                 // Check parameters
1591                 //* NOISY-DEBUG: */ if (!is_object($value)) $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',value[' . gettype($value) . ']=' . print_r($value, true));
1592                 if (empty($keyGroup)) {
1593                         // Throw IAE
1594                         throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1595                 } elseif (empty($subGroup)) {
1596                         // Throw IAE
1597                         throw new InvalidArgumentException('Parameter "subGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1598                 } elseif (empty($key)) {
1599                         // Throw IAE
1600                         throw new InvalidArgumentException('Parameter "key" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1601                 } elseif (!$this->isValidGenericArrayGroup($keyGroup, $subGroup)) {
1602                         // Then abort here
1603                         throw new BadMethodCallException(sprintf('keyGroup=%s,subGroup=%s not found', $keyGroup), FrameworkInterface::EXCEPTION_BAD_METHOD_CALL);
1604                 }
1605
1606                 // Set value here
1607                 $this->genericArray[$keyGroup][$subGroup][$key] = $value;
1608         }
1609
1610         /**
1611          * Getter for generic array key
1612          *
1613          * @param       $keyGroup       Key group to get
1614          * @param       $subGroup       Sub group for the key
1615          * @param       $key            Key to unset
1616          * @return      $value          Mixed value from generic array element
1617          * @throws      InvalidArgumentException        If a parameter is not valid
1618          * @throws      BadMethodCallException  If key/sub group isn't there but this method is invoked
1619          */
1620         protected final function getGenericArrayKey (string $keyGroup, string $subGroup, string $key) {
1621                 // Check parameters
1622                 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1623                 if (empty($keyGroup)) {
1624                         // Throw IAE
1625                         throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1626                 } elseif (empty($subGroup)) {
1627                         // Throw IAE
1628                         throw new InvalidArgumentException('Parameter "subGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1629                 } elseif (empty($key)) {
1630                         // Throw IAE
1631                         throw new InvalidArgumentException('Parameter "key" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1632                 } elseif (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
1633                         // Then abort here
1634                         throw new BadMethodCallException(sprintf('keyGroup=%s,subGroup=%s,key[%s]=%s not found.', $keyGroup, $subGroup, gettype($key), $key), FrameworkInterface::EXCEPTION_BAD_METHOD_CALL);
1635                 }
1636
1637                 // Return it
1638                 return $this->genericArray[$keyGroup][$subGroup][$key];
1639         }
1640
1641         /**
1642          * Sets a value in given generic array key/element
1643          *
1644          * @param       $keyGroup       Main group for the key
1645          * @param       $subGroup       Sub group for the key
1646          * @param       $key            Key to set
1647          * @param       $element        Element to set
1648          * @param       $value          Value to set
1649          * @return      void
1650          * @throws      InvalidArgumentException        If a parameter is not valid
1651          */
1652         protected final function setGenericArrayElement (string $keyGroup, string $subGroup, string $key, string $element, $value) {
1653                 // Check parameter
1654                 //* NOISY-DEBUG: */ if (!is_object($value)) $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element . ',value[' . gettype($value) . ']=' . print_r($value, true));
1655                 if (empty($keyGroup)) {
1656                         // Throw IAE
1657                         throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1658                 } elseif (empty($subGroup)) {
1659                         // Throw IAE
1660                         throw new InvalidArgumentException('Parameter "subGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1661                 } elseif (empty($key)) {
1662                         // Throw IAE
1663                         throw new InvalidArgumentException('Parameter "key" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1664                 } elseif ($element === '') {
1665                         // Throw IAE
1666                         throw new InvalidArgumentException('Parameter "element" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1667                 } elseif (!$this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element)) {
1668                         // Initialize array
1669                         $this->initGenericArrayElement($keyGroup, $subGroup, $key, $element);
1670                 }
1671
1672                 // Then set it
1673                 $this->genericArray[$keyGroup][$subGroup][$key][$element] = $value;
1674         }
1675
1676         /**
1677          * Getter for generic array element
1678          *
1679          * @param       $keyGroup       Key group to get
1680          * @param       $subGroup       Sub group for the key
1681          * @param       $key            Key to look for
1682          * @param       $element        Element to look for
1683          * @return      $value          Mixed value from generic array element
1684          * @throws      InvalidArgumentException        If a parameter is not valid
1685          * @throws      BadMethodCallException  If key/sub group isn't there but this method is invoked
1686          */
1687         protected final function getGenericArrayElement (string $keyGroup, string $subGroup, string $key, string $element) {
1688                 // Check parameter
1689                 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element);
1690                 if (empty($keyGroup)) {
1691                         // Throw IAE
1692                         throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1693                 } elseif (empty($subGroup)) {
1694                         // Throw IAE
1695                         throw new InvalidArgumentException('Parameter "subGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1696                 } elseif (empty($key)) {
1697                         // Throw IAE
1698                         throw new InvalidArgumentException('Parameter "key" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1699                 } elseif ($element === '') {
1700                         // Throw IAE
1701                         throw new InvalidArgumentException('Parameter "element" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1702                 } elseif (!$this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element)) {
1703                         // Then abort here
1704                         throw new BadMethodCallException(sprintf('keyGroup=%s,subGroup=%s,key[%s]=%s,element[%s]=%s not found.', $keyGroup, $subGroup, gettype($key), $key, gettype($element), $element), FrameworkInterface::EXCEPTION_BAD_METHOD_CALL);
1705                 }
1706
1707                 // Return it
1708                 return $this->genericArray[$keyGroup][$subGroup][$key][$element];
1709         }
1710
1711         /**
1712          * Checks if a given sub group is valid (array)
1713          *
1714          * @param       $keyGroup       Key group to get
1715          * @param       $subGroup       Sub group for the key
1716          * @return      $isValid        Whether given sub group is valid
1717          * @throws      InvalidArgumentException        If a parameter is not valid
1718          */
1719         protected final function isValidGenericArrayGroup (string $keyGroup, string $subGroup) {
1720                 // Check parameter
1721                 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup);
1722                 if (empty($keyGroup)) {
1723                         // Throw IAE
1724                         throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1725                 } elseif (empty($subGroup)) {
1726                         // Throw IAE
1727                         throw new InvalidArgumentException('Parameter "subGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1728                 }
1729
1730                 // Determine it
1731                 $isValid = (($this->isGenericArrayGroupSet($keyGroup, $subGroup)) && (is_array($this->getGenericSubArray($keyGroup, $subGroup))));
1732
1733                 // Return it
1734                 return $isValid;
1735         }
1736
1737         /**
1738          * Checks if a given key is valid (array)
1739          *
1740          * @param       $keyGroup       Key group to get
1741          * @param       $subGroup       Sub group for the key
1742          * @param       $key            Key to check
1743          * @return      $isValid        Whether given sub group is valid
1744          */
1745         protected final function isValidGenericArrayKey (string $keyGroup, string $subGroup, string $key) {
1746                 // Check parameters
1747                 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1748                 if (empty($keyGroup)) {
1749                         // Throw IAE
1750                         throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1751                 } elseif (empty($subGroup)) {
1752                         // Throw IAE
1753                         throw new InvalidArgumentException('Parameter "subGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1754                 } elseif (empty($key)) {
1755                         // Throw IAE
1756                         throw new InvalidArgumentException('Parameter "key" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1757                 }
1758
1759                 // Determine it
1760                 $isValid = (($this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) && (is_array($this->getGenericArrayKey($keyGroup, $subGroup, $key))));
1761
1762                 // Return it
1763                 return $isValid;
1764         }
1765
1766         /**
1767          * Initializes the web output instance
1768          *
1769          * @return      void
1770          */
1771         protected function initWebOutputInstance () {
1772                 // Init web output instance
1773                 $outputInstance = ObjectFactory::createObjectByConfiguredName('output_class');
1774
1775                 // Set it locally
1776                 $this->setWebOutputInstance($outputInstance);
1777         }
1778
1779         /**
1780          * Translates boolean true to 'Y' and false to 'N'
1781          *
1782          * @param       $boolean                Boolean value
1783          * @return      $translated             Translated boolean value
1784          */
1785         public static final function translateBooleanToYesNo (bool $boolean) {
1786                 // "Translate" it
1787                 $translated = ($boolean === true) ? 'Y' : 'N';
1788
1789                 // ... and return it
1790                 return $translated;
1791         }
1792
1793         /**
1794          * Creates a full-qualified file name (FQFN) for given file name by adding
1795          * a configured temporary file path to it.
1796          *
1797          * @param       $infoInstance   An instance of a SplFileInfo class
1798          * @return      $tempInstance   An instance of a SplFileInfo class (temporary file)
1799          * @throw       PathWriteProtectedException If the path in 'temp_file_path' is write-protected
1800          * @throws      FileIoException If the file cannot be written
1801          */
1802          protected static function createTempPathForFile (SplFileInfo $infoInstance) {
1803                 // Get config entry
1804                 $basePath = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('temp_file_path');
1805
1806                 // Is the path writeable?
1807                 if (!is_writable($basePath)) {
1808                         // Path is write-protected
1809                         throw new PathWriteProtectedException($infoInstance, self::EXCEPTION_PATH_CANNOT_BE_WRITTEN);
1810                 }
1811
1812                 // Add it
1813                 $tempInstance = new SplFileInfo($basePath . DIRECTORY_SEPARATOR . $infoInstance->getBasename());
1814
1815                 // Is it reachable?
1816                 if (!FrameworkBootstrap::isReachableFilePath($tempInstance)) {
1817                         // Not reachable
1818                         throw new FileIoException($tempInstance, self::EXCEPTION_FILE_NOT_REACHABLE);
1819                 }
1820
1821                 // Return it
1822                 return $tempInstance;
1823          }
1824
1825         /**
1826          * "Getter" for a printable state name
1827          *
1828          * @return      $stateName      Name of the node's state in a printable format
1829          * @todo        Move this class away from this monolithic place (not whole class is monolithic)
1830          */
1831         public final function getPrintableState () {
1832                 // Default is 'null'
1833                 $stateName = 'null';
1834
1835                 // Get the state instance
1836                 $stateInstance = $this->getStateInstance();
1837
1838                 // Is it an instance of Stateable?
1839                 if ($stateInstance instanceof Stateable) {
1840                         // Then use that state name
1841                         $stateName = $stateInstance->getStateName();
1842                 }
1843
1844                 // Return result
1845                 return $stateName;
1846         }
1847
1848 }