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