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