3 * The simulator system class is the super class of all other classes. This
4 * class handles saving of games etc.
6 * @author Roland Haeder <webmaster@shipsimu.org>
8 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2013 Core Developer Team
9 * @license GNU GPL 3.0 or any newer version
10 * @link http://www.shipsimu.org
12 * This program is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation, either version 3 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
27 * Length of output from hash()
29 private static $hashLength = NULL;
34 private $realClass = 'BaseFrameworkSystem';
37 * Instance of a request class
39 private $requestInstance = NULL;
42 * Instance of a response class
44 private $responseInstance = NULL;
47 * Search criteria instance
49 private $searchInstance = NULL;
52 * Update criteria instance
54 private $updateInstance = NULL;
57 * The file I/O instance for the template loader
59 private $fileIoInstance = NULL;
64 private $resolverInstance = NULL;
67 * Template engine instance
69 private $templateInstance = NULL;
72 * Database result instance
74 private $resultInstance = NULL;
77 * Instance for user class
79 private $userInstance = NULL;
82 * A controller instance
84 private $controllerInstance = NULL;
89 private $rngInstance = NULL;
92 * Instance of a crypto helper
94 private $cryptoInstance = NULL;
97 * Instance of an Iterator class
99 private $iteratorInstance = NULL;
102 * Instance of the list
104 private $listInstance = NULL;
109 private $menuInstance = NULL;
112 * Instance of the image
114 private $imageInstance = NULL;
117 * Instance of the stacker
119 private $stackInstance = NULL;
122 * A Compressor instance
124 private $compressorInstance = NULL;
127 * A Parseable instance
129 private $parserInstance = NULL;
132 * A ProtocolHandler instance
134 private $protocolInstance = NULL;
137 * A database wrapper instance
139 private $databaseInstance = NULL;
142 * A helper instance for the form
144 private $helperInstance = NULL;
147 * An instance of a Sourceable class
149 private $sourceInstance = NULL;
152 * An instance of a InputStream class
154 private $inputStreamInstance = NULL;
157 * An instance of a OutputStream class
159 private $outputStreamInstance = NULL;
162 * Networkable handler instance
164 private $handlerInstance = NULL;
167 * Visitor handler instance
169 private $visitorInstance = NULL;
174 private $dhtInstance = NULL;
177 * An instance of a database wrapper class
179 private $wrapperInstance = NULL;
182 * An instance of a file I/O pointer class (not handler)
184 private $pointerInstance = NULL;
187 * An instance of an Indexable class
189 private $indexInstance = NULL;
192 * An instance of a Block class
194 private $blockInstance = NULL;
199 private $minableInstance = NULL;
202 * Thousands separator
204 private $thousands = '.'; // German
209 private $decimals = ','; // German
214 private $socketResource = FALSE;
219 private $packageData = array();
224 private $genericArray = array();
226 /***********************
227 * Exception codes.... *
228 ***********************/
230 // @todo Try to clean these constants up
231 const EXCEPTION_IS_NULL_POINTER = 0x001;
232 const EXCEPTION_IS_NO_OBJECT = 0x002;
233 const EXCEPTION_IS_NO_ARRAY = 0x003;
234 const EXCEPTION_MISSING_METHOD = 0x004;
235 const EXCEPTION_CLASSES_NOT_MATCHING = 0x005;
236 const EXCEPTION_INDEX_OUT_OF_BOUNDS = 0x006;
237 const EXCEPTION_DIMENSION_ARRAY_INVALID = 0x007;
238 const EXCEPTION_ITEM_NOT_TRADEABLE = 0x008;
239 const EXCEPTION_ITEM_NOT_IN_PRICE_LIST = 0x009;
240 const EXCEPTION_GENDER_IS_WRONG = 0x00a;
241 const EXCEPTION_BIRTH_DATE_IS_INVALID = 0x00b;
242 const EXCEPTION_EMPTY_STRUCTURES_ARRAY = 0x00c;
243 const EXCEPTION_HAS_ALREADY_PERSONELL_LIST = 0x00d;
244 const EXCEPTION_NOT_ENOUGTH_UNEMPLOYEES = 0x00e;
245 const EXCEPTION_TOTAL_PRICE_NOT_CALCULATED = 0x00f;
246 const EXCEPTION_HARBOR_HAS_NO_SHIPYARDS = 0x010;
247 const EXCEPTION_CONTRACT_PARTNER_INVALID = 0x011;
248 const EXCEPTION_CONTRACT_PARTNER_MISMATCH = 0x012;
249 const EXCEPTION_CONTRACT_ALREADY_SIGNED = 0x013;
250 const EXCEPTION_UNEXPECTED_EMPTY_STRING = 0x014;
251 const EXCEPTION_PATH_NOT_FOUND = 0x015;
252 const EXCEPTION_INVALID_PATH_NAME = 0x016;
253 const EXCEPTION_READ_PROTECED_PATH = 0x017;
254 const EXCEPTION_WRITE_PROTECED_PATH = 0x018;
255 const EXCEPTION_DIR_POINTER_INVALID = 0x019;
256 const EXCEPTION_FILE_POINTER_INVALID = 0x01a;
257 const EXCEPTION_INVALID_RESOURCE = 0x01b;
258 const EXCEPTION_UNEXPECTED_OBJECT = 0x01c;
259 const EXCEPTION_LIMIT_ELEMENT_IS_UNSUPPORTED = 0x01d;
260 const EXCEPTION_GETTER_IS_MISSING = 0x01e;
261 const EXCEPTION_ARRAY_EXPECTED = 0x01f;
262 const EXCEPTION_ARRAY_HAS_INVALID_COUNT = 0x020;
263 const EXCEPTION_ID_IS_INVALID_FORMAT = 0x021;
264 const EXCEPTION_MD5_CHECKSUMS_MISMATCH = 0x022;
265 const EXCEPTION_UNEXPECTED_STRING_SIZE = 0x023;
266 const EXCEPTION_SIMULATOR_ID_INVALID = 0x024;
267 const EXCEPTION_MISMATCHING_COMPRESSORS = 0x025;
268 const EXCEPTION_CONTAINER_ITEM_IS_NULL = 0x026;
269 const EXCEPTION_ITEM_IS_NO_ARRAY = 0x027;
270 const EXCEPTION_CONTAINER_MAYBE_DAMAGED = 0x028;
271 const EXCEPTION_INVALID_STRING = 0x029;
272 const EXCEPTION_VARIABLE_NOT_SET = 0x02a;
273 const EXCEPTION_ATTRIBUTES_ARE_MISSING = 0x02b;
274 const EXCEPTION_ARRAY_ELEMENTS_MISSING = 0x02c;
275 const EXCEPTION_TEMPLATE_ENGINE_UNSUPPORTED = 0x02d;
276 const EXCEPTION_UNSPPORTED_OPERATION = 0x02e;
277 const EXCEPTION_FACTORY_REQUIRE_PARAMETER = 0x02f;
278 const EXCEPTION_MISSING_ELEMENT = 0x030;
279 const EXCEPTION_HEADERS_ALREADY_SENT = 0x031;
280 const EXCEPTION_DEFAULT_CONTROLLER_GONE = 0x032;
281 const EXCEPTION_CLASS_NOT_FOUND = 0x033;
282 const EXCEPTION_REQUIRED_INTERFACE_MISSING = 0x034;
283 const EXCEPTION_FATAL_ERROR = 0x035;
284 const EXCEPTION_FILE_NOT_FOUND = 0x036;
285 const EXCEPTION_ASSERTION_FAILED = 0x037;
286 const EXCEPTION_FILE_CANNOT_BE_READ = 0x038;
287 const EXCEPTION_DATABASE_UPDATED_NOT_ALLOWED = 0x039;
288 const EXCEPTION_FILTER_CHAIN_INTERCEPTED = 0x03a;
291 * Hexadecimal->Decimal translation array
293 private static $hexdec = array(
313 * Decimal->hexadecimal translation array
315 private static $dechex = array(
335 * Startup time in miliseconds
337 private static $startupTime = 0;
340 * Protected super constructor
342 * @param $className Name of the class
345 protected function __construct ($className) {
347 $this->setRealClass($className);
349 // Set configuration instance if no registry ...
350 if (!$this instanceof Register) {
351 // ... because registries doesn't need to be configured
352 $this->setConfigInstance(FrameworkConfiguration::getSelfInstance());
355 // Is the startup time set? (0 cannot be TRUE anymore)
356 if (self::$startupTime == 0) {
358 self::$startupTime = microtime(TRUE);
363 * Destructor for all classes
367 public function __destruct () {
368 // Flush any updated entries to the database
369 $this->flushPendingUpdates();
371 // Is this object already destroyed?
372 if ($this->__toString() != 'DestructedObject') {
373 // Destroy all informations about this class but keep some text about it alive
374 $this->setRealClass('DestructedObject');
375 } elseif ((defined('DEBUG_DESTRUCTOR')) && (is_object($this->getDebugInstance()))) {
376 // Already destructed object
377 self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:] The object <span class="object_name">%s</span> is already destroyed.',
382 // Do not call this twice
383 trigger_error(__METHOD__ . ': Called twice.');
389 * The __call() method where all non-implemented methods end up
391 * @param $methodName Name of the missing method
392 * @args $args Arguments passed to the method
395 public final function __call ($methodName, $args) {
396 return self::__callStatic($methodName, $args);
400 * The __callStatic() method where all non-implemented static methods end up
402 * @param $methodName Name of the missing method
403 * @args $args Arguments passed to the method
406 public static final function __callStatic ($methodName, $args) {
407 // Init argument string
410 // Is it empty or an array?
413 $argsString = 'NULL';
414 } elseif (is_array($args)) {
415 // Some arguments are there
416 foreach ($args as $arg) {
417 // Add the value itself if not array. This prevents 'array to string conversion' message
418 if (is_array($arg)) {
419 $argsString .= 'Array';
424 // Add data about the argument
425 $argsString .= ' (' . gettype($arg);
427 if (is_string($arg)) {
428 // Add length for strings
429 $argsString .= ', ' . strlen($arg);
430 } elseif (is_array($arg)) {
431 // .. or size if array
432 $argsString .= ', ' . count($arg);
433 } elseif ($arg === TRUE) {
434 // ... is boolean 'TRUE'
435 $argsString .= ', TRUE';
436 } elseif ($arg === FALSE) {
437 // ... is boolean 'FALSE'
438 $argsString .= ', FALSE';
442 $argsString .= '), ';
446 if (substr($argsString, -2, 1) == ',') {
447 $argsString = substr($argsString, 0, -2);
450 // Invalid arguments!
451 $argsString = '!INVALID:' . gettype($args) . '!';
454 // Output stub message
455 // @TODO __CLASS__ does always return BaseFrameworkSystem but not the extending (=child) class
456 self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[unknown::%s:] Stub! Args: %s',
466 * Getter for $realClass
468 * @return $realClass The name of the real class (not BaseFrameworkSystem)
470 public function __toString () {
471 return $this->realClass;
475 * Magic function to catch setting of missing but set class fields/attributes
477 * @param $name Name of the field/attribute
478 * @param $value Value to store
481 public final function __set ($name, $value) {
482 $this->debugBackTrace(sprintf('Tried to set a missing field. name=%s, value[%s]=%s',
485 print_r($value, TRUE)
490 * Magic function to catch getting of missing fields/attributes
492 * @param $name Name of the field/attribute
495 public final function __get ($name) {
496 $this->debugBackTrace(sprintf('Tried to get a missing field. name=%s',
502 * Magic function to catch unsetting of missing fields/attributes
504 * @param $name Name of the field/attribute
507 public final function __unset ($name) {
508 $this->debugBackTrace(sprintf('Tried to unset a missing field. name=%s',
514 * Setter for the real class name
516 * @param $realClass Class name (string)
519 public final function setRealClass ($realClass) {
521 $this->realClass = (string) $realClass;
525 * Setter for database result instance
527 * @param $resultInstance An instance of a database result class
529 * @todo SearchableResult and UpdateableResult shall have a super interface to use here
531 protected final function setResultInstance (SearchableResult $resultInstance) {
532 $this->resultInstance = $resultInstance;
536 * Getter for database result instance
538 * @return $resultInstance An instance of a database result class
540 public final function getResultInstance () {
541 return $this->resultInstance;
545 * Setter for template engine instances
547 * @param $templateInstance An instance of a template engine class
550 protected final function setTemplateInstance (CompileableTemplate $templateInstance) {
551 $this->templateInstance = $templateInstance;
555 * Getter for template engine instances
557 * @return $templateInstance An instance of a template engine class
559 protected final function getTemplateInstance () {
560 return $this->templateInstance;
564 * Setter for search instance
566 * @param $searchInstance Searchable criteria instance
569 public final function setSearchInstance (LocalSearchCriteria $searchInstance) {
570 $this->searchInstance = $searchInstance;
574 * Getter for search instance
576 * @return $searchInstance Searchable criteria instance
578 public final function getSearchInstance () {
579 return $this->searchInstance;
583 * Setter for update instance
585 * @param $updateInstance Searchable criteria instance
588 public final function setUpdateInstance (LocalUpdateCriteria $updateInstance) {
589 $this->updateInstance = $updateInstance;
593 * Getter for update instance
595 * @return $updateInstance Updateable criteria instance
597 public final function getUpdateInstance () {
598 return $this->updateInstance;
602 * Setter for resolver instance
604 * @param $resolverInstance Instance of a command resolver class
607 public final function setResolverInstance (Resolver $resolverInstance) {
608 $this->resolverInstance = $resolverInstance;
612 * Getter for resolver instance
614 * @return $resolverInstance Instance of a command resolver class
616 public final function getResolverInstance () {
617 return $this->resolverInstance;
621 * Setter for language instance
623 * @param $configInstance The configuration instance which shall
624 * be FrameworkConfiguration
627 public final function setConfigInstance (FrameworkConfiguration $configInstance) {
628 Registry::getRegistry()->addInstance('config', $configInstance);
632 * Getter for configuration instance
634 * @return $configInstance Configuration instance
636 public final function getConfigInstance () {
637 $configInstance = Registry::getRegistry()->getInstance('config');
638 return $configInstance;
642 * Setter for debug instance
644 * @param $debugInstance The instance for debug output class
647 public final function setDebugInstance (DebugMiddleware $debugInstance) {
648 Registry::getRegistry()->addInstance('debug', $debugInstance);
652 * Getter for debug instance
654 * @return $debugInstance Instance to class DebugConsoleOutput or DebugWebOutput
656 public final function getDebugInstance () {
657 // Get debug instance
658 $debugInstance = Registry::getRegistry()->getInstance('debug');
661 return $debugInstance;
665 * Setter for web output instance
667 * @param $webInstance The instance for web output class
670 public final function setWebOutputInstance (OutputStreamer $webInstance) {
671 Registry::getRegistry()->addInstance('web_output', $webInstance);
675 * Getter for web output instance
677 * @return $webOutputInstance - Instance to class WebOutput
679 public final function getWebOutputInstance () {
680 $webOutputInstance = Registry::getRegistry()->getInstance('web_output');
681 return $webOutputInstance;
685 * Setter for database instance
687 * @param $databaseInstance The instance for the database connection (forced DatabaseConnection)
690 public final function setDatabaseInstance (DatabaseConnection $databaseInstance) {
691 Registry::getRegistry()->addInstance('db_instance', $databaseInstance);
695 * Getter for database layer
697 * @return $databaseInstance The database layer instance
699 public final function getDatabaseInstance () {
701 $databaseInstance = Registry::getRegistry()->getInstance('db_instance');
704 return $databaseInstance;
708 * Setter for compressor channel
710 * @param $compressorInstance An instance of CompressorChannel
713 public final function setCompressorChannel (CompressorChannel $compressorInstance) {
714 Registry::getRegistry()->addInstance('compressor', $compressorInstance);
718 * Getter for compressor channel
720 * @return $compressorInstance The compressor channel
722 public final function getCompressorChannel () {
723 $compressorInstance = Registry::getRegistry()->getInstance('compressor');
724 return $compressorInstance;
728 * Protected getter for a manageable application helper class
730 * @return $applicationInstance An instance of a manageable application helper class
732 protected final function getApplicationInstance () {
733 $applicationInstance = Registry::getRegistry()->getInstance('application');
734 return $applicationInstance;
738 * Setter for a manageable application helper class
740 * @param $applicationInstance An instance of a manageable application helper class
743 public final function setApplicationInstance (ManageableApplication $applicationInstance) {
744 Registry::getRegistry()->addInstance('application', $applicationInstance);
748 * Setter for request instance
750 * @param $requestInstance An instance of a Requestable class
753 public final function setRequestInstance (Requestable $requestInstance) {
754 $this->requestInstance = $requestInstance;
758 * Getter for request instance
760 * @return $requestInstance An instance of a Requestable class
762 public final function getRequestInstance () {
763 return $this->requestInstance;
767 * Setter for response instance
769 * @param $responseInstance An instance of a Responseable class
772 public final function setResponseInstance (Responseable $responseInstance) {
773 $this->responseInstance = $responseInstance;
777 * Getter for response instance
779 * @return $responseInstance An instance of a Responseable class
781 public final function getResponseInstance () {
782 return $this->responseInstance;
786 * Private getter for language instance
788 * @return $langInstance An instance to the language sub-system
790 protected final function getLanguageInstance () {
791 $langInstance = Registry::getRegistry()->getInstance('language');
792 return $langInstance;
796 * Setter for language instance
798 * @param $langInstance An instance to the language sub-system
800 * @see LanguageSystem
802 public final function setLanguageInstance (ManageableLanguage $langInstance) {
803 Registry::getRegistry()->addInstance('language', $langInstance);
807 * Private getter for file IO instance
809 * @return $fileIoInstance An instance to the file I/O sub-system
811 protected final function getFileIoInstance () {
812 return $this->fileIoInstance;
816 * Setter for file I/O instance
818 * @param $fileIoInstance An instance to the file I/O sub-system
821 public final function setFileIoInstance (IoHandler $fileIoInstance) {
822 $this->fileIoInstance = $fileIoInstance;
826 * Protected setter for user instance
828 * @param $userInstance An instance of a user class
831 protected final function setUserInstance (ManageableAccount $userInstance) {
832 $this->userInstance = $userInstance;
836 * Getter for user instance
838 * @return $userInstance An instance of a user class
840 public final function getUserInstance () {
841 return $this->userInstance;
845 * Setter for controller instance (this surely breaks a bit the MVC patterm)
847 * @param $controllerInstance An instance of the controller
850 public final function setControllerInstance (Controller $controllerInstance) {
851 $this->controllerInstance = $controllerInstance;
855 * Getter for controller instance (this surely breaks a bit the MVC patterm)
857 * @return $controllerInstance An instance of the controller
859 public final function getControllerInstance () {
860 return $this->controllerInstance;
864 * Setter for RNG instance
866 * @param $rngInstance An instance of a random number generator (RNG)
869 protected final function setRngInstance (RandomNumberGenerator $rngInstance) {
870 $this->rngInstance = $rngInstance;
874 * Getter for RNG instance
876 * @return $rngInstance An instance of a random number generator (RNG)
878 public final function getRngInstance () {
879 return $this->rngInstance;
883 * Setter for Cryptable instance
885 * @param $cryptoInstance An instance of a Cryptable class
888 protected final function setCryptoInstance (Cryptable $cryptoInstance) {
889 $this->cryptoInstance = $cryptoInstance;
893 * Getter for Cryptable instance
895 * @return $cryptoInstance An instance of a Cryptable class
897 public final function getCryptoInstance () {
898 return $this->cryptoInstance;
902 * Setter for the list instance
904 * @param $listInstance A list of Listable
907 protected final function setListInstance (Listable $listInstance) {
908 $this->listInstance = $listInstance;
912 * Getter for the list instance
914 * @return $listInstance A list of Listable
916 protected final function getListInstance () {
917 return $this->listInstance;
921 * Setter for the menu instance
923 * @param $menuInstance A RenderableMenu instance
926 protected final function setMenuInstance (RenderableMenu $menuInstance) {
927 $this->menuInstance = $menuInstance;
931 * Getter for the menu instance
933 * @return $menuInstance A RenderableMenu instance
935 protected final function getMenuInstance () {
936 return $this->menuInstance;
940 * Setter for image instance
942 * @param $imageInstance An instance of an image
945 public final function setImageInstance (BaseImage $imageInstance) {
946 $this->imageInstance = $imageInstance;
950 * Getter for image instance
952 * @return $imageInstance An instance of an image
954 public final function getImageInstance () {
955 return $this->imageInstance;
959 * Setter for stacker instance
961 * @param $stackInstance An instance of an stacker
964 public final function setStackInstance (Stackable $stackInstance) {
965 $this->stackInstance = $stackInstance;
969 * Getter for stacker instance
971 * @return $stackInstance An instance of an stacker
973 public final function getStackInstance () {
974 return $this->stackInstance;
978 * Setter for compressor instance
980 * @param $compressorInstance An instance of an compressor
983 public final function setCompressorInstance (Compressor $compressorInstance) {
984 $this->compressorInstance = $compressorInstance;
988 * Getter for compressor instance
990 * @return $compressorInstance An instance of an compressor
992 public final function getCompressorInstance () {
993 return $this->compressorInstance;
997 * Setter for Parseable instance
999 * @param $parserInstance An instance of an Parseable
1002 public final function setParserInstance (Parseable $parserInstance) {
1003 $this->parserInstance = $parserInstance;
1007 * Getter for Parseable instance
1009 * @return $parserInstance An instance of an Parseable
1011 public final function getParserInstance () {
1012 return $this->parserInstance;
1016 * Setter for ProtocolHandler instance
1018 * @param $protocolInstance An instance of an ProtocolHandler
1021 public final function setProtocolInstance (ProtocolHandler $protocolInstance = NULL) {
1022 $this->protocolInstance = $protocolInstance;
1026 * Getter for ProtocolHandler instance
1028 * @return $protocolInstance An instance of an ProtocolHandler
1030 public final function getProtocolInstance () {
1031 return $this->protocolInstance;
1035 * Setter for DatabaseWrapper instance
1037 * @param $wrapperInstance An instance of an DatabaseWrapper
1040 public final function setWrapperInstance (DatabaseWrapper $wrapperInstance) {
1041 $this->wrapperInstance = $wrapperInstance;
1045 * Getter for DatabaseWrapper instance
1047 * @return $wrapperInstance An instance of an DatabaseWrapper
1049 public final function getWrapperInstance () {
1050 return $this->wrapperInstance;
1054 * Setter for socket resource
1056 * @param $socketResource A valid socket resource
1059 public final function setSocketResource ($socketResource) {
1060 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput($this->__toString() . '::' . __FUNCTION__ . ': socketResource=' . $socketResource . ',previous[' . gettype($this->socketResource) . ']=' . $this->socketResource);
1061 $this->socketResource = $socketResource;
1065 * Getter for socket resource
1067 * @return $socketResource A valid socket resource
1069 public final function getSocketResource () {
1070 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput($this->__toString() . '::' . __FUNCTION__ . ': socketResource[' . gettype($this->socketResource) . ']=' . $this->socketResource);
1071 return $this->socketResource;
1075 * Setter for helper instance
1077 * @param $helperInstance An instance of a helper class
1080 protected final function setHelperInstance (Helper $helperInstance) {
1081 $this->helperInstance = $helperInstance;
1085 * Getter for helper instance
1087 * @return $helperInstance An instance of a helper class
1089 public final function getHelperInstance () {
1090 return $this->helperInstance;
1094 * Setter for a Sourceable instance
1096 * @param $sourceInstance The Sourceable instance
1099 protected final function setSourceInstance (Sourceable $sourceInstance) {
1100 $this->sourceInstance = $sourceInstance;
1104 * Getter for a Sourceable instance
1106 * @return $sourceInstance The Sourceable instance
1108 protected final function getSourceInstance () {
1109 return $this->sourceInstance;
1113 * Getter for a InputStream instance
1115 * @param $inputStreamInstance The InputStream instance
1117 protected final function getInputStreamInstance () {
1118 return $this->inputStreamInstance;
1122 * Setter for a InputStream instance
1124 * @param $inputStreamInstance The InputStream instance
1127 protected final function setInputStreamInstance (InputStream $inputStreamInstance) {
1128 $this->inputStreamInstance = $inputStreamInstance;
1132 * Getter for a OutputStream instance
1134 * @param $outputStreamInstance The OutputStream instance
1136 protected final function getOutputStreamInstance () {
1137 return $this->outputStreamInstance;
1141 * Setter for a OutputStream instance
1143 * @param $outputStreamInstance The OutputStream instance
1146 protected final function setOutputStreamInstance (OutputStream $outputStreamInstance) {
1147 $this->outputStreamInstance = $outputStreamInstance;
1151 * Setter for handler instance
1153 * @param $handlerInstance An instance of a Handleable class
1156 protected final function setHandlerInstance (Handleable $handlerInstance) {
1157 $this->handlerInstance = $handlerInstance;
1161 * Getter for handler instance
1163 * @return $handlerInstance A Networkable instance
1165 protected final function getHandlerInstance () {
1166 return $this->handlerInstance;
1170 * Setter for visitor instance
1172 * @param $visitorInstance A Visitor instance
1175 protected final function setVisitorInstance (Visitor $visitorInstance) {
1176 $this->visitorInstance = $visitorInstance;
1180 * Getter for visitor instance
1182 * @return $visitorInstance A Visitor instance
1184 protected final function getVisitorInstance () {
1185 return $this->visitorInstance;
1189 * Setter for DHT instance
1191 * @param $dhtInstance A Distributable instance
1194 protected final function setDhtInstance (Distributable $dhtInstance) {
1195 $this->dhtInstance = $dhtInstance;
1199 * Getter for DHT instance
1201 * @return $dhtInstance A Distributable instance
1203 protected final function getDhtInstance () {
1204 return $this->dhtInstance;
1208 * Setter for raw package Data
1210 * @param $packageData Raw package Data
1213 public final function setPackageData (array $packageData) {
1214 $this->packageData = $packageData;
1218 * Getter for raw package Data
1220 * @return $packageData Raw package Data
1222 public function getPackageData () {
1223 return $this->packageData;
1228 * Setter for Iterator instance
1230 * @param $iteratorInstance An instance of an Iterator
1233 protected final function setIteratorInstance (Iterator $iteratorInstance) {
1234 $this->iteratorInstance = $iteratorInstance;
1238 * Getter for Iterator instance
1240 * @return $iteratorInstance An instance of an Iterator
1242 public final function getIteratorInstance () {
1243 return $this->iteratorInstance;
1247 * Setter for InputOutputPointer instance
1249 * @param $pointerInstance An instance of an InputOutputPointer class
1252 protected final function setPointerInstance (InputOutputPointer $pointerInstance) {
1253 $this->pointerInstance = $pointerInstance;
1257 * Getter for InputOutputPointer instance
1259 * @return $pointerInstance An instance of an InputOutputPointer class
1261 public final function getPointerInstance () {
1262 return $this->pointerInstance;
1266 * Setter for Indexable instance
1268 * @param $indexInstance An instance of an Indexable class
1271 protected final function setIndexInstance (Indexable $indexInstance) {
1272 $this->indexInstance = $indexInstance;
1276 * Getter for Indexable instance
1278 * @return $indexInstance An instance of an Indexable class
1280 public final function getIndexInstance () {
1281 return $this->indexInstance;
1285 * Setter for Block instance
1287 * @param $blockInstance An instance of an Block class
1290 protected final function setBlockInstance (Block $blockInstance) {
1291 $this->blockInstance = $blockInstance;
1295 * Getter for Block instance
1297 * @return $blockInstance An instance of an Block class
1299 public final function getBlockInstance () {
1300 return $this->blockInstance;
1304 * Setter for Minable instance
1306 * @param $minableInstance A Minable instance
1309 protected final function setMinableInstance (Minable $minableInstance) {
1310 $this->minableInstance = $minableInstance;
1314 * Getter for minable instance
1316 * @return $minableInstance A Minable instance
1318 protected final function getMinableInstance () {
1319 return $this->minableInstance;
1323 * Checks whether an object equals this object. You should overwrite this
1324 * method to implement own equality checks
1326 * @param $objectInstance An instance of a FrameworkInterface object
1327 * @return $equals Whether both objects equals
1329 public function equals (FrameworkInterface $objectInstance) {
1332 $this->__toString() == $objectInstance->__toString()
1334 $this->hashCode() == $objectInstance->hashCode()
1337 // Return the result
1342 * Generates a generic hash code of this class. You should really overwrite
1343 * this method with your own hash code generator code. But keep KISS in mind.
1345 * @return $hashCode A generic hash code respresenting this whole class
1347 public function hashCode () {
1349 return crc32($this->__toString());
1353 * Formats computer generated price values into human-understandable formats
1354 * with thousand and decimal separators.
1356 * @param $value The in computer format value for a price
1357 * @param $currency The currency symbol (use HTML-valid characters!)
1358 * @param $decNum Number of decimals after commata
1359 * @return $price The for the current language formated price string
1360 * @throws MissingDecimalsThousandsSeparatorException If decimals or
1361 * thousands separator
1364 public function formatCurrency ($value, $currency = '€', $decNum = 2) {
1365 // Are all required attriutes set?
1366 if ((!isset($this->decimals)) || (!isset($this->thousands))) {
1367 // Throw an exception
1368 throw new MissingDecimalsThousandsSeparatorException($this, self::EXCEPTION_ATTRIBUTES_ARE_MISSING);
1372 $value = (float) $value;
1374 // Reformat the US number
1375 $price = number_format($value, $decNum, $this->decimals, $this->thousands) . $currency;
1377 // Return as string...
1382 * Appends a trailing slash to a string
1384 * @param $str A string (maybe) without trailing slash
1385 * @return $str A string with an auto-appended trailing slash
1387 public final function addMissingTrailingSlash ($str) {
1388 // Is there a trailing slash?
1389 if (substr($str, -1, 1) != '/') {
1393 // Return string with trailing slash
1398 * Prepare the template engine (WebTemplateEngine by default) for a given
1399 * application helper instance (ApplicationHelper by default).
1401 * @param $applicationInstance An application helper instance or
1402 * null if we shall use the default
1403 * @return $templateInstance The template engine instance
1404 * @throws NullPointerException If the discovered application
1405 * instance is still null
1407 protected function prepareTemplateInstance (ManageableApplication $applicationInstance = NULL) {
1408 // Is the application instance set?
1409 if (is_null($applicationInstance)) {
1410 // Get the current instance
1411 $applicationInstance = $this->getApplicationInstance();
1414 if (is_null($applicationInstance)) {
1415 // Thrown an exception
1416 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
1420 // Initialize the template engine
1421 $templateInstance = ObjectFactory::createObjectByConfiguredName('web_template_class');
1423 // Return the prepared instance
1424 return $templateInstance;
1428 * Debugs this instance by putting out it's full content
1430 * @param $message Optional message to show in debug output
1433 public final function debugInstance ($message = '') {
1434 // Restore the error handler to avoid trouble with missing array elements or undeclared variables
1435 restore_error_handler();
1440 // Is a message set?
1441 if (!empty($message)) {
1442 // Construct message
1443 $content = sprintf('<div class="debug_message">Message: %s</div>' . PHP_EOL, $message);
1446 // Generate the output
1447 $content .= sprintf('<pre>%s</pre>',
1450 print_r($this, TRUE)
1456 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>',
1457 $this->__toString(),
1459 ClassLoader::getSelfInstance()->getPrintableIncludeList()
1464 * Replaces control characters with printable output
1466 * @param $str String with control characters
1467 * @return $str Replaced string
1469 protected function replaceControlCharacters ($str) {
1472 chr(13), '[r]', str_replace(
1473 chr(10), '[n]', str_replace(
1483 * Output a partial stub message for the caller method
1485 * @param $message An optional message to display
1488 protected function partialStub ($message = '') {
1489 // Get the backtrace
1490 $backtrace = debug_backtrace();
1492 // Generate the class::method string
1493 $methodName = 'UnknownClass->unknownMethod';
1494 if ((isset($backtrace[1]['class'])) && (isset($backtrace[1]['function']))) {
1495 $methodName = $backtrace[1]['class'] . '->' . $backtrace[1]['function'];
1498 // Construct the full message
1499 $stubMessage = sprintf('[%s:] Partial stub!',
1503 // Is the extra message given?
1504 if (!empty($message)) {
1505 // Then add it as well
1506 $stubMessage .= ' Message: ' . $message;
1509 // Debug instance is there?
1510 if (!is_null($this->getDebugInstance())) {
1511 // Output stub message
1512 self::createDebugInstance(__CLASS__)->debugOutput($stubMessage);
1515 trigger_error($stubMessage);
1521 * Outputs a debug backtrace and stops further script execution
1523 * @param $message An optional message to output
1524 * @param $doExit Whether exit the program (TRUE is default)
1527 public function debugBackTrace ($message = '', $doExit = TRUE) {
1528 // Sorry, there is no other way getting this nice backtrace
1529 if (!empty($message)) {
1531 printf('Message: %s<br />' . chr(10), $message);
1535 debug_print_backtrace();
1539 if ($doExit === TRUE) {
1545 * Creates an instance of a debugger instance
1547 * @param $className Name of the class (currently unsupported)
1548 * @return $debugInstance An instance of a debugger class
1550 public final static function createDebugInstance ($className) {
1551 // Is the instance set?
1552 if (!Registry::getRegistry()->instanceExists('debug')) {
1553 // Init debug instance
1554 $debugInstance = NULL;
1558 // Get a debugger instance
1559 $debugInstance = DebugMiddleware::createDebugMiddleware(FrameworkConfiguration::getSelfInstance()->getConfigEntry('debug_class'));
1560 } catch (NullPointerException $e) {
1561 // Didn't work, no instance there
1562 exit('Cannot create debugInstance! Exception=' . $e->__toString() . ', message=' . $e->getMessage());
1565 // Empty string should be ignored and used for testing the middleware
1566 DebugMiddleware::getSelfInstance()->output('');
1568 // Set it in its own class. This will set it in the registry
1569 $debugInstance->setDebugInstance($debugInstance);
1571 // Get instance from registry
1572 $debugInstance = Registry::getRegistry()->getDebugInstance();
1576 return $debugInstance;
1580 * Simple output of a message with line-break
1582 * @param $message Message to output
1585 public function outputLine ($message) {
1587 print($message . PHP_EOL);
1591 * Outputs a debug message whether to debug instance (should be set!) or
1592 * dies with or ptints the message. Do NEVER EVER rewrite the exit() call to
1593 * ApplicationEntryPoint::app_exit(), this would cause an endless loop.
1595 * @param $message Message we shall send out...
1596 * @param $doPrint Whether print or die here (default: print)
1597 * @paran $stripTags Whether to strip tags (default: FALSE)
1600 public function debugOutput ($message, $doPrint = TRUE, $stripTags = FALSE) {
1601 // Set debug instance to NULL
1602 $debugInstance = NULL;
1606 // Get debug instance
1607 $debugInstance = $this->getDebugInstance();
1608 } catch (NullPointerException $e) {
1609 // The debug instance is not set (yet)
1612 // Is the debug instance there?
1613 if (is_object($debugInstance)) {
1614 // Use debug output handler
1615 $debugInstance->output($message, $stripTags);
1617 if ($doPrint === FALSE) {
1618 // Die here if not printed
1622 // Are debug times enabled?
1623 if ($this->getConfigInstance()->getConfigEntry('debug_output_timings') == 'Y') {
1625 $message = $this->getPrintableExecutionTime() . $message;
1629 if ($doPrint === TRUE) {
1631 $this->outputLine($message);
1640 * Converts e.g. a command from URL to a valid class by keeping out bad characters
1642 * @param $str The string, what ever it is needs to be converted
1643 * @return $className Generated class name
1645 public function convertToClassName ($str) {
1649 // Convert all dashes in underscores
1650 $str = $this->convertDashesToUnderscores($str);
1652 // Now use that underscores to get classname parts for hungarian style
1653 foreach (explode('_', $str) as $strPart) {
1654 // Make the class name part lower case and first upper case
1655 $className .= ucfirst(strtolower($strPart));
1658 // Return class name
1663 * Converts dashes to underscores, e.g. useable for configuration entries
1665 * @param $str The string with maybe dashes inside
1666 * @return $str The converted string with no dashed, but underscores
1668 public final function convertDashesToUnderscores ($str) {
1670 $str = str_replace('-', '_', $str);
1672 // Return converted string
1677 * Marks up the code by adding e.g. line numbers
1679 * @param $phpCode Unmarked PHP code
1680 * @return $markedCode Marked PHP code
1682 public function markupCode ($phpCode) {
1687 $errorArray = error_get_last();
1689 // Init the code with error message
1690 if (is_array($errorArray)) {
1692 $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>',
1693 basename($errorArray['file']),
1694 $errorArray['line'],
1695 $errorArray['message'],
1700 // Add line number to the code
1701 foreach (explode(chr(10), $phpCode) as $lineNo => $code) {
1703 $markedCode .= sprintf('<span id="code_line">%s</span>: %s' . chr(10),
1705 htmlentities($code, ENT_QUOTES)
1714 * Filter a given GMT timestamp (non Uni* stamp!) to make it look more
1715 * beatiful for web-based front-ends. If null is given a message id
1716 * null_timestamp will be resolved and returned.
1718 * @param $timestamp Timestamp to prepare (filter) for display
1719 * @return $readable A readable timestamp
1721 public function doFilterFormatTimestamp ($timestamp) {
1722 // Default value to return
1725 // Is the timestamp null?
1726 if (is_null($timestamp)) {
1727 // Get a message string
1728 $readable = $this->getLanguageInstance()->getMessage('null_timestamp');
1730 switch ($this->getLanguageInstance()->getLanguageCode()) {
1731 case 'de': // German format is a bit different to default
1732 // Split the GMT stamp up
1733 $dateTime = explode(' ', $timestamp );
1734 $dateArray = explode('-', $dateTime[0]);
1735 $timeArray = explode(':', $dateTime[1]);
1737 // Construct the timestamp
1738 $readable = sprintf($this->getConfigInstance()->getConfigEntry('german_date_time'),
1748 default: // Default is pass-through
1749 $readable = $timestamp;
1759 * Filter a given number into a localized number
1761 * @param $value The raw value from e.g. database
1762 * @return $localized Localized value
1764 public function doFilterFormatNumber ($value) {
1765 // Generate it from config and localize dependencies
1766 switch ($this->getLanguageInstance()->getLanguageCode()) {
1767 case 'de': // German format is a bit different to default
1768 $localized = number_format($value, $this->getConfigInstance()->getConfigEntry('decimals'), ',', '.');
1771 default: // US, etc.
1772 $localized = number_format($value, $this->getConfigInstance()->getConfigEntry('decimals'), '.', ',');
1781 * "Getter" for databse entry
1783 * @return $entry An array with database entries
1784 * @throws NullPointerException If the database result is not found
1785 * @throws InvalidDatabaseResultException If the database result is invalid
1787 protected final function getDatabaseEntry () {
1788 // Is there an instance?
1789 if (is_null($this->getResultInstance())) {
1790 // Throw an exception here
1791 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
1795 $this->getResultInstance()->rewind();
1797 // Do we have an entry?
1798 if ($this->getResultInstance()->valid() === FALSE) {
1799 throw new InvalidDatabaseResultException(array($this, $this->getResultInstance()), DatabaseResult::EXCEPTION_INVALID_DATABASE_RESULT);
1803 $this->getResultInstance()->next();
1806 $entry = $this->getResultInstance()->current();
1813 * Getter for field name
1815 * @param $fieldName Field name which we shall get
1816 * @return $fieldValue Field value from the user
1817 * @throws NullPointerException If the result instance is null
1819 public final function getField ($fieldName) {
1820 // Default field value
1823 // Get result instance
1824 $resultInstance = $this->getResultInstance();
1826 // Is this instance null?
1827 if (is_null($resultInstance)) {
1828 // Then the user instance is no longer valid (expired cookies?)
1829 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
1832 // Get current array
1833 $fieldArray = $resultInstance->current();
1834 //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput($fieldName.':<pre>'.print_r($fieldArray, TRUE).'</pre>');
1836 // Convert dashes to underscore
1837 $fieldName = $this->convertDashesToUnderscores($fieldName);
1839 // Does the field exist?
1840 if (isset($fieldArray[$fieldName])) {
1842 $fieldValue = $fieldArray[$fieldName];
1844 // Missing field entry, may require debugging
1845 self::createDebugInstance(__CLASS__)->debugOutput($this->__toString() . ':fieldname=' . $fieldName . ' not found!');
1853 * Flushs all pending updates to the database layer
1857 public function flushPendingUpdates () {
1858 // Get result instance
1859 $resultInstance = $this->getResultInstance();
1861 // Do we have data to update?
1862 if ((is_object($resultInstance)) && ($resultInstance->ifDataNeedsFlush())) {
1863 // Get wrapper class name config entry
1864 $configEntry = $resultInstance->getUpdateInstance()->getWrapperConfigEntry();
1866 // Create object instance
1867 $wrapperInstance = ObjectFactory::createObjectByConfiguredName($configEntry);
1869 // Yes, then send the whole result to the database layer
1870 $wrapperInstance->doUpdateByResult($this->getResultInstance());
1875 * Outputs a deprecation warning to the developer.
1877 * @param $message The message we shall output to the developer
1879 * @todo Write a logging mechanism for productive mode
1881 public function deprecationWarning ($message) {
1882 // Is developer mode active?
1883 if (defined('DEVELOPER')) {
1884 // Debug instance is there?
1885 if (!is_null($this->getDebugInstance())) {
1886 // Output stub message
1887 self::createDebugInstance(__CLASS__)->debugOutput($message);
1890 trigger_error($message . "<br />\n");
1894 // @TODO Finish this part!
1895 $this->partialStub('Developer mode inactive. Message:' . $message);
1900 * Checks whether the given PHP extension is loaded
1902 * @param $phpExtension The PHP extension we shall check
1903 * @return $isLoaded Whether the PHP extension is loaded
1905 public final function isPhpExtensionLoaded ($phpExtension) {
1907 $isLoaded = in_array($phpExtension, get_loaded_extensions());
1914 * "Getter" as a time() replacement but with milliseconds. You should use this
1915 * method instead of the encapsulated getimeofday() function.
1917 * @return $milliTime Timestamp with milliseconds
1919 public function getMilliTime () {
1920 // Get the time of day as float
1921 $milliTime = gettimeofday(TRUE);
1928 * Idles (sleeps) for given milliseconds
1930 * @return $hasSlept Whether it goes fine
1932 public function idle ($milliSeconds) {
1933 // Sleep is fine by default
1936 // Idle so long with found function
1937 if (function_exists('time_sleep_until')) {
1938 // Get current time and add idle time
1939 $sleepUntil = $this->getMilliTime() + abs($milliSeconds) / 1000;
1941 // New PHP 5.1.0 function found, ignore errors
1942 $hasSlept = @time_sleep_until($sleepUntil);
1945 * My Sun station doesn't have that function even with latest PHP
1948 usleep($milliSeconds * 1000);
1955 * Converts a hexadecimal string, even with negative sign as first string to
1956 * a decimal number using BC functions.
1958 * This work is based on comment #86673 on php.net documentation page at:
1959 * <http://de.php.net/manual/en/function.dechex.php#86673>
1961 * @param $hex Hexadecimal string
1962 * @return $dec Decimal number
1964 protected function hex2dec ($hex) {
1965 // Convert to all lower-case
1966 $hex = strtolower($hex);
1968 // Detect sign (negative/positive numbers)
1970 if (substr($hex, 0, 1) == '-') {
1972 $hex = substr($hex, 1);
1975 // Decode the hexadecimal string into a decimal number
1977 for ($i = strlen($hex) - 1, $e = 1; $i >= 0; $i--, $e = bcmul($e, 16)) {
1978 $factor = self::$hexdec[substr($hex, $i, 1)];
1979 $dec = bcadd($dec, bcmul($factor, $e));
1982 // Return the decimal number
1983 return $sign . $dec;
1987 * Converts even very large decimal numbers, also signed, to a hexadecimal
1990 * This work is based on comment #97756 on php.net documentation page at:
1991 * <http://de.php.net/manual/en/function.hexdec.php#97756>
1993 * @param $dec Decimal number, even with negative sign
1994 * @param $maxLength Optional maximum length of the string
1995 * @return $hex Hexadecimal string
1997 protected function dec2hex ($dec, $maxLength = 0) {
1998 // maxLength can be zero or devideable by 2
1999 assert(($maxLength == 0) || (($maxLength % 2) == 0));
2001 // Detect sign (negative/positive numbers)
2008 // Encode the decimal number into a hexadecimal string
2011 $hex = self::$dechex[($dec % (2 ^ 4))] . $hex;
2013 } while ($dec >= 1);
2016 * Leading zeros are required for hex-decimal "numbers". In some
2017 * situations more leading zeros are wanted, so check for both
2020 if ($maxLength > 0) {
2021 // Prepend more zeros
2022 $hex = str_pad($hex, $maxLength, '0', STR_PAD_LEFT);
2023 } elseif ((strlen($hex) % 2) != 0) {
2024 // Only make string's length dividable by 2
2028 // Return the hexadecimal string
2029 return $sign . $hex;
2033 * Converts a ASCII string (0 to 255) into a decimal number.
2035 * @param $asc The ASCII string to be converted
2036 * @return $dec Decimal number
2038 protected function asc2dec ($asc) {
2039 // Convert it into a hexadecimal number
2040 $hex = bin2hex($asc);
2042 // And back into a decimal number
2043 $dec = $this->hex2dec($hex);
2050 * Converts a decimal number into an ASCII string.
2052 * @param $dec Decimal number
2053 * @return $asc An ASCII string
2055 protected function dec2asc ($dec) {
2056 // First convert the number into a hexadecimal string
2057 $hex = $this->dec2hex($dec);
2059 // Then convert it into the ASCII string
2060 $asc = $this->hex2asc($hex);
2067 * Converts a hexadecimal number into an ASCII string. Negative numbers
2070 * @param $hex Hexadecimal string
2071 * @return $asc An ASCII string
2073 protected function hex2asc ($hex) {
2074 // Check for length, it must be devideable by 2
2075 //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('hex='.$hex);
2076 assert((strlen($hex) % 2) == 0);
2080 for ($idx = 0; $idx < strlen($hex); $idx+=2) {
2081 // Get the decimal number of the chunk
2082 $part = hexdec(substr($hex, $idx, 2));
2084 // Add it to the final string
2088 // Return the final string
2093 * Checks whether the given encoded data was encoded with Base64
2095 * @param $encodedData Encoded data we shall check
2096 * @return $isBase64 Whether the encoded data is Base64
2098 protected function isBase64Encoded ($encodedData) {
2100 $isBase64 = (@base64_decode($encodedData, TRUE) !== FALSE);
2107 * "Getter" to get response/request type from analysis of the system.
2109 * @return $responseType Analyzed response type
2111 protected function getResponseTypeFromSystem () {
2112 // Default is console
2113 $responseType = 'console';
2115 // Is 'HTTP_HOST' set?
2116 if (isset($_SERVER['HTTP_HOST'])) {
2117 // Then it is a HTTP response/request
2118 $responseType = 'http';
2122 return $responseType;
2126 * Gets a cache key from Criteria instance
2128 * @param $criteriaInstance An instance of a Criteria class
2129 * @param $onlyKeys Only use these keys for a cache key
2130 * @return $cacheKey A cache key suitable for lookup/storage purposes
2132 protected function getCacheKeyByCriteria (Criteria $criteriaInstance, array $onlyKeys = array()) {
2134 $cacheKey = sprintf('%s@%s',
2135 $this->__toString(),
2136 $criteriaInstance->getCacheKey($onlyKeys)
2140 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput($this->__toString() . ': cacheKey=' . $cacheKey);
2145 * Getter for startup time in miliseconds
2147 * @return $startupTime Startup time in miliseconds
2149 protected function getStartupTime () {
2150 return self::$startupTime;
2154 * "Getter" for a printable currently execution time in nice braces
2156 * @return $executionTime Current execution time in nice braces
2158 protected function getPrintableExecutionTime () {
2159 // Caculate the execution time
2160 $executionTime = microtime(TRUE) - $this->getStartupTime();
2162 // Pack it in nice braces
2163 $executionTime = sprintf('[ %01.5f ] ', $executionTime);
2166 return $executionTime;
2170 * Hashes a given string with a simple but stronger hash function (no salt)
2171 * and hex-encode it.
2173 * @param $str The string to be hashed
2174 * @return $hash The hash from string $str
2176 public static final function hash ($str) {
2177 // Hash given string with (better secure) hasher
2178 $hash = bin2hex(mhash(MHASH_SHA256, $str));
2185 * "Getter" for length of hash() output. This will be "cached" to speed up
2188 * @return $length Length of hash() output
2190 public static final function getHashLength () {
2192 if (is_null(self::$hashLength)) {
2193 // No, then hash a string and save its length.
2194 self::$hashLength = strlen(self::hash('abc123'));
2198 return self::$hashLength;
2202 * Checks whether the given number is really a number (only chars 0-9).
2204 * @param $num A string consisting only chars between 0 and 9
2205 * @param $castValue Whether to cast the value to double. Do only use this to secure numbers from Requestable classes.
2206 * @param $assertMismatch Whether to assert mismatches
2207 * @return $ret The (hopefully) secured numbered value
2209 public function bigintval ($num, $castValue = TRUE, $assertMismatch = FALSE) {
2210 // Filter all numbers out
2211 $ret = preg_replace('/[^0123456789]/', '', $num);
2214 if ($castValue === TRUE) {
2215 // Cast to biggest numeric type
2216 $ret = (double) $ret;
2219 // Assert only if requested
2220 if ($assertMismatch === TRUE) {
2221 // Has the whole value changed?
2222 assert(('' . $ret . '' != '' . $num . '') && (!is_null($num)));
2230 * Checks whether the given hexadecimal number is really a hex-number (only chars 0-9,a-f).
2232 * @param $num A string consisting only chars between 0 and 9
2233 * @param $assertMismatch Whether to assert mismatches
2234 * @return $ret The (hopefully) secured hext-numbered value
2236 public function hexval ($num, $assertMismatch = FALSE) {
2237 // Filter all numbers out
2238 $ret = preg_replace('/[^0123456789abcdefABCDEF]/', '', $num);
2240 // Assert only if requested
2241 if ($assertMismatch === TRUE) {
2242 // Has the whole value changed?
2243 assert(('' . $ret . '' != '' . $num . '') && (!is_null($num)));
2251 * Checks whether start/end marker are set
2253 * @param $data Data to be checked
2254 * @return $isset Whether start/end marker are set
2256 public final function ifStartEndMarkersSet ($data) {
2258 $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));
2260 // ... and return it
2265 * Determines if an element is set in the generic array
2267 * @param $keyGroup Main group for the key
2268 * @param $subGroup Sub group for the key
2269 * @param $key Key to check
2270 * @param $element Element to check
2271 * @return $isset Whether the given key is set
2273 protected final function isGenericArrayElementSet ($keyGroup, $subGroup, $key, $element) {
2275 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element);
2278 $isset = isset($this->genericArray[$keyGroup][$subGroup][$key][$element]);
2284 * Determines if a key is set in the generic array
2286 * @param $keyGroup Main group for the key
2287 * @param $subGroup Sub group for the key
2288 * @param $key Key to check
2289 * @return $isset Whether the given key is set
2291 protected final function isGenericArrayKeySet ($keyGroup, $subGroup, $key) {
2293 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
2296 $isset = isset($this->genericArray[$keyGroup][$subGroup][$key]);
2304 * Determines if a group is set in the generic array
2306 * @param $keyGroup Main group
2307 * @param $subGroup Sub group
2308 * @return $isset Whether the given group is set
2310 protected final function isGenericArrayGroupSet ($keyGroup, $subGroup) {
2312 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup);
2315 $isset = isset($this->genericArray[$keyGroup][$subGroup]);
2322 * Getter for sub key group
2324 * @param $keyGroup Main key group
2325 * @param $subGroup Sub key group
2326 * @return $array An array with all array elements
2328 protected final function getGenericSubArray ($keyGroup, $subGroup) {
2330 if (!$this->isGenericArrayGroupSet($keyGroup, $subGroup)) {
2331 // No, then abort here
2332 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' not found.');
2337 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',value=' . print_r($this->genericArray[$keyGroup][$subGroup], TRUE));
2340 return $this->genericArray[$keyGroup][$subGroup];
2344 * Unsets a given key in generic array
2346 * @param $keyGroup Main group for the key
2347 * @param $subGroup Sub group for the key
2348 * @param $key Key to unset
2351 protected final function unsetGenericArrayKey ($keyGroup, $subGroup, $key) {
2353 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
2356 unset($this->genericArray[$keyGroup][$subGroup][$key]);
2360 * Unsets a given element in generic array
2362 * @param $keyGroup Main group for the key
2363 * @param $subGroup Sub group for the key
2364 * @param $key Key to unset
2365 * @param $element Element to unset
2368 protected final function unsetGenericArrayElement ($keyGroup, $subGroup, $key, $element) {
2370 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element);
2373 unset($this->genericArray[$keyGroup][$subGroup][$key][$element]);
2377 * Append a string to a given generic array key
2379 * @param $keyGroup Main group for the key
2380 * @param $subGroup Sub group for the key
2381 * @param $key Key to unset
2382 * @param $value Value to add/append
2385 protected final function appendStringToGenericArrayKey ($keyGroup, $subGroup, $key, $value, $appendGlue = '') {
2387 //* 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);
2389 // Is it already there?
2390 if ($this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
2392 $this->genericArray[$keyGroup][$subGroup][$key] .= $appendGlue . (string) $value;
2395 $this->genericArray[$keyGroup][$subGroup][$key] = (string) $value;
2400 * Append a string to a given generic array element
2402 * @param $keyGroup Main group for the key
2403 * @param $subGroup Sub group for the key
2404 * @param $key Key to unset
2405 * @param $element Element to check
2406 * @param $value Value to add/append
2409 protected final function appendStringToGenericArrayElement ($keyGroup, $subGroup, $key, $element, $value, $appendGlue = '') {
2411 //* 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);
2413 // Is it already there?
2414 if ($this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element)) {
2416 $this->genericArray[$keyGroup][$subGroup][$key][$element] .= $appendGlue . (string) $value;
2419 $this->genericArray[$keyGroup][$subGroup][$key][$element] = (string) $value;
2424 * Initializes given generic array group
2426 * @param $keyGroup Main group for the key
2427 * @param $subGroup Sub group for the key
2428 * @param $key Key to use
2429 * @param $forceInit Optionally force initialization
2432 protected final function initGenericArrayGroup ($keyGroup, $subGroup, $forceInit = FALSE) {
2434 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',forceInit=' . intval($forceInit));
2436 // Is it already set?
2437 if (($forceInit === FALSE) && ($this->isGenericArrayGroupSet($keyGroup, $subGroup))) {
2438 // Already initialized
2439 trigger_error(__METHOD__ . ':keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' already initialized.');
2444 $this->genericArray[$keyGroup][$subGroup] = array();
2448 * Initializes given generic array key
2450 * @param $keyGroup Main group for the key
2451 * @param $subGroup Sub group for the key
2452 * @param $key Key to use
2453 * @param $forceInit Optionally force initialization
2456 protected final function initGenericArrayKey ($keyGroup, $subGroup, $key, $forceInit = FALSE) {
2458 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',forceInit=' . intval($forceInit));
2460 // Is it already set?
2461 if (($forceInit === FALSE) && ($this->isGenericArrayKeySet($keyGroup, $subGroup, $key))) {
2462 // Already initialized
2463 trigger_error(__METHOD__ . ':keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' already initialized.');
2468 $this->genericArray[$keyGroup][$subGroup][$key] = array();
2472 * Initializes given generic array element
2474 * @param $keyGroup Main group for the key
2475 * @param $subGroup Sub group for the key
2476 * @param $key Key to use
2477 * @param $element Element to use
2478 * @param $forceInit Optionally force initialization
2481 protected final function initGenericArrayElement ($keyGroup, $subGroup, $key, $element, $forceInit = FALSE) {
2483 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element . ',forceInit=' . intval($forceInit));
2485 // Is it already set?
2486 if (($forceInit === FALSE) && ($this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element))) {
2487 // Already initialized
2488 trigger_error(__METHOD__ . ':keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element . ' already initialized.');
2493 $this->genericArray[$keyGroup][$subGroup][$key][$element] = array();
2497 * Pushes an element to a generic key
2499 * @param $keyGroup Main group for the key
2500 * @param $subGroup Sub group for the key
2501 * @param $key Key to use
2502 * @param $value Value to add/append
2503 * @return $count Number of array elements
2505 protected final function pushValueToGenericArrayKey ($keyGroup, $subGroup, $key, $value) {
2507 //* NOISY-DEBUG: */ if (!is_object($value)) $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',value[' . gettype($value) . ']=' . print_r($value, TRUE));
2510 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
2512 $this->initGenericArrayKey($keyGroup, $subGroup, $key);
2516 $count = array_push($this->genericArray[$keyGroup][$subGroup][$key], $value);
2519 //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], TRUE));
2520 //* DEBUG: */ print(__METHOD__ . ': count=' . $count . PHP_EOL);
2525 * Pushes an element to a generic array element
2527 * @param $keyGroup Main group for the key
2528 * @param $subGroup Sub group for the key
2529 * @param $key Key to use
2530 * @param $element Element to check
2531 * @param $value Value to add/append
2532 * @return $count Number of array elements
2534 protected final function pushValueToGenericArrayElement ($keyGroup, $subGroup, $key, $element, $value) {
2536 //* 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));
2539 if (!$this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element)) {
2541 $this->initGenericArrayElement($keyGroup, $subGroup, $key, $element);
2545 $count = array_push($this->genericArray[$keyGroup][$subGroup][$key][$element], $value);
2548 //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], TRUE));
2549 //* DEBUG: */ print(__METHOD__ . ': count=' . $count . PHP_EOL);
2554 * Pops an element from a generic group
2556 * @param $keyGroup Main group for the key
2557 * @param $subGroup Sub group for the key
2558 * @param $key Key to unset
2559 * @return $value Last "popped" value
2561 protected final function popGenericArrayElement ($keyGroup, $subGroup, $key) {
2563 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
2566 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
2568 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' not found.');
2573 $value = array_pop($this->genericArray[$keyGroup][$subGroup][$key]);
2576 //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], TRUE));
2577 //* DEBUG: */ print(__METHOD__ . ': value[' . gettype($value) . ']=' . print_r($value, TRUE) . PHP_EOL);
2582 * Shifts an element from a generic group
2584 * @param $keyGroup Main group for the key
2585 * @param $subGroup Sub group for the key
2586 * @param $key Key to unset
2587 * @return $value Last "popped" value
2589 protected final function shiftGenericArrayElement ($keyGroup, $subGroup, $key) {
2591 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
2594 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
2596 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' not found.');
2601 $value = array_shift($this->genericArray[$keyGroup][$subGroup][$key]);
2604 //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], TRUE));
2605 //* DEBUG: */ print(__METHOD__ . ': value[' . gettype($value) . ']=' . print_r($value, TRUE) . PHP_EOL);
2610 * Count generic array group
2612 * @param $keyGroup Main group for the key
2613 * @return $count Count of given group
2615 protected final function countGenericArray ($keyGroup) {
2617 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup);
2620 if (!isset($this->genericArray[$keyGroup])) {
2622 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ' not found.');
2627 $count = count($this->genericArray[$keyGroup]);
2630 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',count=' . $count);
2637 * Count generic array sub group
2639 * @param $keyGroup Main group for the key
2640 * @param $subGroup Sub group for the key
2641 * @return $count Count of given group
2643 protected final function countGenericArrayGroup ($keyGroup, $subGroup) {
2645 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup);
2648 if (!$this->isGenericArrayGroupSet($keyGroup, $subGroup)) {
2650 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' not found.');
2655 $count = count($this->genericArray[$keyGroup][$subGroup]);
2658 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',count=' . $count);
2665 * Count generic array elements
2667 * @param $keyGroup Main group for the key
2668 * @param $subGroup Sub group for the key
2669 * @para $key Key to count
2670 * @return $count Count of given key
2672 protected final function countGenericArrayElements ($keyGroup, $subGroup, $key) {
2674 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
2677 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
2679 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' not found.');
2681 } elseif (!$this->isValidGenericArrayGroup($keyGroup, $subGroup)) {
2683 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' is not an array.');
2688 $count = count($this->genericArray[$keyGroup][$subGroup][$key]);
2691 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',count=' . $count);
2698 * Getter for whole generic group array
2700 * @param $keyGroup Key group to get
2701 * @return $array Whole generic array group
2703 protected final function getGenericArray ($keyGroup) {
2705 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup);
2708 if (!isset($this->genericArray[$keyGroup])) {
2710 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ' does not exist.');
2715 return $this->genericArray[$keyGroup];
2719 * Setter for generic array key
2721 * @param $keyGroup Key group to get
2722 * @param $subGroup Sub group for the key
2723 * @param $key Key to unset
2724 * @param $value Mixed value from generic array element
2727 protected final function setGenericArrayKey ($keyGroup, $subGroup, $key, $value) {
2729 //* NOISY-DEBUG: */ if (!is_object($value)) $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',value[' . gettype($value) . ']=' . print_r($value, TRUE));
2732 $this->genericArray[$keyGroup][$subGroup][$key] = $value;
2736 * Getter for generic array key
2738 * @param $keyGroup Key group to get
2739 * @param $subGroup Sub group for the key
2740 * @param $key Key to unset
2741 * @return $value Mixed value from generic array element
2743 protected final function getGenericArrayKey ($keyGroup, $subGroup, $key) {
2745 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
2748 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
2750 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' does not exist.');
2755 return $this->genericArray[$keyGroup][$subGroup][$key];
2759 * Sets a value in given generic array key/element
2761 * @param $keyGroup Main group for the key
2762 * @param $subGroup Sub group for the key
2763 * @param $key Key to set
2764 * @param $element Element to set
2765 * @param $value Value to set
2768 protected final function setGenericArrayElement ($keyGroup, $subGroup, $key, $element, $value) {
2770 //* 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));
2773 $this->genericArray[$keyGroup][$subGroup][$key][$element] = $value;
2777 * Getter for generic array element
2779 * @param $keyGroup Key group to get
2780 * @param $subGroup Sub group for the key
2781 * @param $key Key to look for
2782 * @param $element Element to look for
2783 * @return $value Mixed value from generic array element
2785 protected final function getGenericArrayElement ($keyGroup, $subGroup, $key, $element) {
2787 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element);
2790 if (!$this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element)) {
2792 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element . ' does not exist.');
2797 return $this->genericArray[$keyGroup][$subGroup][$key][$element];
2801 * Checks if a given sub group is valid (array)
2803 * @param $keyGroup Key group to get
2804 * @param $subGroup Sub group for the key
2805 * @return $isValid Whether given sub group is valid
2807 protected final function isValidGenericArrayGroup ($keyGroup, $subGroup) {
2809 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup);
2812 $isValid = (($this->isGenericArrayGroupSet($keyGroup, $subGroup)) && (is_array($this->getGenericSubArray($keyGroup, $subGroup))));
2819 * Checks if a given key is valid (array)
2821 * @param $keyGroup Key group to get
2822 * @param $subGroup Sub group for the key
2823 * @param $key Key to check
2824 * @return $isValid Whether given sub group is valid
2826 protected final function isValidGenericArrayKey ($keyGroup, $subGroup, $key) {
2828 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
2831 $isValid = (($this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) && (is_array($this->getGenericArrayKey($keyGroup, $subGroup, $key))));
2838 * Translates boolean TRUE to 'Y' and FALSE to 'N'
2840 * @param $boolean Boolean value
2841 * @return $translated Translated boolean value
2843 public static final function translateBooleanToYesNo ($boolean) {
2844 // Make sure it is really boolean
2845 assert(is_bool($boolean));
2848 $translated = ($boolean === TRUE) ? 'Y' : 'N';
2850 // ... and return it