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