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