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