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