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