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