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