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