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