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