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