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