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