Merge branch 'master' of git.mxchange.org:/var/cache/git/repos/core
[core.git] / inc / classes / main / class_BaseFrameworkSystem.php
1 <?php
2 /**
3  * The simulator system class is the super class of all other classes. This
4  * class handles saving of games etc.
5  *
6  * @author              Roland Haeder <webmaster@shipsimu.org>
7  * @version             0.0.0
8  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2014 Core Developer Team
9  * @license             GNU GPL 3.0 or any newer version
10  * @link                http://www.shipsimu.org
11  *
12  * This program is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation, either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program. If not, see <http://www.gnu.org/licenses/>.
24  */
25 class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
26         /**
27          * Length of output from hash()
28          */
29         private static $hashLength = NULL;
30
31         /**
32          * The real class name
33          */
34         private $realClass = 'BaseFrameworkSystem';
35
36         /**
37          * Instance of a request class
38          */
39         private $requestInstance = NULL;
40
41         /**
42          * Instance of a response class
43          */
44         private $responseInstance = NULL;
45
46         /**
47          * Search criteria instance
48          */
49         private $searchInstance = NULL;
50
51         /**
52          * Update criteria instance
53          */
54         private $updateInstance = NULL;
55
56         /**
57          * The file I/O instance for the template loader
58          */
59         private $fileIoInstance = NULL;
60
61         /**
62          * Resolver instance
63          */
64         private $resolverInstance = NULL;
65
66         /**
67          * Template engine instance
68          */
69         private $templateInstance = NULL;
70
71         /**
72          * Database result instance
73          */
74         private $resultInstance = NULL;
75
76         /**
77          * Instance for user class
78          */
79         private $userInstance = NULL;
80
81         /**
82          * A controller instance
83          */
84         private $controllerInstance = NULL;
85
86         /**
87          * Instance of a RNG
88          */
89         private $rngInstance = NULL;
90
91         /**
92          * Instance of a crypto helper
93          */
94         private $cryptoInstance = NULL;
95
96         /**
97          * Instance of an Iterator class
98          */
99         private $iteratorInstance = NULL;
100
101         /**
102          * Instance of the list
103          */
104         private $listInstance = NULL;
105
106         /**
107          * Instance of a menu
108          */
109         private $menuInstance = NULL;
110
111         /**
112          * Instance of the image
113          */
114         private $imageInstance = NULL;
115
116         /**
117          * Instance of the stacker
118          */
119         private $stackInstance = NULL;
120
121         /**
122          * A Compressor instance
123          */
124         private $compressorInstance = NULL;
125
126         /**
127          * A Parseable instance
128          */
129         private $parserInstance = NULL;
130
131         /**
132          * A HandleableProtocol instance
133          */
134         private $protocolInstance = NULL;
135
136         /**
137          * A database wrapper instance
138          */
139         private $databaseInstance = NULL;
140
141         /**
142          * A helper instance for the form
143          */
144         private $helperInstance = NULL;
145
146         /**
147          * An instance of a Sourceable class
148          */
149         private $sourceInstance = NULL;
150
151         /**
152          * An instance of a InputStream class
153          */
154         private $inputStreamInstance = NULL;
155
156         /**
157          * An instance of a OutputStream class
158          */
159         private $outputStreamInstance = NULL;
160
161         /**
162          * Networkable handler instance
163          */
164         private $handlerInstance = NULL;
165
166         /**
167          * Visitor handler instance
168          */
169         private $visitorInstance = NULL;
170
171         /**
172          * DHT instance
173          */
174         private $dhtInstance = NULL;
175
176         /**
177          * An instance of a database wrapper class
178          */
179         private $wrapperInstance = NULL;
180
181         /**
182          * An instance of a file I/O pointer class (not handler)
183          */
184         private $pointerInstance = NULL;
185
186         /**
187          * An instance of an Indexable class
188          */
189         private $indexInstance = NULL;
190
191         /**
192          * An instance of a Block class
193          */
194         private $blockInstance = NULL;
195
196         /**
197          * A Minable instance
198          */
199         private $minableInstance = NULL;
200
201         /**
202          * A FrameworkDirectory instance
203          */
204         private $directoryInstance = NULL;
205
206         /**
207          * Listener instance
208          */
209         private $listenerInstance = NULL;
210
211         /**
212          * Thousands separator
213          */
214         private $thousands = '.'; // German
215
216         /**
217          * Decimal separator
218          */
219         private $decimals  = ','; // German
220
221         /**
222          * Socket resource
223          */
224         private $socketResource = FALSE;
225
226         /**
227          * Regular expression to use for validation
228          */
229         private $regularExpression = '';
230
231         /**
232          * Package data
233          */
234         private $packageData = array();
235
236         /**
237          * Generic array
238          */
239         private $genericArray = array();
240
241         /***********************
242          * Exception codes.... *
243          ***********************/
244
245         // @todo Try to clean these constants up
246         const EXCEPTION_IS_NULL_POINTER              = 0x001;
247         const EXCEPTION_IS_NO_OBJECT                 = 0x002;
248         const EXCEPTION_IS_NO_ARRAY                  = 0x003;
249         const EXCEPTION_MISSING_METHOD               = 0x004;
250         const EXCEPTION_CLASSES_NOT_MATCHING         = 0x005;
251         const EXCEPTION_INDEX_OUT_OF_BOUNDS          = 0x006;
252         const EXCEPTION_DIMENSION_ARRAY_INVALID      = 0x007;
253         const EXCEPTION_ITEM_NOT_TRADEABLE           = 0x008;
254         const EXCEPTION_ITEM_NOT_IN_PRICE_LIST       = 0x009;
255         const EXCEPTION_GENDER_IS_WRONG              = 0x00a;
256         const EXCEPTION_BIRTH_DATE_IS_INVALID        = 0x00b;
257         const EXCEPTION_EMPTY_STRUCTURES_ARRAY       = 0x00c;
258         const EXCEPTION_HAS_ALREADY_PERSONELL_LIST   = 0x00d;
259         const EXCEPTION_NOT_ENOUGTH_UNEMPLOYEES      = 0x00e;
260         const EXCEPTION_TOTAL_PRICE_NOT_CALCULATED   = 0x00f;
261         const EXCEPTION_HARBOR_HAS_NO_SHIPYARDS      = 0x010;
262         const EXCEPTION_CONTRACT_PARTNER_INVALID     = 0x011;
263         const EXCEPTION_CONTRACT_PARTNER_MISMATCH    = 0x012;
264         const EXCEPTION_CONTRACT_ALREADY_SIGNED      = 0x013;
265         const EXCEPTION_UNEXPECTED_EMPTY_STRING      = 0x014;
266         const EXCEPTION_PATH_NOT_FOUND               = 0x015;
267         const EXCEPTION_INVALID_PATH_NAME            = 0x016;
268         const EXCEPTION_READ_PROTECED_PATH           = 0x017;
269         const EXCEPTION_WRITE_PROTECED_PATH          = 0x018;
270         const EXCEPTION_DIR_POINTER_INVALID          = 0x019;
271         const EXCEPTION_FILE_POINTER_INVALID         = 0x01a;
272         const EXCEPTION_INVALID_RESOURCE             = 0x01b;
273         const EXCEPTION_UNEXPECTED_OBJECT            = 0x01c;
274         const EXCEPTION_LIMIT_ELEMENT_IS_UNSUPPORTED = 0x01d;
275         const EXCEPTION_GETTER_IS_MISSING            = 0x01e;
276         const EXCEPTION_ARRAY_EXPECTED               = 0x01f;
277         const EXCEPTION_ARRAY_HAS_INVALID_COUNT      = 0x020;
278         const EXCEPTION_ID_IS_INVALID_FORMAT         = 0x021;
279         const EXCEPTION_MD5_CHECKSUMS_MISMATCH       = 0x022;
280         const EXCEPTION_UNEXPECTED_STRING_SIZE       = 0x023;
281         const EXCEPTION_SIMULATOR_ID_INVALID         = 0x024;
282         const EXCEPTION_MISMATCHING_COMPRESSORS      = 0x025;
283         const EXCEPTION_CONTAINER_ITEM_IS_NULL       = 0x026;
284         const EXCEPTION_ITEM_IS_NO_ARRAY             = 0x027;
285         const EXCEPTION_CONTAINER_MAYBE_DAMAGED      = 0x028;
286         const EXCEPTION_INVALID_STRING               = 0x029;
287         const EXCEPTION_VARIABLE_NOT_SET             = 0x02a;
288         const EXCEPTION_ATTRIBUTES_ARE_MISSING       = 0x02b;
289         const EXCEPTION_ARRAY_ELEMENTS_MISSING       = 0x02c;
290         const EXCEPTION_TEMPLATE_ENGINE_UNSUPPORTED  = 0x02d;
291         const EXCEPTION_UNSPPORTED_OPERATION         = 0x02e;
292         const EXCEPTION_FACTORY_REQUIRE_PARAMETER    = 0x02f;
293         const EXCEPTION_MISSING_ELEMENT              = 0x030;
294         const EXCEPTION_HEADERS_ALREADY_SENT         = 0x031;
295         const EXCEPTION_DEFAULT_CONTROLLER_GONE      = 0x032;
296         const EXCEPTION_CLASS_NOT_FOUND              = 0x033;
297         const EXCEPTION_REQUIRED_INTERFACE_MISSING   = 0x034;
298         const EXCEPTION_FATAL_ERROR                  = 0x035;
299         const EXCEPTION_FILE_NOT_FOUND               = 0x036;
300         const EXCEPTION_ASSERTION_FAILED             = 0x037;
301         const EXCEPTION_FILE_CANNOT_BE_READ          = 0x038;
302         const EXCEPTION_DATABASE_UPDATED_NOT_ALLOWED = 0x039;
303         const EXCEPTION_FILTER_CHAIN_INTERCEPTED     = 0x03a;
304
305         /**
306          * Hexadecimal->Decimal translation array
307          */
308         private static $hexdec = array(
309                 '0' => 0,
310                 '1' => 1,
311                 '2' => 2,
312                 '3' => 3,
313                 '4' => 4,
314                 '5' => 5,
315                 '6' => 6,
316                 '7' => 7,
317                 '8' => 8,
318                 '9' => 9,
319                 'a' => 10,
320                 'b' => 11,
321                 'c' => 12,
322                 'd' => 13,
323                 'e' => 14,
324                 'f' => 15
325         );
326
327         /**
328          * Decimal->hexadecimal translation array
329          */
330         private static $dechex = array(
331                  0 => '0',
332                  1 => '1',
333                  2 => '2',
334                  3 => '3',
335                  4 => '4',
336                  5 => '5',
337                  6 => '6',
338                  7 => '7',
339                  8 => '8',
340                  9 => '9',
341                 10 => 'a',
342                 11 => 'b',
343                 12 => 'c',
344                 13 => 'd',
345                 14 => 'e',
346                 15 => 'f'
347         );
348
349         /**
350          * Startup time in miliseconds
351          */
352         private static $startupTime = 0;
353
354         /**
355          * Protected super constructor
356          *
357          * @param       $className      Name of the class
358          * @return      void
359          */
360         protected function __construct ($className) {
361                 // Set real class
362                 $this->setRealClass($className);
363
364                 // Set configuration instance if no registry ...
365                 if (!$this instanceof Register) {
366                         // ... because registries doesn't need to be configured
367                         $this->setConfigInstance(FrameworkConfiguration::getSelfInstance());
368                 } // END - if
369
370                 // Is the startup time set? (0 cannot be TRUE anymore)
371                 if (self::$startupTime == 0) {
372                         // Then set it
373                         self::$startupTime = microtime(TRUE);
374                 } // END - if
375         }
376
377         /**
378          * Destructor for all classes
379          *
380          * @return      void
381          */
382         public function __destruct () {
383                 // Flush any updated entries to the database
384                 $this->flushPendingUpdates();
385
386                 // Is this object already destroyed?
387                 if ($this->__toString() != 'DestructedObject') {
388                         // Destroy all informations about this class but keep some text about it alive
389                         $this->setRealClass('DestructedObject');
390                 } elseif ((defined('DEBUG_DESTRUCTOR')) && (is_object($this->getDebugInstance()))) {
391                         // Already destructed object
392                         self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:] The object <span class="object_name">%s</span> is already destroyed.',
393                                 __CLASS__,
394                                 $this->__toString()
395                         ));
396                 } else {
397                         // Do not call this twice
398                         trigger_error(__METHOD__ . ': Called twice.');
399                         exit;
400                 }
401         }
402
403         /**
404          * The __call() method where all non-implemented methods end up
405          *
406          * @param       $methodName             Name of the missing method
407          * @args        $args                   Arguments passed to the method
408          * @return      void
409          */
410         public final function __call ($methodName, $args) {
411                 return self::__callStatic($methodName, $args);
412         }
413
414         /**
415          * The __callStatic() method where all non-implemented static methods end up
416          *
417          * @param       $methodName             Name of the missing method
418          * @args        $args                   Arguments passed to the method
419          * @return      void
420          */
421         public static final function __callStatic ($methodName, $args) {
422                 // Init argument string
423                 $argsString = '';
424
425                 // Is it empty or an array?
426                 if (empty($args)) {
427                         // No arguments
428                         $argsString = 'NULL';
429                 } elseif (is_array($args)) {
430                         // Some arguments are there
431                         foreach ($args as $arg) {
432                                 // Add the value itself if not array. This prevents 'array to string conversion' message
433                                 if (is_array($arg)) {
434                                         $argsString .= 'Array';
435                                 } else {
436                                         $argsString .= $arg;
437                                 }
438
439                                 // Add data about the argument
440                                 $argsString .= ' (' . gettype($arg);
441
442                                 if (is_string($arg)) {
443                                         // Add length for strings
444                                         $argsString .= ', ' . strlen($arg);
445                                 } elseif (is_array($arg)) {
446                                         // .. or size if array
447                                         $argsString .= ', ' . count($arg);
448                                 } elseif ($arg === TRUE) {
449                                         // ... is boolean 'TRUE'
450                                         $argsString .= ', TRUE';
451                                 } elseif ($arg === FALSE) {
452                                         // ... is boolean 'FALSE'
453                                         $argsString .= ', FALSE';
454                                 }
455
456                                 // Closing bracket
457                                 $argsString .= '), ';
458                         } // END - foreach
459
460                         // Remove last comma
461                         if (substr($argsString, -2, 1) == ',') {
462                                 $argsString = substr($argsString, 0, -2);
463                         } // END - if
464                 } else {
465                         // Invalid arguments!
466                         $argsString = '!INVALID:' . gettype($args) . '!';
467                 }
468
469                 // Output stub message
470                 // @TODO __CLASS__ does always return BaseFrameworkSystem but not the extending (=child) class
471                 self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[unknown::%s:] Stub! Args: %s',
472                         $methodName,
473                         $argsString
474                 ));
475
476                 // Return nothing
477                 return NULL;
478         }
479
480         /**
481          * Getter for $realClass
482          *
483          * @return      $realClass The name of the real class (not BaseFrameworkSystem)
484          */
485         public function __toString () {
486                 return $this->realClass;
487         }
488
489         /**
490          * Magic function to catch setting of missing but set class fields/attributes
491          *
492          * @param       $name   Name of the field/attribute
493          * @param       $value  Value to store
494          * @return      void
495          */
496         public final function __set ($name, $value) {
497                 $this->debugBackTrace(sprintf('Tried to set a missing field. name=%s, value[%s]=%s',
498                         $name,
499                         gettype($value),
500                         print_r($value, TRUE)
501                 ));
502         }
503
504         /**
505          * Magic function to catch getting of missing fields/attributes
506          *
507          * @param       $name   Name of the field/attribute
508          * @return      void
509          */
510         public final function __get ($name) {
511                 $this->debugBackTrace(sprintf('Tried to get a missing field. name=%s',
512                         $name
513                 ));
514         }
515
516         /**
517          * Magic function to catch unsetting of missing fields/attributes
518          *
519          * @param       $name   Name of the field/attribute
520          * @return      void
521          */
522         public final function __unset ($name) {
523                 $this->debugBackTrace(sprintf('Tried to unset a missing field. name=%s',
524                         $name
525                 ));
526         }
527
528         /**
529          * Setter for the real class name
530          *
531          * @param       $realClass      Class name (string)
532          * @return      void
533          */
534         public final function setRealClass ($realClass) {
535                 // Set real class
536                 $this->realClass = (string) $realClass;
537         }
538
539         /**
540          * Setter for database result instance
541          *
542          * @param       $resultInstance         An instance of a database result class
543          * @return      void
544          * @todo        SearchableResult and UpdateableResult shall have a super interface to use here
545          */
546         protected final function setResultInstance (SearchableResult $resultInstance) {
547                 $this->resultInstance =  $resultInstance;
548         }
549
550         /**
551          * Getter for database result instance
552          *
553          * @return      $resultInstance         An instance of a database result class
554          */
555         public final function getResultInstance () {
556                 return $this->resultInstance;
557         }
558
559         /**
560          * Setter for template engine instances
561          *
562          * @param       $templateInstance       An instance of a template engine class
563          * @return      void
564          */
565         protected final function setTemplateInstance (CompileableTemplate $templateInstance) {
566                 $this->templateInstance = $templateInstance;
567         }
568
569         /**
570          * Getter for template engine instances
571          *
572          * @return      $templateInstance       An instance of a template engine class
573          */
574         protected final function getTemplateInstance () {
575                 return $this->templateInstance;
576         }
577
578         /**
579          * Setter for search instance
580          *
581          * @param       $searchInstance         Searchable criteria instance
582          * @return      void
583          */
584         public final function setSearchInstance (LocalSearchCriteria $searchInstance) {
585                 $this->searchInstance = $searchInstance;
586         }
587
588         /**
589          * Getter for search instance
590          *
591          * @return      $searchInstance         Searchable criteria instance
592          */
593         public final function getSearchInstance () {
594                 return $this->searchInstance;
595         }
596
597         /**
598          * Setter for update instance
599          *
600          * @param       $updateInstance         Searchable criteria instance
601          * @return      void
602          */
603         public final function setUpdateInstance (LocalUpdateCriteria $updateInstance) {
604                 $this->updateInstance = $updateInstance;
605         }
606
607         /**
608          * Getter for update instance
609          *
610          * @return      $updateInstance         Updateable criteria instance
611          */
612         public final function getUpdateInstance () {
613                 return $this->updateInstance;
614         }
615
616         /**
617          * Setter for resolver instance
618          *
619          * @param       $resolverInstance       Instance of a command resolver class
620          * @return      void
621          */
622         public final function setResolverInstance (Resolver $resolverInstance) {
623                 $this->resolverInstance = $resolverInstance;
624         }
625
626         /**
627          * Getter for resolver instance
628          *
629          * @return      $resolverInstance       Instance of a command resolver class
630          */
631         public final function getResolverInstance () {
632                 return $this->resolverInstance;
633         }
634
635         /**
636          * Setter for language instance
637          *
638          * @param       $configInstance         The configuration instance which shall
639          *                                                              be FrameworkConfiguration
640          * @return      void
641          */
642         public final function setConfigInstance (FrameworkConfiguration $configInstance) {
643                 Registry::getRegistry()->addInstance('config', $configInstance);
644         }
645
646         /**
647          * Getter for configuration instance
648          *
649          * @return      $configInstance         Configuration instance
650          */
651         public final function getConfigInstance () {
652                 $configInstance = Registry::getRegistry()->getInstance('config');
653                 return $configInstance;
654         }
655
656         /**
657          * Setter for debug instance
658          *
659          * @param       $debugInstance  The instance for debug output class
660          * @return      void
661          */
662         public final function setDebugInstance (DebugMiddleware $debugInstance) {
663                 Registry::getRegistry()->addInstance('debug', $debugInstance);
664         }
665
666         /**
667          * Getter for debug instance
668          *
669          * @return      $debugInstance  Instance to class DebugConsoleOutput or DebugWebOutput
670          */
671         public final function getDebugInstance () {
672                 // Get debug instance
673                 $debugInstance = Registry::getRegistry()->getInstance('debug');
674
675                 // Return it
676                 return $debugInstance;
677         }
678
679         /**
680          * Setter for web output instance
681          *
682          * @param       $webInstance    The instance for web output class
683          * @return      void
684          */
685         public final function setWebOutputInstance (OutputStreamer $webInstance) {
686                 Registry::getRegistry()->addInstance('web_output', $webInstance);
687         }
688
689         /**
690          * Getter for web output instance
691          *
692          * @return      $webOutputInstance - Instance to class WebOutput
693          */
694         public final function getWebOutputInstance () {
695                 $webOutputInstance = Registry::getRegistry()->getInstance('web_output');
696                 return $webOutputInstance;
697         }
698
699         /**
700          * Setter for database instance
701          *
702          * @param       $databaseInstance       The instance for the database connection (forced DatabaseConnection)
703          * @return      void
704          */
705         public final function setDatabaseInstance (DatabaseConnection $databaseInstance) {
706                 Registry::getRegistry()->addInstance('db_instance', $databaseInstance);
707         }
708
709         /**
710          * Getter for database layer
711          *
712          * @return      $databaseInstance       The database layer instance
713          */
714         public final function getDatabaseInstance () {
715                 // Get instance
716                 $databaseInstance = Registry::getRegistry()->getInstance('db_instance');
717
718                 // Return instance
719                 return $databaseInstance;
720         }
721
722         /**
723          * Setter for compressor channel
724          *
725          * @param       $compressorInstance             An instance of CompressorChannel
726          * @return      void
727          */
728         public final function setCompressorChannel (CompressorChannel $compressorInstance) {
729                 Registry::getRegistry()->addInstance('compressor', $compressorInstance);
730         }
731
732         /**
733          * Getter for compressor channel
734          *
735          * @return      $compressorInstance             The compressor channel
736          */
737         public final function getCompressorChannel () {
738                 $compressorInstance = Registry::getRegistry()->getInstance('compressor');
739                 return $compressorInstance;
740         }
741
742         /**
743          * Protected getter for a manageable application helper class
744          *
745          * @return      $applicationInstance    An instance of a manageable application helper class
746          */
747         protected final function getApplicationInstance () {
748                 $applicationInstance = Registry::getRegistry()->getInstance('application');
749                 return $applicationInstance;
750         }
751
752         /**
753          * Setter for a manageable application helper class
754          *
755          * @param       $applicationInstance    An instance of a manageable application helper class
756          * @return      void
757          */
758         public final function setApplicationInstance (ManageableApplication $applicationInstance) {
759                 Registry::getRegistry()->addInstance('application', $applicationInstance);
760         }
761
762         /**
763          * Setter for request instance
764          *
765          * @param       $requestInstance        An instance of a Requestable class
766          * @return      void
767          */
768         public final function setRequestInstance (Requestable $requestInstance) {
769                 $this->requestInstance = $requestInstance;
770         }
771
772         /**
773          * Getter for request instance
774          *
775          * @return      $requestInstance        An instance of a Requestable class
776          */
777         public final function getRequestInstance () {
778                 return $this->requestInstance;
779         }
780
781         /**
782          * Setter for response instance
783          *
784          * @param       $responseInstance       An instance of a Responseable class
785          * @return      void
786          */
787         public final function setResponseInstance (Responseable $responseInstance) {
788                 $this->responseInstance = $responseInstance;
789         }
790
791         /**
792          * Getter for response instance
793          *
794          * @return      $responseInstance       An instance of a Responseable class
795          */
796         public final function getResponseInstance () {
797                 return $this->responseInstance;
798         }
799
800         /**
801          * Private getter for language instance
802          *
803          * @return      $langInstance   An instance to the language sub-system
804          */
805         protected final function getLanguageInstance () {
806                 $langInstance = Registry::getRegistry()->getInstance('language');
807                 return $langInstance;
808         }
809
810         /**
811          * Setter for language instance
812          *
813          * @param       $langInstance   An instance to the language sub-system
814          * @return      void
815          * @see         LanguageSystem
816          */
817         public final function setLanguageInstance (ManageableLanguage $langInstance) {
818                 Registry::getRegistry()->addInstance('language', $langInstance);
819         }
820
821         /**
822          * Private getter for file IO instance
823          *
824          * @return      $fileIoInstance         An instance to the file I/O sub-system
825          */
826         protected final function getFileIoInstance () {
827                 return $this->fileIoInstance;
828         }
829
830         /**
831          * Setter for file I/O instance
832          *
833          * @param       $fileIoInstance         An instance to the file I/O sub-system
834          * @return      void
835          */
836         public final function setFileIoInstance (IoHandler $fileIoInstance) {
837                 $this->fileIoInstance = $fileIoInstance;
838         }
839
840         /**
841          * Protected setter for user instance
842          *
843          * @param       $userInstance   An instance of a user class
844          * @return      void
845          */
846         protected final function setUserInstance (ManageableAccount $userInstance) {
847                 $this->userInstance = $userInstance;
848         }
849
850         /**
851          * Getter for user instance
852          *
853          * @return      $userInstance   An instance of a user class
854          */
855         public final function getUserInstance () {
856                 return $this->userInstance;
857         }
858
859         /**
860          * Setter for controller instance (this surely breaks a bit the MVC patterm)
861          *
862          * @param       $controllerInstance             An instance of the controller
863          * @return      void
864          */
865         public final function setControllerInstance (Controller $controllerInstance) {
866                 $this->controllerInstance = $controllerInstance;
867         }
868
869         /**
870          * Getter for controller instance (this surely breaks a bit the MVC patterm)
871          *
872          * @return      $controllerInstance             An instance of the controller
873          */
874         public final function getControllerInstance () {
875                 return $this->controllerInstance;
876         }
877
878         /**
879          * Setter for RNG instance
880          *
881          * @param       $rngInstance    An instance of a random number generator (RNG)
882          * @return      void
883          */
884         protected final function setRngInstance (RandomNumberGenerator $rngInstance) {
885                 $this->rngInstance = $rngInstance;
886         }
887
888         /**
889          * Getter for RNG instance
890          *
891          * @return      $rngInstance    An instance of a random number generator (RNG)
892          */
893         public final function getRngInstance () {
894                 return $this->rngInstance;
895         }
896
897         /**
898          * Setter for Cryptable instance
899          *
900          * @param       $cryptoInstance An instance of a Cryptable class
901          * @return      void
902          */
903         protected final function setCryptoInstance (Cryptable $cryptoInstance) {
904                 $this->cryptoInstance = $cryptoInstance;
905         }
906
907         /**
908          * Getter for Cryptable instance
909          *
910          * @return      $cryptoInstance An instance of a Cryptable class
911          */
912         public final function getCryptoInstance () {
913                 return $this->cryptoInstance;
914         }
915
916         /**
917          * Setter for the list instance
918          *
919          * @param       $listInstance   A list of Listable
920          * @return      void
921          */
922         protected final function setListInstance (Listable $listInstance) {
923                 $this->listInstance = $listInstance;
924         }
925
926         /**
927          * Getter for the list instance
928          *
929          * @return      $listInstance   A list of Listable
930          */
931         protected final function getListInstance () {
932                 return $this->listInstance;
933         }
934
935         /**
936          * Setter for the menu instance
937          *
938          * @param       $menuInstance   A RenderableMenu instance
939          * @return      void
940          */
941         protected final function setMenuInstance (RenderableMenu $menuInstance) {
942                 $this->menuInstance = $menuInstance;
943         }
944
945         /**
946          * Getter for the menu instance
947          *
948          * @return      $menuInstance   A RenderableMenu instance
949          */
950         protected final function getMenuInstance () {
951                 return $this->menuInstance;
952         }
953
954         /**
955          * Setter for image instance
956          *
957          * @param       $imageInstance  An instance of an image
958          * @return      void
959          */
960         public final function setImageInstance (BaseImage $imageInstance) {
961                 $this->imageInstance = $imageInstance;
962         }
963
964         /**
965          * Getter for image instance
966          *
967          * @return      $imageInstance  An instance of an image
968          */
969         public final function getImageInstance () {
970                 return $this->imageInstance;
971         }
972
973         /**
974          * Setter for stacker instance
975          *
976          * @param       $stackInstance  An instance of an stacker
977          * @return      void
978          */
979         public final function setStackInstance (Stackable $stackInstance) {
980                 $this->stackInstance = $stackInstance;
981         }
982
983         /**
984          * Getter for stacker instance
985          *
986          * @return      $stackInstance  An instance of an stacker
987          */
988         public final function getStackInstance () {
989                 return $this->stackInstance;
990         }
991
992         /**
993          * Setter for compressor instance
994          *
995          * @param       $compressorInstance     An instance of an compressor
996          * @return      void
997          */
998         public final function setCompressorInstance (Compressor $compressorInstance) {
999                 $this->compressorInstance = $compressorInstance;
1000         }
1001
1002         /**
1003          * Getter for compressor instance
1004          *
1005          * @return      $compressorInstance     An instance of an compressor
1006          */
1007         public final function getCompressorInstance () {
1008                 return $this->compressorInstance;
1009         }
1010
1011         /**
1012          * Setter for Parseable instance
1013          *
1014          * @param       $parserInstance An instance of an Parseable
1015          * @return      void
1016          */
1017         public final function setParserInstance (Parseable $parserInstance) {
1018                 $this->parserInstance = $parserInstance;
1019         }
1020
1021         /**
1022          * Getter for Parseable instance
1023          *
1024          * @return      $parserInstance An instance of an Parseable
1025          */
1026         public final function getParserInstance () {
1027                 return $this->parserInstance;
1028         }
1029
1030         /**
1031          * Setter for HandleableProtocol instance
1032          *
1033          * @param       $protocolInstance       An instance of an HandleableProtocol
1034          * @return      void
1035          */
1036         public final function setProtocolInstance (HandleableProtocol $protocolInstance = NULL) {
1037                 $this->protocolInstance = $protocolInstance;
1038         }
1039
1040         /**
1041          * Getter for HandleableProtocol instance
1042          *
1043          * @return      $protocolInstance       An instance of an HandleableProtocol
1044          */
1045         public final function getProtocolInstance () {
1046                 return $this->protocolInstance;
1047         }
1048
1049         /**
1050          * Setter for DatabaseWrapper instance
1051          *
1052          * @param       $wrapperInstance        An instance of an DatabaseWrapper
1053          * @return      void
1054          */
1055         public final function setWrapperInstance (DatabaseWrapper $wrapperInstance) {
1056                 $this->wrapperInstance = $wrapperInstance;
1057         }
1058
1059         /**
1060          * Getter for DatabaseWrapper instance
1061          *
1062          * @return      $wrapperInstance        An instance of an DatabaseWrapper
1063          */
1064         public final function getWrapperInstance () {
1065                 return $this->wrapperInstance;
1066         }
1067
1068         /**
1069          * Setter for socket resource
1070          *
1071          * @param       $socketResource         A valid socket resource
1072          * @return      void
1073          */
1074         public final function setSocketResource ($socketResource) {
1075                 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput($this->__toString() . '::' . __FUNCTION__ . ': socketResource=' . $socketResource . ',previous[' . gettype($this->socketResource) . ']=' . $this->socketResource);
1076                 $this->socketResource = $socketResource;
1077         }
1078
1079         /**
1080          * Getter for socket resource
1081          *
1082          * @return      $socketResource         A valid socket resource
1083          */
1084         public final function getSocketResource () {
1085                 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput($this->__toString() . '::' . __FUNCTION__ . ': socketResource[' . gettype($this->socketResource) . ']=' . $this->socketResource);
1086                 return $this->socketResource;
1087         }
1088
1089         /**
1090          * Setter for regular expression
1091          *
1092          * @param       $regularExpression      A valid regular expression
1093          * @return      void
1094          */
1095         public final function setRegularExpression ($regularExpression) {
1096                 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput($this->__toString() . '::' . __FUNCTION__ . ': regularExpression=' . $regularExpression . ',previous[' . gettype($this->regularExpression) . ']=' . $this->regularExpression);
1097                 $this->regularExpression = $regularExpression;
1098         }
1099
1100         /**
1101          * Getter for regular expression
1102          *
1103          * @return      $regularExpression      A valid regular expression
1104          */
1105         public final function getRegularExpression () {
1106                 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput($this->__toString() . '::' . __FUNCTION__ . ': regularExpression[' . gettype($this->regularExpression) . ']=' . $this->regularExpression);
1107                 return $this->regularExpression;
1108         }
1109
1110         /**
1111          * Setter for helper instance
1112          *
1113          * @param       $helperInstance         An instance of a helper class
1114          * @return      void
1115          */
1116         protected final function setHelperInstance (Helper $helperInstance) {
1117                 $this->helperInstance = $helperInstance;
1118         }
1119
1120         /**
1121          * Getter for helper instance
1122          *
1123          * @return      $helperInstance         An instance of a helper class
1124          */
1125         public final function getHelperInstance () {
1126                 return $this->helperInstance;
1127         }
1128
1129         /**
1130          * Setter for a Sourceable instance
1131          *
1132          * @param       $sourceInstance The Sourceable instance
1133          * @return      void
1134          */
1135         protected final function setSourceInstance (Sourceable $sourceInstance) {
1136                 $this->sourceInstance = $sourceInstance;
1137         }
1138
1139         /**
1140          * Getter for a Sourceable instance
1141          *
1142          * @return      $sourceInstance The Sourceable instance
1143          */
1144         protected final function getSourceInstance () {
1145                 return $this->sourceInstance;
1146         }
1147
1148         /**
1149          * Getter for a InputStream instance
1150          *
1151          * @param       $inputStreamInstance    The InputStream instance
1152          */
1153         protected final function getInputStreamInstance () {
1154                 return $this->inputStreamInstance;
1155         }
1156
1157         /**
1158          * Setter for a InputStream instance
1159          *
1160          * @param       $inputStreamInstance    The InputStream instance
1161          * @return      void
1162          */
1163         protected final function setInputStreamInstance (InputStream $inputStreamInstance) {
1164                 $this->inputStreamInstance = $inputStreamInstance;
1165         }
1166
1167         /**
1168          * Getter for a OutputStream instance
1169          *
1170          * @param       $outputStreamInstance   The OutputStream instance
1171          */
1172         protected final function getOutputStreamInstance () {
1173                 return $this->outputStreamInstance;
1174         }
1175
1176         /**
1177          * Setter for a OutputStream instance
1178          *
1179          * @param       $outputStreamInstance   The OutputStream instance
1180          * @return      void
1181          */
1182         protected final function setOutputStreamInstance (OutputStream $outputStreamInstance) {
1183                 $this->outputStreamInstance = $outputStreamInstance;
1184         }
1185
1186         /**
1187          * Setter for handler instance
1188          *
1189          * @param       $handlerInstance        An instance of a Handleable class
1190          * @return      void
1191          */
1192         protected final function setHandlerInstance (Handleable $handlerInstance) {
1193                 $this->handlerInstance = $handlerInstance;
1194         }
1195
1196         /**
1197          * Getter for handler instance
1198          *
1199          * @return      $handlerInstance        A Networkable instance
1200          */
1201         protected final function getHandlerInstance () {
1202                 return $this->handlerInstance;
1203         }
1204
1205         /**
1206          * Setter for visitor instance
1207          *
1208          * @param       $visitorInstance        A Visitor instance
1209          * @return      void
1210          */
1211         protected final function setVisitorInstance (Visitor $visitorInstance) {
1212                 $this->visitorInstance = $visitorInstance;
1213         }
1214
1215         /**
1216          * Getter for visitor instance
1217          *
1218          * @return      $visitorInstance        A Visitor instance
1219          */
1220         protected final function getVisitorInstance () {
1221                 return $this->visitorInstance;
1222         }
1223
1224         /**
1225          * Setter for DHT instance
1226          *
1227          * @param       $dhtInstance    A Distributable instance
1228          * @return      void
1229          */
1230         protected final function setDhtInstance (Distributable $dhtInstance) {
1231                 $this->dhtInstance = $dhtInstance;
1232         }
1233
1234         /**
1235          * Getter for DHT instance
1236          *
1237          * @return      $dhtInstance    A Distributable instance
1238          */
1239         protected final function getDhtInstance () {
1240                 return $this->dhtInstance;
1241         }
1242
1243         /**
1244          * Setter for raw package Data
1245          *
1246          * @param       $packageData    Raw package Data
1247          * @return      void
1248          */
1249         public final function setPackageData (array $packageData) {
1250                 $this->packageData = $packageData;
1251         }
1252
1253         /**
1254          * Getter for raw package Data
1255          *
1256          * @return      $packageData    Raw package Data
1257          */
1258         public function getPackageData () {
1259                 return $this->packageData;
1260         }
1261
1262
1263         /**
1264          * Setter for Iterator instance
1265          *
1266          * @param       $iteratorInstance       An instance of an Iterator
1267          * @return      void
1268          */
1269         protected final function setIteratorInstance (Iterator $iteratorInstance) {
1270                 $this->iteratorInstance = $iteratorInstance;
1271         }
1272
1273         /**
1274          * Getter for Iterator instance
1275          *
1276          * @return      $iteratorInstance       An instance of an Iterator
1277          */
1278         public final function getIteratorInstance () {
1279                 return $this->iteratorInstance;
1280         }
1281
1282         /**
1283          * Setter for FilePointer instance
1284          *
1285          * @param       $pointerInstance        An instance of an FilePointer class
1286          * @return      void
1287          */
1288         protected final function setPointerInstance (FilePointer $pointerInstance) {
1289                 $this->pointerInstance = $pointerInstance;
1290         }
1291
1292         /**
1293          * Getter for FilePointer instance
1294          *
1295          * @return      $pointerInstance        An instance of an FilePointer class
1296          */
1297         public final function getPointerInstance () {
1298                 return $this->pointerInstance;
1299         }
1300
1301         /**
1302          * Setter for Indexable instance
1303          *
1304          * @param       $indexInstance  An instance of an Indexable class
1305          * @return      void
1306          */
1307         protected final function setIndexInstance (Indexable $indexInstance) {
1308                 $this->indexInstance = $indexInstance;
1309         }
1310
1311         /**
1312          * Getter for Indexable instance
1313          *
1314          * @return      $indexInstance  An instance of an Indexable class
1315          */
1316         public final function getIndexInstance () {
1317                 return $this->indexInstance;
1318         }
1319
1320         /**
1321          * Setter for Block instance
1322          *
1323          * @param       $blockInstance  An instance of an Block class
1324          * @return      void
1325          */
1326         protected final function setBlockInstance (Block $blockInstance) {
1327                 $this->blockInstance = $blockInstance;
1328         }
1329
1330         /**
1331          * Getter for Block instance
1332          *
1333          * @return      $blockInstance  An instance of an Block class
1334          */
1335         public final function getBlockInstance () {
1336                 return $this->blockInstance;
1337         }
1338
1339         /**
1340          * Setter for Minable instance
1341          *
1342          * @param       $minableInstance        A Minable instance
1343          * @return      void
1344          */
1345         protected final function setMinableInstance (Minable $minableInstance) {
1346                 $this->minableInstance = $minableInstance;
1347         }
1348
1349         /**
1350          * Getter for minable instance
1351          *
1352          * @return      $minableInstance        A Minable instance
1353          */
1354         protected final function getMinableInstance () {
1355                 return $this->minableInstance;
1356         }
1357
1358         /**
1359          * Setter for FrameworkDirectory instance
1360          *
1361          * @param       $directoryInstance      A FrameworkDirectoryPointer instance
1362          * @return      void
1363          */
1364         protected final function setDirectoryInstance (FrameworkDirectory $directoryInstance) {
1365                 $this->directoryInstance = $directoryInstance;
1366         }
1367
1368         /**
1369          * Getter for FrameworkDirectory instance
1370          *
1371          * @return      $directoryInstance      A FrameworkDirectory instance
1372          */
1373         protected final function getDirectoryInstance () {
1374                 return $this->directoryInstance;
1375         }
1376
1377         /**
1378          * Setter for listener instance
1379          *
1380          * @param       $listenerInstance       A Listenable instance
1381          * @return      void
1382          */
1383         protected final function setListenerInstance (Listenable $listenerInstance) {
1384                 $this->listenerInstance = $listenerInstance;
1385         }
1386
1387         /**
1388          * Getter for listener instance
1389          *
1390          * @return      $listenerInstance       A Listenable instance
1391          */
1392         protected final function getListenerInstance () {
1393                 return $this->listenerInstance;
1394         }
1395
1396         /**
1397          * Checks whether an object equals this object. You should overwrite this
1398          * method to implement own equality checks
1399          *
1400          * @param       $objectInstance         An instance of a FrameworkInterface object
1401          * @return      $equals                         Whether both objects equals
1402          */
1403         public function equals (FrameworkInterface $objectInstance) {
1404                 // Now test it
1405                 $equals = ((
1406                         $this->__toString() == $objectInstance->__toString()
1407                 ) && (
1408                         $this->hashCode() == $objectInstance->hashCode()
1409                 ));
1410
1411                 // Return the result
1412                 return $equals;
1413         }
1414
1415         /**
1416          * Generates a generic hash code of this class. You should really overwrite
1417          * this method with your own hash code generator code. But keep KISS in mind.
1418          *
1419          * @return      $hashCode       A generic hash code respresenting this whole class
1420          */
1421         public function hashCode () {
1422                 // Simple hash code
1423                 return crc32($this->__toString());
1424         }
1425
1426         /**
1427          * Formats computer generated price values into human-understandable formats
1428          * with thousand and decimal separators.
1429          *
1430          * @param       $value          The in computer format value for a price
1431          * @param       $currency       The currency symbol (use HTML-valid characters!)
1432          * @param       $decNum         Number of decimals after commata
1433          * @return      $price          The for the current language formated price string
1434          * @throws      MissingDecimalsThousandsSeparatorException      If decimals or
1435          *                                                                                              thousands separator
1436          *                                                                                              is missing
1437          */
1438         public function formatCurrency ($value, $currency = '&euro;', $decNum = 2) {
1439                 // Are all required attriutes set?
1440                 if ((!isset($this->decimals)) || (!isset($this->thousands))) {
1441                         // Throw an exception
1442                         throw new MissingDecimalsThousandsSeparatorException($this, self::EXCEPTION_ATTRIBUTES_ARE_MISSING);
1443                 } // END - if
1444
1445                 // Cast the number
1446                 $value = (float) $value;
1447
1448                 // Reformat the US number
1449                 $price = number_format($value, $decNum, $this->decimals, $this->thousands) . $currency;
1450
1451                 // Return as string...
1452                 return $price;
1453         }
1454
1455         /**
1456          * Appends a trailing slash to a string
1457          *
1458          * @param       $str    A string (maybe) without trailing slash
1459          * @return      $str    A string with an auto-appended trailing slash
1460          */
1461         public final function addMissingTrailingSlash ($str) {
1462                 // Is there a trailing slash?
1463                 if (substr($str, -1, 1) != '/') {
1464                         $str .= '/';
1465                 } // END - if
1466
1467                 // Return string with trailing slash
1468                 return $str;
1469         }
1470
1471         /**
1472          * Prepare the template engine (WebTemplateEngine by default) for a given
1473          * application helper instance (ApplicationHelper by default).
1474          *
1475          * @param               $applicationInstance    An application helper instance or
1476          *                                                                              null if we shall use the default
1477          * @return              $templateInstance               The template engine instance
1478          * @throws              NullPointerException    If the discovered application
1479          *                                                                              instance is still null
1480          */
1481         protected function prepareTemplateInstance (ManageableApplication $applicationInstance = NULL) {
1482                 // Is the application instance set?
1483                 if (is_null($applicationInstance)) {
1484                         // Get the current instance
1485                         $applicationInstance = $this->getApplicationInstance();
1486
1487                         // Still null?
1488                         if (is_null($applicationInstance)) {
1489                                 // Thrown an exception
1490                                 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
1491                         } // END - if
1492                 } // END - if
1493
1494                 // Initialize the template engine
1495                 $templateInstance = ObjectFactory::createObjectByConfiguredName('web_template_class');
1496
1497                 // Return the prepared instance
1498                 return $templateInstance;
1499         }
1500
1501         /**
1502          * Debugs this instance by putting out it's full content
1503          *
1504          * @param       $message        Optional message to show in debug output
1505          * @return      void
1506          */
1507         public final function debugInstance ($message = '') {
1508                 // Restore the error handler to avoid trouble with missing array elements or undeclared variables
1509                 restore_error_handler();
1510
1511                 // Init content
1512                 $content = '';
1513
1514                 // Is a message set?
1515                 if (!empty($message)) {
1516                         // Construct message
1517                         $content = sprintf('<div class="debug_message">Message: %s</div>' . PHP_EOL, $message);
1518                 } // END - if
1519
1520                 // Generate the output
1521                 $content .= sprintf('<pre>%s</pre>',
1522                         trim(
1523                                 htmlentities(
1524                                         print_r($this, TRUE)
1525                                 )
1526                         )
1527                 );
1528
1529                 // Output it
1530                 ApplicationEntryPoint::app_exit(sprintf('<div class="debug_header">%s debug output:</div><div class="debug_content">%s</div>Loaded includes: <div class="debug_include_list">%s</div>',
1531                         $this->__toString(),
1532                         $content,
1533                         ClassLoader::getSelfInstance()->getPrintableIncludeList()
1534                 ));
1535         }
1536
1537         /**
1538          * Replaces control characters with printable output
1539          *
1540          * @param       $str    String with control characters
1541          * @return      $str    Replaced string
1542          */
1543         protected function replaceControlCharacters ($str) {
1544                 // Replace them
1545                 $str = str_replace(
1546                         chr(13), '[r]', str_replace(
1547                         chr(10), '[n]', str_replace(
1548                         chr(9) , '[t]',
1549                         $str
1550                 )));
1551
1552                 // Return it
1553                 return $str;
1554         }
1555
1556         /**
1557          * Output a partial stub message for the caller method
1558          *
1559          * @param       $message        An optional message to display
1560          * @return      void
1561          */
1562         protected function partialStub ($message = '') {
1563                 // Get the backtrace
1564                 $backtrace = debug_backtrace();
1565
1566                 // Generate the class::method string
1567                 $methodName = 'UnknownClass-&gt;unknownMethod';
1568                 if ((isset($backtrace[1]['class'])) && (isset($backtrace[1]['function']))) {
1569                         $methodName = $backtrace[1]['class'] . '-&gt;' . $backtrace[1]['function'];
1570                 } // END - if
1571
1572                 // Construct the full message
1573                 $stubMessage = sprintf('[%s:] Partial stub!',
1574                         $methodName
1575                 );
1576
1577                 // Is the extra message given?
1578                 if (!empty($message)) {
1579                         // Then add it as well
1580                         $stubMessage .= ' Message: ' . $message;
1581                 } // END - if
1582
1583                 // Debug instance is there?
1584                 if (!is_null($this->getDebugInstance())) {
1585                         // Output stub message
1586                         self::createDebugInstance(__CLASS__)->debugOutput($stubMessage);
1587                 } else {
1588                         // Trigger an error
1589                         trigger_error($stubMessage);
1590                         exit;
1591                 }
1592         }
1593
1594         /**
1595          * Outputs a debug backtrace and stops further script execution
1596          *
1597          * @param       $message        An optional message to output
1598          * @param       $doExit         Whether exit the program (TRUE is default)
1599          * @return      void
1600          */
1601         public function debugBackTrace ($message = '', $doExit = TRUE) {
1602                 // Sorry, there is no other way getting this nice backtrace
1603                 if (!empty($message)) {
1604                         // Output message
1605                         printf('Message: %s<br />' . chr(10), $message);
1606                 } // END - if
1607
1608                 print('<pre>');
1609                 debug_print_backtrace();
1610                 print('</pre>');
1611
1612                 // Exit program?
1613                 if ($doExit === TRUE) {
1614                         exit();
1615                 } // END - if
1616         }
1617
1618         /**
1619          * Creates an instance of a debugger instance
1620          *
1621          * @param       $className              Name of the class (currently unsupported)
1622          * @return      $debugInstance  An instance of a debugger class
1623          */
1624         public final static function createDebugInstance ($className) {
1625                 // Is the instance set?
1626                 if (!Registry::getRegistry()->instanceExists('debug')) {
1627                         // Init debug instance
1628                         $debugInstance = NULL;
1629
1630                         // Try it
1631                         try {
1632                                 // Get a debugger instance
1633                                 $debugInstance = DebugMiddleware::createDebugMiddleware(FrameworkConfiguration::getSelfInstance()->getConfigEntry('debug_class'));
1634                         } catch (NullPointerException $e) {
1635                                 // Didn't work, no instance there
1636                                 exit('Cannot create debugInstance! Exception=' . $e->__toString() . ', message=' . $e->getMessage());
1637                         }
1638
1639                         // Empty string should be ignored and used for testing the middleware
1640                         DebugMiddleware::getSelfInstance()->output('');
1641
1642                         // Set it in its own class. This will set it in the registry
1643                         $debugInstance->setDebugInstance($debugInstance);
1644                 } else {
1645                         // Get instance from registry
1646                         $debugInstance = Registry::getRegistry()->getDebugInstance();
1647                 }
1648
1649                 // Return it
1650                 return $debugInstance;
1651         }
1652
1653         /**
1654          * Simple output of a message with line-break
1655          *
1656          * @param       $message        Message to output
1657          * @return      void
1658          */
1659         public function outputLine ($message) {
1660                 // Simply output it
1661                 print($message . PHP_EOL);
1662         }
1663
1664         /**
1665          * Outputs a debug message whether to debug instance (should be set!) or
1666          * dies with or ptints the message. Do NEVER EVER rewrite the exit() call to
1667          * ApplicationEntryPoint::app_exit(), this would cause an endless loop.
1668          *
1669          * @param       $message        Message we shall send out...
1670          * @param       $doPrint        Whether print or die here (default: print)
1671          * @paran       $stripTags      Whether to strip tags (default: FALSE)
1672          * @return      void
1673          */
1674         public function debugOutput ($message, $doPrint = TRUE, $stripTags = FALSE) {
1675                 // Set debug instance to NULL
1676                 $debugInstance = NULL;
1677
1678                 // Try it:
1679                 try {
1680                         // Get debug instance
1681                         $debugInstance = $this->getDebugInstance();
1682                 } catch (NullPointerException $e) {
1683                         // The debug instance is not set (yet)
1684                 }
1685
1686                 // Is the debug instance there?
1687                 if (is_object($debugInstance)) {
1688                         // Use debug output handler
1689                         $debugInstance->output($message, $stripTags);
1690
1691                         if ($doPrint === FALSE) {
1692                                 // Die here if not printed
1693                                 exit();
1694                         } // END - if
1695                 } else {
1696                         // Are debug times enabled?
1697                         if ($this->getConfigInstance()->getConfigEntry('debug_output_timings') == 'Y') {
1698                                 // Prepent it
1699                                 $message = $this->getPrintableExecutionTime() . $message;
1700                         } // END - if
1701
1702                         // Put directly out
1703                         if ($doPrint === TRUE) {
1704                                 // Print message
1705                                 $this->outputLine($message);
1706                         } else {
1707                                 // Die here
1708                                 exit($message);
1709                         }
1710                 }
1711         }
1712
1713         /**
1714          * Converts e.g. a command from URL to a valid class by keeping out bad characters
1715          *
1716          * @param       $str            The string, what ever it is needs to be converted
1717          * @return      $className      Generated class name
1718          */
1719         public function convertToClassName ($str) {
1720                 // Init class name
1721                 $className = '';
1722
1723                 // Convert all dashes in underscores
1724                 $str = $this->convertDashesToUnderscores($str);
1725
1726                 // Now use that underscores to get classname parts for hungarian style
1727                 foreach (explode('_', $str) as $strPart) {
1728                         // Make the class name part lower case and first upper case
1729                         $className .= ucfirst(strtolower($strPart));
1730                 } // END - foreach
1731
1732                 // Return class name
1733                 return $className;
1734         }
1735
1736         /**
1737          * Converts dashes to underscores, e.g. useable for configuration entries
1738          *
1739          * @param       $str    The string with maybe dashes inside
1740          * @return      $str    The converted string with no dashed, but underscores
1741          */
1742         public final function convertDashesToUnderscores ($str) {
1743                 // Convert them all
1744                 $str = str_replace('-', '_', $str);
1745
1746                 // Return converted string
1747                 return $str;
1748         }
1749
1750         /**
1751          * Marks up the code by adding e.g. line numbers
1752          *
1753          * @param       $phpCode                Unmarked PHP code
1754          * @return      $markedCode             Marked PHP code
1755          */
1756         public function markupCode ($phpCode) {
1757                 // Init marked code
1758                 $markedCode = '';
1759
1760                 // Get last error
1761                 $errorArray = error_get_last();
1762
1763                 // Init the code with error message
1764                 if (is_array($errorArray)) {
1765                         // Get error infos
1766                         $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>',
1767                                 basename($errorArray['file']),
1768                                 $errorArray['line'],
1769                                 $errorArray['message'],
1770                                 $errorArray['type']
1771                         );
1772                 } // END - if
1773
1774                 // Add line number to the code
1775                 foreach (explode(chr(10), $phpCode) as $lineNo => $code) {
1776                         // Add line numbers
1777                         $markedCode .= sprintf('<span id="code_line">%s</span>: %s' . chr(10),
1778                                 ($lineNo + 1),
1779                                 htmlentities($code, ENT_QUOTES)
1780                         );
1781                 } // END - foreach
1782
1783                 // Return the code
1784                 return $markedCode;
1785         }
1786
1787         /**
1788          * Filter a given GMT timestamp (non Uni* stamp!) to make it look more
1789          * beatiful for web-based front-ends. If null is given a message id
1790          * null_timestamp will be resolved and returned.
1791          *
1792          * @param       $timestamp      Timestamp to prepare (filter) for display
1793          * @return      $readable       A readable timestamp
1794          */
1795         public function doFilterFormatTimestamp ($timestamp) {
1796                 // Default value to return
1797                 $readable = '???';
1798
1799                 // Is the timestamp null?
1800                 if (is_null($timestamp)) {
1801                         // Get a message string
1802                         $readable = $this->getLanguageInstance()->getMessage('null_timestamp');
1803                 } else {
1804                         switch ($this->getLanguageInstance()->getLanguageCode()) {
1805                                 case 'de': // German format is a bit different to default
1806                                         // Split the GMT stamp up
1807                                         $dateTime  = explode(' ', $timestamp  );
1808                                         $dateArray = explode('-', $dateTime[0]);
1809                                         $timeArray = explode(':', $dateTime[1]);
1810
1811                                         // Construct the timestamp
1812                                         $readable = sprintf($this->getConfigInstance()->getConfigEntry('german_date_time'),
1813                                                 $dateArray[0],
1814                                                 $dateArray[1],
1815                                                 $dateArray[2],
1816                                                 $timeArray[0],
1817                                                 $timeArray[1],
1818                                                 $timeArray[2]
1819                                         );
1820                                         break;
1821
1822                                 default: // Default is pass-through
1823                                         $readable = $timestamp;
1824                                         break;
1825                         } // END - switch
1826                 }
1827
1828                 // Return the stamp
1829                 return $readable;
1830         }
1831
1832         /**
1833          * Filter a given number into a localized number
1834          *
1835          * @param       $value          The raw value from e.g. database
1836          * @return      $localized      Localized value
1837          */
1838         public function doFilterFormatNumber ($value) {
1839                 // Generate it from config and localize dependencies
1840                 switch ($this->getLanguageInstance()->getLanguageCode()) {
1841                         case 'de': // German format is a bit different to default
1842                                 $localized = number_format($value, $this->getConfigInstance()->getConfigEntry('decimals'), ',', '.');
1843                                 break;
1844
1845                         default: // US, etc.
1846                                 $localized = number_format($value, $this->getConfigInstance()->getConfigEntry('decimals'), '.', ',');
1847                                 break;
1848                 } // END - switch
1849
1850                 // Return it
1851                 return $localized;
1852         }
1853
1854         /**
1855          * "Getter" for databse entry
1856          *
1857          * @return      $entry  An array with database entries
1858          * @throws      NullPointerException    If the database result is not found
1859          * @throws      InvalidDatabaseResultException  If the database result is invalid
1860          */
1861         protected final function getDatabaseEntry () {
1862                 // Is there an instance?
1863                 if (is_null($this->getResultInstance())) {
1864                         // Throw an exception here
1865                         throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
1866                 } // END - if
1867
1868                 // Rewind it
1869                 $this->getResultInstance()->rewind();
1870
1871                 // Do we have an entry?
1872                 if ($this->getResultInstance()->valid() === FALSE) {
1873                         throw new InvalidDatabaseResultException(array($this, $this->getResultInstance()), DatabaseResult::EXCEPTION_INVALID_DATABASE_RESULT);
1874                 } // END - if
1875
1876                 // Get next entry
1877                 $this->getResultInstance()->next();
1878
1879                 // Fetch it
1880                 $entry = $this->getResultInstance()->current();
1881
1882                 // And return it
1883                 return $entry;
1884         }
1885
1886         /**
1887          * Getter for field name
1888          *
1889          * @param       $fieldName              Field name which we shall get
1890          * @return      $fieldValue             Field value from the user
1891          * @throws      NullPointerException    If the result instance is null
1892          */
1893         public final function getField ($fieldName) {
1894                 // Default field value
1895                 $fieldValue = NULL;
1896
1897                 // Get result instance
1898                 $resultInstance = $this->getResultInstance();
1899
1900                 // Is this instance null?
1901                 if (is_null($resultInstance)) {
1902                         // Then the user instance is no longer valid (expired cookies?)
1903                         throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
1904                 } // END - if
1905
1906                 // Get current array
1907                 $fieldArray = $resultInstance->current();
1908                 //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput($fieldName.':<pre>'.print_r($fieldArray, TRUE).'</pre>');
1909
1910                 // Convert dashes to underscore
1911                 $fieldName = $this->convertDashesToUnderscores($fieldName);
1912
1913                 // Does the field exist?
1914                 if (isset($fieldArray[$fieldName])) {
1915                         // Get it
1916                         $fieldValue = $fieldArray[$fieldName];
1917                 } else {
1918                         // Missing field entry, may require debugging
1919                         self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']:fieldName=' . $fieldName . ' not found!');
1920                 }
1921
1922                 // Return it
1923                 return $fieldValue;
1924         }
1925
1926         /**
1927          * Flushs all pending updates to the database layer
1928          *
1929          * @return      void
1930          */
1931         public function flushPendingUpdates () {
1932                 // Get result instance
1933                 $resultInstance = $this->getResultInstance();
1934
1935                 // Do we have data to update?
1936                 if ((is_object($resultInstance)) && ($resultInstance->ifDataNeedsFlush())) {
1937                         // Get wrapper class name config entry
1938                         $configEntry = $resultInstance->getUpdateInstance()->getWrapperConfigEntry();
1939
1940                         // Create object instance
1941                         $wrapperInstance = ObjectFactory::createObjectByConfiguredName($configEntry);
1942
1943                         // Yes, then send the whole result to the database layer
1944                         $wrapperInstance->doUpdateByResult($this->getResultInstance());
1945                 } // END - if
1946         }
1947
1948         /**
1949          * Outputs a deprecation warning to the developer.
1950          *
1951          * @param       $message        The message we shall output to the developer
1952          * @return      void
1953          * @todo        Write a logging mechanism for productive mode
1954          */
1955         public function deprecationWarning ($message) {
1956                 // Is developer mode active?
1957                 if (defined('DEVELOPER')) {
1958                         // Debug instance is there?
1959                         if (!is_null($this->getDebugInstance())) {
1960                                 // Output stub message
1961                                 self::createDebugInstance(__CLASS__)->debugOutput($message);
1962                         } else {
1963                                 // Trigger an error
1964                                 trigger_error($message . "<br />\n");
1965                                 exit;
1966                         }
1967                 } else {
1968                         // @TODO Finish this part!
1969                         $this->partialStub('Developer mode inactive. Message:' . $message);
1970                 }
1971         }
1972
1973         /**
1974          * Checks whether the given PHP extension is loaded
1975          *
1976          * @param       $phpExtension   The PHP extension we shall check
1977          * @return      $isLoaded       Whether the PHP extension is loaded
1978          */
1979         public final function isPhpExtensionLoaded ($phpExtension) {
1980                 // Is it loaded?
1981                 $isLoaded = in_array($phpExtension, get_loaded_extensions());
1982
1983                 // Return result
1984                 return $isLoaded;
1985         }
1986
1987         /**
1988          * "Getter" as a time() replacement but with milliseconds. You should use this
1989          * method instead of the encapsulated getimeofday() function.
1990          *
1991          * @return      $milliTime      Timestamp with milliseconds
1992          */
1993         public function getMilliTime () {
1994                 // Get the time of day as float
1995                 $milliTime = gettimeofday(TRUE);
1996
1997                 // Return it
1998                 return $milliTime;
1999         }
2000
2001         /**
2002          * Idles (sleeps) for given milliseconds
2003          *
2004          * @return      $hasSlept       Whether it goes fine
2005          */
2006         public function idle ($milliSeconds) {
2007                 // Sleep is fine by default
2008                 $hasSlept = TRUE;
2009
2010                 // Idle so long with found function
2011                 if (function_exists('time_sleep_until')) {
2012                         // Get current time and add idle time
2013                         $sleepUntil = $this->getMilliTime() + abs($milliSeconds) / 1000;
2014
2015                         // New PHP 5.1.0 function found, ignore errors
2016                         $hasSlept = @time_sleep_until($sleepUntil);
2017                 } else {
2018                         /*
2019                          * My Sun station doesn't have that function even with latest PHP
2020                          * package. :(
2021                          */
2022                         usleep($milliSeconds * 1000);
2023                 }
2024
2025                 // Return result
2026                 return $hasSlept;
2027         }
2028         /**
2029          * Converts a hexadecimal string, even with negative sign as first string to
2030          * a decimal number using BC functions.
2031          *
2032          * This work is based on comment #86673 on php.net documentation page at:
2033          * <http://de.php.net/manual/en/function.dechex.php#86673>
2034          *
2035          * @param       $hex    Hexadecimal string
2036          * @return      $dec    Decimal number
2037          */
2038         protected function hex2dec ($hex) {
2039                 // Convert to all lower-case
2040                 $hex = strtolower($hex);
2041
2042                 // Detect sign (negative/positive numbers)
2043                 $sign = '';
2044                 if (substr($hex, 0, 1) == '-') {
2045                         $sign = '-';
2046                         $hex = substr($hex, 1);
2047                 } // END - if
2048
2049                 // Decode the hexadecimal string into a decimal number
2050                 $dec = 0;
2051                 for ($i = strlen($hex) - 1, $e = 1; $i >= 0; $i--, $e = bcmul($e, 16)) {
2052                         $factor = self::$hexdec[substr($hex, $i, 1)];
2053                         $dec = bcadd($dec, bcmul($factor, $e));
2054                 } // END - for
2055
2056                 // Return the decimal number
2057                 return $sign . $dec;
2058         }
2059
2060         /**
2061          * Converts even very large decimal numbers, also signed, to a hexadecimal
2062          * string.
2063          *
2064          * This work is based on comment #97756 on php.net documentation page at:
2065          * <http://de.php.net/manual/en/function.hexdec.php#97756>
2066          *
2067          * @param       $dec            Decimal number, even with negative sign
2068          * @param       $maxLength      Optional maximum length of the string
2069          * @return      $hex    Hexadecimal string
2070          */
2071         protected function dec2hex ($dec, $maxLength = 0) {
2072                 // maxLength can be zero or devideable by 2
2073                 assert(($maxLength == 0) || (($maxLength % 2) == 0));
2074
2075                 // Detect sign (negative/positive numbers)
2076                 $sign = '';
2077                 if ($dec < 0) {
2078                         $sign = '-';
2079                         $dec = abs($dec);
2080                 } // END - if
2081
2082                 // Encode the decimal number into a hexadecimal string
2083                 $hex = '';
2084                 do {
2085                         $hex = self::$dechex[($dec % (2 ^ 4))] . $hex;
2086                         $dec /= (2 ^ 4);
2087                 } while ($dec >= 1);
2088
2089                 /*
2090                  * Leading zeros are required for hex-decimal "numbers". In some
2091                  * situations more leading zeros are wanted, so check for both
2092                  * conditions.
2093                  */
2094                 if ($maxLength > 0) {
2095                         // Prepend more zeros
2096                         $hex = str_pad($hex, $maxLength, '0', STR_PAD_LEFT);
2097                 } elseif ((strlen($hex) % 2) != 0) {
2098                         // Only make string's length dividable by 2
2099                         $hex = '0' . $hex;
2100                 }
2101
2102                 // Return the hexadecimal string
2103                 return $sign . $hex;
2104         }
2105
2106         /**
2107          * Converts a ASCII string (0 to 255) into a decimal number.
2108          *
2109          * @param       $asc    The ASCII string to be converted
2110          * @return      $dec    Decimal number
2111          */
2112         protected function asc2dec ($asc) {
2113                 // Convert it into a hexadecimal number
2114                 $hex = bin2hex($asc);
2115
2116                 // And back into a decimal number
2117                 $dec = $this->hex2dec($hex);
2118
2119                 // Return it
2120                 return $dec;
2121         }
2122
2123         /**
2124          * Converts a decimal number into an ASCII string.
2125          *
2126          * @param       $dec            Decimal number
2127          * @return      $asc    An ASCII string
2128          */
2129         protected function dec2asc ($dec) {
2130                 // First convert the number into a hexadecimal string
2131                 $hex = $this->dec2hex($dec);
2132
2133                 // Then convert it into the ASCII string
2134                 $asc = $this->hex2asc($hex);
2135
2136                 // Return it
2137                 return $asc;
2138         }
2139
2140         /**
2141          * Converts a hexadecimal number into an ASCII string. Negative numbers
2142          * are not allowed.
2143          *
2144          * @param       $hex    Hexadecimal string
2145          * @return      $asc    An ASCII string
2146          */
2147         protected function hex2asc ($hex) {
2148                 // Check for length, it must be devideable by 2
2149                 //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('hex='.$hex);
2150                 assert((strlen($hex) % 2) == 0);
2151
2152                 // Walk the string
2153                 $asc = '';
2154                 for ($idx = 0; $idx < strlen($hex); $idx+=2) {
2155                         // Get the decimal number of the chunk
2156                         $part = hexdec(substr($hex, $idx, 2));
2157
2158                         // Add it to the final string
2159                         $asc .= chr($part);
2160                 } // END - for
2161
2162                 // Return the final string
2163                 return $asc;
2164         }
2165
2166         /**
2167          * Checks whether the given encoded data was encoded with Base64
2168          *
2169          * @param       $encodedData    Encoded data we shall check
2170          * @return      $isBase64               Whether the encoded data is Base64
2171          */
2172         protected function isBase64Encoded ($encodedData) {
2173                 // Determine it
2174                 $isBase64 = (@base64_decode($encodedData, TRUE) !== FALSE);
2175
2176                 // Return it
2177                 return $isBase64;
2178         }
2179
2180         /**
2181          * "Getter" to get response/request type from analysis of the system.
2182          *
2183          * @return      $responseType   Analyzed response type
2184          */
2185         protected function getResponseTypeFromSystem () {
2186                 // Default is console
2187                 $responseType = 'console';
2188
2189                 // Is 'HTTP_HOST' set?
2190                 if (isset($_SERVER['HTTP_HOST'])) {
2191                         // Then it is a HTTP response/request
2192                         $responseType = 'http';
2193                 } // END - if
2194
2195                 // Return it
2196                 return $responseType;
2197         }
2198
2199         /**
2200          * Gets a cache key from Criteria instance
2201          *
2202          * @param       $criteriaInstance       An instance of a Criteria class
2203          * @param       $onlyKeys                       Only use these keys for a cache key
2204          * @return      $cacheKey                       A cache key suitable for lookup/storage purposes
2205          */
2206         protected function getCacheKeyByCriteria (Criteria $criteriaInstance, array $onlyKeys = array()) {
2207                 // Generate it
2208                 $cacheKey = sprintf('%s@%s',
2209                         $this->__toString(),
2210                         $criteriaInstance->getCacheKey($onlyKeys)
2211                 );
2212
2213                 // And return it
2214                 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput($this->__toString() . ': cacheKey=' . $cacheKey);
2215                 return $cacheKey;
2216         }
2217
2218         /**
2219          * Getter for startup time in miliseconds
2220          *
2221          * @return      $startupTime    Startup time in miliseconds
2222          */
2223         protected function getStartupTime () {
2224                 return self::$startupTime;
2225         }
2226
2227         /**
2228          * "Getter" for a printable currently execution time in nice braces
2229          *
2230          * @return      $executionTime  Current execution time in nice braces
2231          */
2232         protected function getPrintableExecutionTime () {
2233                 // Caculate the execution time
2234                 $executionTime = microtime(TRUE) - $this->getStartupTime();
2235
2236                 // Pack it in nice braces
2237                 $executionTime = sprintf('[ %01.5f ] ', $executionTime);
2238
2239                 // And return it
2240                 return $executionTime;
2241         }
2242
2243         /**
2244          * Hashes a given string with a simple but stronger hash function (no salt)
2245          * and hex-encode it.
2246          *
2247          * @param       $str    The string to be hashed
2248          * @return      $hash   The hash from string $str
2249          */
2250         public static final function hash ($str) {
2251                 // Hash given string with (better secure) hasher
2252                 $hash = bin2hex(mhash(MHASH_SHA256, $str));
2253
2254                 // Return it
2255                 return $hash;
2256         }
2257
2258         /**
2259          * "Getter" for length of hash() output. This will be "cached" to speed up
2260          * things.
2261          *
2262          * @return      $length         Length of hash() output
2263          */
2264         public static final function getHashLength () {
2265                 // Is it cashed?
2266                 if (is_null(self::$hashLength)) {
2267                         // No, then hash a string and save its length.
2268                         self::$hashLength = strlen(self::hash('abc123'));
2269                 } // END - if
2270
2271                 // Return it
2272                 return self::$hashLength;
2273         }
2274
2275         /**
2276          * Checks whether the given number is really a number (only chars 0-9).
2277          *
2278          * @param       $num            A string consisting only chars between 0 and 9
2279          * @param       $castValue      Whether to cast the value to double. Do only use this to secure numbers from Requestable classes.
2280          * @param       $assertMismatch         Whether to assert mismatches
2281          * @return      $ret            The (hopefully) secured numbered value
2282          */
2283         public function bigintval ($num, $castValue = TRUE, $assertMismatch = FALSE) {
2284                 // Filter all numbers out
2285                 $ret = preg_replace('/[^0123456789]/', '', $num);
2286
2287                 // Shall we cast?
2288                 if ($castValue === TRUE) {
2289                         // Cast to biggest numeric type
2290                         $ret = (double) $ret;
2291                 } // END - if
2292
2293                 // Assert only if requested
2294                 if ($assertMismatch === TRUE) {
2295                         // Has the whole value changed?
2296                         assert(('' . $ret . '' != '' . $num . '') && (!is_null($num)));
2297                 } // END - if
2298
2299                 // Return result
2300                 return $ret;
2301         }
2302
2303         /**
2304          * Checks whether the given hexadecimal number is really a hex-number (only chars 0-9,a-f).
2305          *
2306          * @param       $num    A string consisting only chars between 0 and 9
2307          * @param       $assertMismatch         Whether to assert mismatches
2308          * @return      $ret    The (hopefully) secured hext-numbered value
2309          */
2310         public function hexval ($num, $assertMismatch = FALSE) {
2311                 // Filter all numbers out
2312                 $ret = preg_replace('/[^0123456789abcdefABCDEF]/', '', $num);
2313
2314                 // Assert only if requested
2315                 if ($assertMismatch === TRUE) {
2316                         // Has the whole value changed?
2317                         assert(('' . $ret . '' != '' . $num . '') && (!is_null($num)));
2318                 } // END - if
2319
2320                 // Return result
2321                 return $ret;
2322         }
2323
2324         /**
2325          * Checks whether start/end marker are set
2326          *
2327          * @param       $data   Data to be checked
2328          * @return      $isset  Whether start/end marker are set
2329          */
2330         public final function ifStartEndMarkersSet ($data) {
2331                 // Determine it
2332                 $isset = ((substr($data, 0, strlen(BaseRawDataHandler::STREAM_START_MARKER)) == BaseRawDataHandler::STREAM_START_MARKER) && (substr($data, -1 * strlen(BaseRawDataHandler::STREAM_END_MARKER), strlen(BaseRawDataHandler::STREAM_END_MARKER)) == BaseRawDataHandler::STREAM_END_MARKER));
2333
2334                 // ... and return it
2335                 return $isset;
2336         }
2337
2338         /**
2339          * Determines if an element is set in the generic array
2340          *
2341          * @param       $keyGroup       Main group for the key
2342          * @param       $subGroup       Sub group for the key
2343          * @param       $key            Key to check
2344          * @param       $element        Element to check
2345          * @return      $isset          Whether the given key is set
2346          */
2347         protected final function isGenericArrayElementSet ($keyGroup, $subGroup, $key, $element) {
2348                 // Debug message
2349                 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element);
2350
2351                 // Is it there?
2352                 $isset = isset($this->genericArray[$keyGroup][$subGroup][$key][$element]);
2353
2354                 // Return it
2355                 return $isset;
2356         }
2357         /**
2358          * Determines if a key is set in the generic array
2359          *
2360          * @param       $keyGroup       Main group for the key
2361          * @param       $subGroup       Sub group for the key
2362          * @param       $key            Key to check
2363          * @return      $isset          Whether the given key is set
2364          */
2365         protected final function isGenericArrayKeySet ($keyGroup, $subGroup, $key) {
2366                 // Debug message
2367                 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
2368
2369                 // Is it there?
2370                 $isset = isset($this->genericArray[$keyGroup][$subGroup][$key]);
2371
2372                 // Return it
2373                 return $isset;
2374         }
2375
2376
2377         /**
2378          * Determines if a group is set in the generic array
2379          *
2380          * @param       $keyGroup       Main group
2381          * @param       $subGroup       Sub group
2382          * @return      $isset          Whether the given group is set
2383          */
2384         protected final function isGenericArrayGroupSet ($keyGroup, $subGroup) {
2385                 // Debug message
2386                 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup);
2387
2388                 // Is it there?
2389                 $isset = isset($this->genericArray[$keyGroup][$subGroup]);
2390
2391                 // Return it
2392                 return $isset;
2393         }
2394
2395         /**
2396          * Getter for sub key group
2397          *
2398          * @param       $keyGroup       Main key group
2399          * @param       $subGroup       Sub key group
2400          * @return      $array          An array with all array elements
2401          */
2402         protected final function getGenericSubArray ($keyGroup, $subGroup) {
2403                 // Is it there?
2404                 if (!$this->isGenericArrayGroupSet($keyGroup, $subGroup)) {
2405                         // No, then abort here
2406                         trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' not found.');
2407                         exit;
2408                 } // END - if
2409
2410                 // Debug message
2411                 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',value=' . print_r($this->genericArray[$keyGroup][$subGroup], TRUE));
2412
2413                 // Return it
2414                 return $this->genericArray[$keyGroup][$subGroup];
2415         }
2416
2417         /**
2418          * Unsets a given key in generic array
2419          *
2420          * @param       $keyGroup       Main group for the key
2421          * @param       $subGroup       Sub group for the key
2422          * @param       $key            Key to unset
2423          * @return      void
2424          */
2425         protected final function unsetGenericArrayKey ($keyGroup, $subGroup, $key) {
2426                 // Debug message
2427                 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
2428
2429                 // Remove it
2430                 unset($this->genericArray[$keyGroup][$subGroup][$key]);
2431         }
2432
2433         /**
2434          * Unsets a given element in generic array
2435          *
2436          * @param       $keyGroup       Main group for the key
2437          * @param       $subGroup       Sub group for the key
2438          * @param       $key            Key to unset
2439          * @param       $element        Element to unset
2440          * @return      void
2441          */
2442         protected final function unsetGenericArrayElement ($keyGroup, $subGroup, $key, $element) {
2443                 // Debug message
2444                 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element);
2445
2446                 // Remove it
2447                 unset($this->genericArray[$keyGroup][$subGroup][$key][$element]);
2448         }
2449
2450         /**
2451          * Append a string to a given generic array key
2452          *
2453          * @param       $keyGroup       Main group for the key
2454          * @param       $subGroup       Sub group for the key
2455          * @param       $key            Key to unset
2456          * @param       $value          Value to add/append
2457          * @return      void
2458          */
2459         protected final function appendStringToGenericArrayKey ($keyGroup, $subGroup, $key, $value, $appendGlue = '') {
2460                 // Debug message
2461                 //* 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);
2462
2463                 // Is it already there?
2464                 if ($this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
2465                         // Append it
2466                         $this->genericArray[$keyGroup][$subGroup][$key] .= $appendGlue . (string) $value;
2467                 } else {
2468                         // Add it
2469                         $this->genericArray[$keyGroup][$subGroup][$key] = (string) $value;
2470                 }
2471         }
2472
2473         /**
2474          * Append a string to a given generic array element
2475          *
2476          * @param       $keyGroup       Main group for the key
2477          * @param       $subGroup       Sub group for the key
2478          * @param       $key            Key to unset
2479          * @param       $element        Element to check
2480          * @param       $value          Value to add/append
2481          * @return      void
2482          */
2483         protected final function appendStringToGenericArrayElement ($keyGroup, $subGroup, $key, $element, $value, $appendGlue = '') {
2484                 // Debug message
2485                 //* 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);
2486
2487                 // Is it already there?
2488                 if ($this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element)) {
2489                         // Append it
2490                         $this->genericArray[$keyGroup][$subGroup][$key][$element] .= $appendGlue . (string) $value;
2491                 } else {
2492                         // Add it
2493                         $this->genericArray[$keyGroup][$subGroup][$key][$element] = (string) $value;
2494                 }
2495         }
2496
2497         /**
2498          * Initializes given generic array group
2499          *
2500          * @param       $keyGroup       Main group for the key
2501          * @param       $subGroup       Sub group for the key
2502          * @param       $key            Key to use
2503          * @param       $forceInit      Optionally force initialization
2504          * @return      void
2505          */
2506         protected final function initGenericArrayGroup ($keyGroup, $subGroup, $forceInit = FALSE) {
2507                 // Debug message
2508                 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',forceInit=' . intval($forceInit));
2509
2510                 // Is it already set?
2511                 if (($forceInit === FALSE) && ($this->isGenericArrayGroupSet($keyGroup, $subGroup))) {
2512                         // Already initialized
2513                         trigger_error(__METHOD__ . ':keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' already initialized.');
2514                         exit;
2515                 } // END - if
2516
2517                 // Initialize it
2518                 $this->genericArray[$keyGroup][$subGroup] = array();
2519         }
2520
2521         /**
2522          * Initializes given generic array key
2523          *
2524          * @param       $keyGroup       Main group for the key
2525          * @param       $subGroup       Sub group for the key
2526          * @param       $key            Key to use
2527          * @param       $forceInit      Optionally force initialization
2528          * @return      void
2529          */
2530         protected final function initGenericArrayKey ($keyGroup, $subGroup, $key, $forceInit = FALSE) {
2531                 // Debug message
2532                 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',forceInit=' . intval($forceInit));
2533
2534                 // Is it already set?
2535                 if (($forceInit === FALSE) && ($this->isGenericArrayKeySet($keyGroup, $subGroup, $key))) {
2536                         // Already initialized
2537                         trigger_error(__METHOD__ . ':keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' already initialized.');
2538                         exit;
2539                 } // END - if
2540
2541                 // Initialize it
2542                 $this->genericArray[$keyGroup][$subGroup][$key] = array();
2543         }
2544
2545         /**
2546          * Initializes given generic array element
2547          *
2548          * @param       $keyGroup       Main group for the key
2549          * @param       $subGroup       Sub group for the key
2550          * @param       $key            Key to use
2551          * @param       $element        Element to use
2552          * @param       $forceInit      Optionally force initialization
2553          * @return      void
2554          */
2555         protected final function initGenericArrayElement ($keyGroup, $subGroup, $key, $element, $forceInit = FALSE) {
2556                 // Debug message
2557                 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element . ',forceInit=' . intval($forceInit));
2558
2559                 // Is it already set?
2560                 if (($forceInit === FALSE) && ($this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element))) {
2561                         // Already initialized
2562                         trigger_error(__METHOD__ . ':keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element . ' already initialized.');
2563                         exit;
2564                 } // END - if
2565
2566                 // Initialize it
2567                 $this->genericArray[$keyGroup][$subGroup][$key][$element] = array();
2568         }
2569
2570         /**
2571          * Pushes an element to a generic key
2572          *
2573          * @param       $keyGroup       Main group for the key
2574          * @param       $subGroup       Sub group for the key
2575          * @param       $key            Key to use
2576          * @param       $value          Value to add/append
2577          * @return      $count          Number of array elements
2578          */
2579         protected final function pushValueToGenericArrayKey ($keyGroup, $subGroup, $key, $value) {
2580                 // Debug message
2581                 //* NOISY-DEBUG: */ if (!is_object($value)) $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',value[' . gettype($value) . ']=' . print_r($value, TRUE));
2582
2583                 // Is it set?
2584                 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
2585                         // Initialize array
2586                         $this->initGenericArrayKey($keyGroup, $subGroup, $key);
2587                 } // END - if
2588
2589                 // Then push it
2590                 $count = array_push($this->genericArray[$keyGroup][$subGroup][$key], $value);
2591
2592                 // Return count
2593                 //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], TRUE));
2594                 //* DEBUG: */ print(__METHOD__ . ': count=' . $count . PHP_EOL);
2595                 return $count;
2596         }
2597
2598         /**
2599          * Pushes an element to a generic array element
2600          *
2601          * @param       $keyGroup       Main group for the key
2602          * @param       $subGroup       Sub group for the key
2603          * @param       $key            Key to use
2604          * @param       $element        Element to check
2605          * @param       $value          Value to add/append
2606          * @return      $count          Number of array elements
2607          */
2608         protected final function pushValueToGenericArrayElement ($keyGroup, $subGroup, $key, $element, $value) {
2609                 // Debug message
2610                 //* 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));
2611
2612                 // Is it set?
2613                 if (!$this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element)) {
2614                         // Initialize array
2615                         $this->initGenericArrayElement($keyGroup, $subGroup, $key, $element);
2616                 } // END - if
2617
2618                 // Then push it
2619                 $count = array_push($this->genericArray[$keyGroup][$subGroup][$key][$element], $value);
2620
2621                 // Return count
2622                 //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], TRUE));
2623                 //* DEBUG: */ print(__METHOD__ . ': count=' . $count . PHP_EOL);
2624                 return $count;
2625         }
2626
2627         /**
2628          * Pops an element from  a generic group
2629          *
2630          * @param       $keyGroup       Main group for the key
2631          * @param       $subGroup       Sub group for the key
2632          * @param       $key            Key to unset
2633          * @return      $value          Last "popped" value
2634          */
2635         protected final function popGenericArrayElement ($keyGroup, $subGroup, $key) {
2636                 // Debug message
2637                 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
2638
2639                 // Is it set?
2640                 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
2641                         // Not found
2642                         trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' not found.');
2643                         exit;
2644                 } // END - if
2645
2646                 // Then "pop" it
2647                 $value = array_pop($this->genericArray[$keyGroup][$subGroup][$key]);
2648
2649                 // Return value
2650                 //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], TRUE));
2651                 //* DEBUG: */ print(__METHOD__ . ': value[' . gettype($value) . ']=' . print_r($value, TRUE) . PHP_EOL);
2652                 return $value;
2653         }
2654
2655         /**
2656          * Shifts an element from  a generic group
2657          *
2658          * @param       $keyGroup       Main group for the key
2659          * @param       $subGroup       Sub group for the key
2660          * @param       $key            Key to unset
2661          * @return      $value          Last "popped" value
2662          */
2663         protected final function shiftGenericArrayElement ($keyGroup, $subGroup, $key) {
2664                 // Debug message
2665                 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
2666
2667                 // Is it set?
2668                 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
2669                         // Not found
2670                         trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' not found.');
2671                         exit;
2672                 } // END - if
2673
2674                 // Then "shift" it
2675                 $value = array_shift($this->genericArray[$keyGroup][$subGroup][$key]);
2676
2677                 // Return value
2678                 //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], TRUE));
2679                 //* DEBUG: */ print(__METHOD__ . ': value[' . gettype($value) . ']=' . print_r($value, TRUE) . PHP_EOL);
2680                 return $value;
2681         }
2682
2683         /**
2684          * Count generic array group
2685          *
2686          * @param       $keyGroup       Main group for the key
2687          * @return      $count          Count of given group
2688          */
2689         protected final function countGenericArray ($keyGroup) {
2690                 // Debug message
2691                 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup);
2692
2693                 // Is it there?
2694                 if (!isset($this->genericArray[$keyGroup])) {
2695                         // Abort here
2696                         trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ' not found.');
2697                         exit;
2698                 } // END - if
2699
2700                 // Then count it
2701                 $count = count($this->genericArray[$keyGroup]);
2702
2703                 // Debug message
2704                 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',count=' . $count);
2705
2706                 // Return it
2707                 return $count;
2708         }
2709
2710         /**
2711          * Count generic array sub group
2712          *
2713          * @param       $keyGroup       Main group for the key
2714          * @param       $subGroup       Sub group for the key
2715          * @return      $count          Count of given group
2716          */
2717         protected final function countGenericArrayGroup ($keyGroup, $subGroup) {
2718                 // Debug message
2719                 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup);
2720
2721                 // Is it there?
2722                 if (!$this->isGenericArrayGroupSet($keyGroup, $subGroup)) {
2723                         // Abort here
2724                         trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' not found.');
2725                         exit;
2726                 } // END - if
2727
2728                 // Then count it
2729                 $count = count($this->genericArray[$keyGroup][$subGroup]);
2730
2731                 // Debug message
2732                 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',count=' . $count);
2733
2734                 // Return it
2735                 return $count;
2736         }
2737
2738         /**
2739          * Count generic array elements
2740          *
2741          * @param       $keyGroup       Main group for the key
2742          * @param       $subGroup       Sub group for the key
2743          * @para        $key            Key to count
2744          * @return      $count          Count of given key
2745          */
2746         protected final function countGenericArrayElements ($keyGroup, $subGroup, $key) {
2747                 // Debug message
2748                 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
2749
2750                 // Is it there?
2751                 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
2752                         // Abort here
2753                         trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' not found.');
2754                         exit;
2755                 } elseif (!$this->isValidGenericArrayGroup($keyGroup, $subGroup)) {
2756                         // Not valid
2757                         trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' is not an array.');
2758                         exit;
2759                 }
2760
2761                 // Then count it
2762                 $count = count($this->genericArray[$keyGroup][$subGroup][$key]);
2763
2764                 // Debug message
2765                 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',count=' . $count);
2766
2767                 // Return it
2768                 return $count;
2769         }
2770
2771         /**
2772          * Getter for whole generic group array
2773          *
2774          * @param       $keyGroup       Key group to get
2775          * @return      $array          Whole generic array group
2776          */
2777         protected final function getGenericArray ($keyGroup) {
2778                 // Debug message
2779                 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup);
2780
2781                 // Is it there?
2782                 if (!isset($this->genericArray[$keyGroup])) {
2783                         // Then abort here
2784                         trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ' does not exist.');
2785                         exit;
2786                 } // END - if
2787
2788                 // Return it
2789                 return $this->genericArray[$keyGroup];
2790         }
2791
2792         /**
2793          * Setter for generic array key
2794          *
2795          * @param       $keyGroup       Key group to get
2796          * @param       $subGroup       Sub group for the key
2797          * @param       $key            Key to unset
2798          * @param       $value          Mixed value from generic array element
2799          * @return      void
2800          */
2801         protected final function setGenericArrayKey ($keyGroup, $subGroup, $key, $value) {
2802                 // Debug message
2803                 //* NOISY-DEBUG: */ if (!is_object($value)) $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',value[' . gettype($value) . ']=' . print_r($value, TRUE));
2804
2805                 // Set value here
2806                 $this->genericArray[$keyGroup][$subGroup][$key] = $value;
2807         }
2808
2809         /**
2810          * Getter for generic array key
2811          *
2812          * @param       $keyGroup       Key group to get
2813          * @param       $subGroup       Sub group for the key
2814          * @param       $key            Key to unset
2815          * @return      $value          Mixed value from generic array element
2816          */
2817         protected final function getGenericArrayKey ($keyGroup, $subGroup, $key) {
2818                 // Debug message
2819                 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
2820
2821                 // Is it there?
2822                 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
2823                         // Then abort here
2824                         trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' does not exist.');
2825                         exit;
2826                 } // END - if
2827
2828                 // Return it
2829                 return $this->genericArray[$keyGroup][$subGroup][$key];
2830         }
2831
2832         /**
2833          * Sets a value in given generic array key/element
2834          *
2835          * @param       $keyGroup       Main group for the key
2836          * @param       $subGroup       Sub group for the key
2837          * @param       $key            Key to set
2838          * @param       $element        Element to set
2839          * @param       $value          Value to set
2840          * @return      void
2841          */
2842         protected final function setGenericArrayElement ($keyGroup, $subGroup, $key, $element, $value) {
2843                 // Debug message
2844                 //* 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));
2845
2846                 // Then set it
2847                 $this->genericArray[$keyGroup][$subGroup][$key][$element] = $value;
2848         }
2849
2850         /**
2851          * Getter for generic array element
2852          *
2853          * @param       $keyGroup       Key group to get
2854          * @param       $subGroup       Sub group for the key
2855          * @param       $key            Key to look for
2856          * @param       $element        Element to look for
2857          * @return      $value          Mixed value from generic array element
2858          */
2859         protected final function getGenericArrayElement ($keyGroup, $subGroup, $key, $element) {
2860                 // Debug message
2861                 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element);
2862
2863                 // Is it there?
2864                 if (!$this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element)) {
2865                         // Then abort here
2866                         trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element . ' does not exist.');
2867                         exit;
2868                 } // END - if
2869
2870                 // Return it
2871                 return $this->genericArray[$keyGroup][$subGroup][$key][$element];
2872         }
2873
2874         /**
2875          * Checks if a given sub group is valid (array)
2876          *
2877          * @param       $keyGroup       Key group to get
2878          * @param       $subGroup       Sub group for the key
2879          * @return      $isValid        Whether given sub group is valid
2880          */
2881         protected final function isValidGenericArrayGroup ($keyGroup, $subGroup) {
2882                 // Debug message
2883                 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup);
2884
2885                 // Determine it
2886                 $isValid = (($this->isGenericArrayGroupSet($keyGroup, $subGroup)) && (is_array($this->getGenericSubArray($keyGroup, $subGroup))));
2887
2888                 // Return it
2889                 return $isValid;
2890         }
2891
2892         /**
2893          * Checks if a given key is valid (array)
2894          *
2895          * @param       $keyGroup       Key group to get
2896          * @param       $subGroup       Sub group for the key
2897          * @param       $key            Key to check
2898          * @return      $isValid        Whether given sub group is valid
2899          */
2900         protected final function isValidGenericArrayKey ($keyGroup, $subGroup, $key) {
2901                 // Debug message
2902                 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
2903
2904                 // Determine it
2905                 $isValid = (($this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) && (is_array($this->getGenericArrayKey($keyGroup, $subGroup, $key))));
2906
2907                 // Return it
2908                 return $isValid;
2909         }
2910
2911         /**
2912          * Translates boolean TRUE to 'Y' and FALSE to 'N'
2913          *
2914          * @param       $boolean                Boolean value
2915          * @return      $translated             Translated boolean value
2916          */
2917         public static final function translateBooleanToYesNo ($boolean) {
2918                 // Make sure it is really boolean
2919                 assert(is_bool($boolean));
2920
2921                 // "Translate" it
2922                 $translated = ($boolean === TRUE) ? 'Y' : 'N';
2923
2924                 // ... and return it
2925                 return $translated;
2926         }
2927 }
2928
2929 // [EOF]
2930 ?>