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 - 2014 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 HandleableProtocol 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 * A FrameworkDirectory instance
204 private $directoryInstance = NULL;
207 * Thousands separator
209 private $thousands = '.'; // German
214 private $decimals = ','; // German
219 private $socketResource = FALSE;
224 private $packageData = array();
229 private $genericArray = array();
231 /***********************
232 * Exception codes.... *
233 ***********************/
235 // @todo Try to clean these constants up
236 const EXCEPTION_IS_NULL_POINTER = 0x001;
237 const EXCEPTION_IS_NO_OBJECT = 0x002;
238 const EXCEPTION_IS_NO_ARRAY = 0x003;
239 const EXCEPTION_MISSING_METHOD = 0x004;
240 const EXCEPTION_CLASSES_NOT_MATCHING = 0x005;
241 const EXCEPTION_INDEX_OUT_OF_BOUNDS = 0x006;
242 const EXCEPTION_DIMENSION_ARRAY_INVALID = 0x007;
243 const EXCEPTION_ITEM_NOT_TRADEABLE = 0x008;
244 const EXCEPTION_ITEM_NOT_IN_PRICE_LIST = 0x009;
245 const EXCEPTION_GENDER_IS_WRONG = 0x00a;
246 const EXCEPTION_BIRTH_DATE_IS_INVALID = 0x00b;
247 const EXCEPTION_EMPTY_STRUCTURES_ARRAY = 0x00c;
248 const EXCEPTION_HAS_ALREADY_PERSONELL_LIST = 0x00d;
249 const EXCEPTION_NOT_ENOUGTH_UNEMPLOYEES = 0x00e;
250 const EXCEPTION_TOTAL_PRICE_NOT_CALCULATED = 0x00f;
251 const EXCEPTION_HARBOR_HAS_NO_SHIPYARDS = 0x010;
252 const EXCEPTION_CONTRACT_PARTNER_INVALID = 0x011;
253 const EXCEPTION_CONTRACT_PARTNER_MISMATCH = 0x012;
254 const EXCEPTION_CONTRACT_ALREADY_SIGNED = 0x013;
255 const EXCEPTION_UNEXPECTED_EMPTY_STRING = 0x014;
256 const EXCEPTION_PATH_NOT_FOUND = 0x015;
257 const EXCEPTION_INVALID_PATH_NAME = 0x016;
258 const EXCEPTION_READ_PROTECED_PATH = 0x017;
259 const EXCEPTION_WRITE_PROTECED_PATH = 0x018;
260 const EXCEPTION_DIR_POINTER_INVALID = 0x019;
261 const EXCEPTION_FILE_POINTER_INVALID = 0x01a;
262 const EXCEPTION_INVALID_RESOURCE = 0x01b;
263 const EXCEPTION_UNEXPECTED_OBJECT = 0x01c;
264 const EXCEPTION_LIMIT_ELEMENT_IS_UNSUPPORTED = 0x01d;
265 const EXCEPTION_GETTER_IS_MISSING = 0x01e;
266 const EXCEPTION_ARRAY_EXPECTED = 0x01f;
267 const EXCEPTION_ARRAY_HAS_INVALID_COUNT = 0x020;
268 const EXCEPTION_ID_IS_INVALID_FORMAT = 0x021;
269 const EXCEPTION_MD5_CHECKSUMS_MISMATCH = 0x022;
270 const EXCEPTION_UNEXPECTED_STRING_SIZE = 0x023;
271 const EXCEPTION_SIMULATOR_ID_INVALID = 0x024;
272 const EXCEPTION_MISMATCHING_COMPRESSORS = 0x025;
273 const EXCEPTION_CONTAINER_ITEM_IS_NULL = 0x026;
274 const EXCEPTION_ITEM_IS_NO_ARRAY = 0x027;
275 const EXCEPTION_CONTAINER_MAYBE_DAMAGED = 0x028;
276 const EXCEPTION_INVALID_STRING = 0x029;
277 const EXCEPTION_VARIABLE_NOT_SET = 0x02a;
278 const EXCEPTION_ATTRIBUTES_ARE_MISSING = 0x02b;
279 const EXCEPTION_ARRAY_ELEMENTS_MISSING = 0x02c;
280 const EXCEPTION_TEMPLATE_ENGINE_UNSUPPORTED = 0x02d;
281 const EXCEPTION_UNSPPORTED_OPERATION = 0x02e;
282 const EXCEPTION_FACTORY_REQUIRE_PARAMETER = 0x02f;
283 const EXCEPTION_MISSING_ELEMENT = 0x030;
284 const EXCEPTION_HEADERS_ALREADY_SENT = 0x031;
285 const EXCEPTION_DEFAULT_CONTROLLER_GONE = 0x032;
286 const EXCEPTION_CLASS_NOT_FOUND = 0x033;
287 const EXCEPTION_REQUIRED_INTERFACE_MISSING = 0x034;
288 const EXCEPTION_FATAL_ERROR = 0x035;
289 const EXCEPTION_FILE_NOT_FOUND = 0x036;
290 const EXCEPTION_ASSERTION_FAILED = 0x037;
291 const EXCEPTION_FILE_CANNOT_BE_READ = 0x038;
292 const EXCEPTION_DATABASE_UPDATED_NOT_ALLOWED = 0x039;
293 const EXCEPTION_FILTER_CHAIN_INTERCEPTED = 0x03a;
296 * Hexadecimal->Decimal translation array
298 private static $hexdec = array(
318 * Decimal->hexadecimal translation array
320 private static $dechex = array(
340 * Startup time in miliseconds
342 private static $startupTime = 0;
345 * Protected super constructor
347 * @param $className Name of the class
350 protected function __construct ($className) {
352 $this->setRealClass($className);
354 // Set configuration instance if no registry ...
355 if (!$this instanceof Register) {
356 // ... because registries doesn't need to be configured
357 $this->setConfigInstance(FrameworkConfiguration::getSelfInstance());
360 // Is the startup time set? (0 cannot be TRUE anymore)
361 if (self::$startupTime == 0) {
363 self::$startupTime = microtime(TRUE);
368 * Destructor for all classes
372 public function __destruct () {
373 // Flush any updated entries to the database
374 $this->flushPendingUpdates();
376 // Is this object already destroyed?
377 if ($this->__toString() != 'DestructedObject') {
378 // Destroy all informations about this class but keep some text about it alive
379 $this->setRealClass('DestructedObject');
380 } elseif ((defined('DEBUG_DESTRUCTOR')) && (is_object($this->getDebugInstance()))) {
381 // Already destructed object
382 self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:] The object <span class="object_name">%s</span> is already destroyed.',
387 // Do not call this twice
388 trigger_error(__METHOD__ . ': Called twice.');
394 * The __call() method where all non-implemented methods end up
396 * @param $methodName Name of the missing method
397 * @args $args Arguments passed to the method
400 public final function __call ($methodName, $args) {
401 return self::__callStatic($methodName, $args);
405 * The __callStatic() method where all non-implemented static methods end up
407 * @param $methodName Name of the missing method
408 * @args $args Arguments passed to the method
411 public static final function __callStatic ($methodName, $args) {
412 // Init argument string
415 // Is it empty or an array?
418 $argsString = 'NULL';
419 } elseif (is_array($args)) {
420 // Some arguments are there
421 foreach ($args as $arg) {
422 // Add the value itself if not array. This prevents 'array to string conversion' message
423 if (is_array($arg)) {
424 $argsString .= 'Array';
429 // Add data about the argument
430 $argsString .= ' (' . gettype($arg);
432 if (is_string($arg)) {
433 // Add length for strings
434 $argsString .= ', ' . strlen($arg);
435 } elseif (is_array($arg)) {
436 // .. or size if array
437 $argsString .= ', ' . count($arg);
438 } elseif ($arg === TRUE) {
439 // ... is boolean 'TRUE'
440 $argsString .= ', TRUE';
441 } elseif ($arg === FALSE) {
442 // ... is boolean 'FALSE'
443 $argsString .= ', FALSE';
447 $argsString .= '), ';
451 if (substr($argsString, -2, 1) == ',') {
452 $argsString = substr($argsString, 0, -2);
455 // Invalid arguments!
456 $argsString = '!INVALID:' . gettype($args) . '!';
459 // Output stub message
460 // @TODO __CLASS__ does always return BaseFrameworkSystem but not the extending (=child) class
461 self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[unknown::%s:] Stub! Args: %s',
471 * Getter for $realClass
473 * @return $realClass The name of the real class (not BaseFrameworkSystem)
475 public function __toString () {
476 return $this->realClass;
480 * Magic function to catch setting of missing but set class fields/attributes
482 * @param $name Name of the field/attribute
483 * @param $value Value to store
486 public final function __set ($name, $value) {
487 $this->debugBackTrace(sprintf('Tried to set a missing field. name=%s, value[%s]=%s',
490 print_r($value, TRUE)
495 * Magic function to catch getting of missing fields/attributes
497 * @param $name Name of the field/attribute
500 public final function __get ($name) {
501 $this->debugBackTrace(sprintf('Tried to get a missing field. name=%s',
507 * Magic function to catch unsetting of missing fields/attributes
509 * @param $name Name of the field/attribute
512 public final function __unset ($name) {
513 $this->debugBackTrace(sprintf('Tried to unset a missing field. name=%s',
519 * Setter for the real class name
521 * @param $realClass Class name (string)
524 public final function setRealClass ($realClass) {
526 $this->realClass = (string) $realClass;
530 * Setter for database result instance
532 * @param $resultInstance An instance of a database result class
534 * @todo SearchableResult and UpdateableResult shall have a super interface to use here
536 protected final function setResultInstance (SearchableResult $resultInstance) {
537 $this->resultInstance = $resultInstance;
541 * Getter for database result instance
543 * @return $resultInstance An instance of a database result class
545 public final function getResultInstance () {
546 return $this->resultInstance;
550 * Setter for template engine instances
552 * @param $templateInstance An instance of a template engine class
555 protected final function setTemplateInstance (CompileableTemplate $templateInstance) {
556 $this->templateInstance = $templateInstance;
560 * Getter for template engine instances
562 * @return $templateInstance An instance of a template engine class
564 protected final function getTemplateInstance () {
565 return $this->templateInstance;
569 * Setter for search instance
571 * @param $searchInstance Searchable criteria instance
574 public final function setSearchInstance (LocalSearchCriteria $searchInstance) {
575 $this->searchInstance = $searchInstance;
579 * Getter for search instance
581 * @return $searchInstance Searchable criteria instance
583 public final function getSearchInstance () {
584 return $this->searchInstance;
588 * Setter for update instance
590 * @param $updateInstance Searchable criteria instance
593 public final function setUpdateInstance (LocalUpdateCriteria $updateInstance) {
594 $this->updateInstance = $updateInstance;
598 * Getter for update instance
600 * @return $updateInstance Updateable criteria instance
602 public final function getUpdateInstance () {
603 return $this->updateInstance;
607 * Setter for resolver instance
609 * @param $resolverInstance Instance of a command resolver class
612 public final function setResolverInstance (Resolver $resolverInstance) {
613 $this->resolverInstance = $resolverInstance;
617 * Getter for resolver instance
619 * @return $resolverInstance Instance of a command resolver class
621 public final function getResolverInstance () {
622 return $this->resolverInstance;
626 * Setter for language instance
628 * @param $configInstance The configuration instance which shall
629 * be FrameworkConfiguration
632 public final function setConfigInstance (FrameworkConfiguration $configInstance) {
633 Registry::getRegistry()->addInstance('config', $configInstance);
637 * Getter for configuration instance
639 * @return $configInstance Configuration instance
641 public final function getConfigInstance () {
642 $configInstance = Registry::getRegistry()->getInstance('config');
643 return $configInstance;
647 * Setter for debug instance
649 * @param $debugInstance The instance for debug output class
652 public final function setDebugInstance (DebugMiddleware $debugInstance) {
653 Registry::getRegistry()->addInstance('debug', $debugInstance);
657 * Getter for debug instance
659 * @return $debugInstance Instance to class DebugConsoleOutput or DebugWebOutput
661 public final function getDebugInstance () {
662 // Get debug instance
663 $debugInstance = Registry::getRegistry()->getInstance('debug');
666 return $debugInstance;
670 * Setter for web output instance
672 * @param $webInstance The instance for web output class
675 public final function setWebOutputInstance (OutputStreamer $webInstance) {
676 Registry::getRegistry()->addInstance('web_output', $webInstance);
680 * Getter for web output instance
682 * @return $webOutputInstance - Instance to class WebOutput
684 public final function getWebOutputInstance () {
685 $webOutputInstance = Registry::getRegistry()->getInstance('web_output');
686 return $webOutputInstance;
690 * Setter for database instance
692 * @param $databaseInstance The instance for the database connection (forced DatabaseConnection)
695 public final function setDatabaseInstance (DatabaseConnection $databaseInstance) {
696 Registry::getRegistry()->addInstance('db_instance', $databaseInstance);
700 * Getter for database layer
702 * @return $databaseInstance The database layer instance
704 public final function getDatabaseInstance () {
706 $databaseInstance = Registry::getRegistry()->getInstance('db_instance');
709 return $databaseInstance;
713 * Setter for compressor channel
715 * @param $compressorInstance An instance of CompressorChannel
718 public final function setCompressorChannel (CompressorChannel $compressorInstance) {
719 Registry::getRegistry()->addInstance('compressor', $compressorInstance);
723 * Getter for compressor channel
725 * @return $compressorInstance The compressor channel
727 public final function getCompressorChannel () {
728 $compressorInstance = Registry::getRegistry()->getInstance('compressor');
729 return $compressorInstance;
733 * Protected getter for a manageable application helper class
735 * @return $applicationInstance An instance of a manageable application helper class
737 protected final function getApplicationInstance () {
738 $applicationInstance = Registry::getRegistry()->getInstance('application');
739 return $applicationInstance;
743 * Setter for a manageable application helper class
745 * @param $applicationInstance An instance of a manageable application helper class
748 public final function setApplicationInstance (ManageableApplication $applicationInstance) {
749 Registry::getRegistry()->addInstance('application', $applicationInstance);
753 * Setter for request instance
755 * @param $requestInstance An instance of a Requestable class
758 public final function setRequestInstance (Requestable $requestInstance) {
759 $this->requestInstance = $requestInstance;
763 * Getter for request instance
765 * @return $requestInstance An instance of a Requestable class
767 public final function getRequestInstance () {
768 return $this->requestInstance;
772 * Setter for response instance
774 * @param $responseInstance An instance of a Responseable class
777 public final function setResponseInstance (Responseable $responseInstance) {
778 $this->responseInstance = $responseInstance;
782 * Getter for response instance
784 * @return $responseInstance An instance of a Responseable class
786 public final function getResponseInstance () {
787 return $this->responseInstance;
791 * Private getter for language instance
793 * @return $langInstance An instance to the language sub-system
795 protected final function getLanguageInstance () {
796 $langInstance = Registry::getRegistry()->getInstance('language');
797 return $langInstance;
801 * Setter for language instance
803 * @param $langInstance An instance to the language sub-system
805 * @see LanguageSystem
807 public final function setLanguageInstance (ManageableLanguage $langInstance) {
808 Registry::getRegistry()->addInstance('language', $langInstance);
812 * Private getter for file IO instance
814 * @return $fileIoInstance An instance to the file I/O sub-system
816 protected final function getFileIoInstance () {
817 return $this->fileIoInstance;
821 * Setter for file I/O instance
823 * @param $fileIoInstance An instance to the file I/O sub-system
826 public final function setFileIoInstance (IoHandler $fileIoInstance) {
827 $this->fileIoInstance = $fileIoInstance;
831 * Protected setter for user instance
833 * @param $userInstance An instance of a user class
836 protected final function setUserInstance (ManageableAccount $userInstance) {
837 $this->userInstance = $userInstance;
841 * Getter for user instance
843 * @return $userInstance An instance of a user class
845 public final function getUserInstance () {
846 return $this->userInstance;
850 * Setter for controller instance (this surely breaks a bit the MVC patterm)
852 * @param $controllerInstance An instance of the controller
855 public final function setControllerInstance (Controller $controllerInstance) {
856 $this->controllerInstance = $controllerInstance;
860 * Getter for controller instance (this surely breaks a bit the MVC patterm)
862 * @return $controllerInstance An instance of the controller
864 public final function getControllerInstance () {
865 return $this->controllerInstance;
869 * Setter for RNG instance
871 * @param $rngInstance An instance of a random number generator (RNG)
874 protected final function setRngInstance (RandomNumberGenerator $rngInstance) {
875 $this->rngInstance = $rngInstance;
879 * Getter for RNG instance
881 * @return $rngInstance An instance of a random number generator (RNG)
883 public final function getRngInstance () {
884 return $this->rngInstance;
888 * Setter for Cryptable instance
890 * @param $cryptoInstance An instance of a Cryptable class
893 protected final function setCryptoInstance (Cryptable $cryptoInstance) {
894 $this->cryptoInstance = $cryptoInstance;
898 * Getter for Cryptable instance
900 * @return $cryptoInstance An instance of a Cryptable class
902 public final function getCryptoInstance () {
903 return $this->cryptoInstance;
907 * Setter for the list instance
909 * @param $listInstance A list of Listable
912 protected final function setListInstance (Listable $listInstance) {
913 $this->listInstance = $listInstance;
917 * Getter for the list instance
919 * @return $listInstance A list of Listable
921 protected final function getListInstance () {
922 return $this->listInstance;
926 * Setter for the menu instance
928 * @param $menuInstance A RenderableMenu instance
931 protected final function setMenuInstance (RenderableMenu $menuInstance) {
932 $this->menuInstance = $menuInstance;
936 * Getter for the menu instance
938 * @return $menuInstance A RenderableMenu instance
940 protected final function getMenuInstance () {
941 return $this->menuInstance;
945 * Setter for image instance
947 * @param $imageInstance An instance of an image
950 public final function setImageInstance (BaseImage $imageInstance) {
951 $this->imageInstance = $imageInstance;
955 * Getter for image instance
957 * @return $imageInstance An instance of an image
959 public final function getImageInstance () {
960 return $this->imageInstance;
964 * Setter for stacker instance
966 * @param $stackInstance An instance of an stacker
969 public final function setStackInstance (Stackable $stackInstance) {
970 $this->stackInstance = $stackInstance;
974 * Getter for stacker instance
976 * @return $stackInstance An instance of an stacker
978 public final function getStackInstance () {
979 return $this->stackInstance;
983 * Setter for compressor instance
985 * @param $compressorInstance An instance of an compressor
988 public final function setCompressorInstance (Compressor $compressorInstance) {
989 $this->compressorInstance = $compressorInstance;
993 * Getter for compressor instance
995 * @return $compressorInstance An instance of an compressor
997 public final function getCompressorInstance () {
998 return $this->compressorInstance;
1002 * Setter for Parseable instance
1004 * @param $parserInstance An instance of an Parseable
1007 public final function setParserInstance (Parseable $parserInstance) {
1008 $this->parserInstance = $parserInstance;
1012 * Getter for Parseable instance
1014 * @return $parserInstance An instance of an Parseable
1016 public final function getParserInstance () {
1017 return $this->parserInstance;
1021 * Setter for HandleableProtocol instance
1023 * @param $protocolInstance An instance of an HandleableProtocol
1026 public final function setProtocolInstance (ProtocolHandler $protocolInstance = NULL) {
1027 $this->protocolInstance = $protocolInstance;
1031 * Getter for HandleableProtocol instance
1033 * @return $protocolInstance An instance of an HandleableProtocol
1035 public final function getProtocolInstance () {
1036 return $this->protocolInstance;
1040 * Setter for DatabaseWrapper instance
1042 * @param $wrapperInstance An instance of an DatabaseWrapper
1045 public final function setWrapperInstance (DatabaseWrapper $wrapperInstance) {
1046 $this->wrapperInstance = $wrapperInstance;
1050 * Getter for DatabaseWrapper instance
1052 * @return $wrapperInstance An instance of an DatabaseWrapper
1054 public final function getWrapperInstance () {
1055 return $this->wrapperInstance;
1059 * Setter for socket resource
1061 * @param $socketResource A valid socket resource
1064 public final function setSocketResource ($socketResource) {
1065 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput($this->__toString() . '::' . __FUNCTION__ . ': socketResource=' . $socketResource . ',previous[' . gettype($this->socketResource) . ']=' . $this->socketResource);
1066 $this->socketResource = $socketResource;
1070 * Getter for socket resource
1072 * @return $socketResource A valid socket resource
1074 public final function getSocketResource () {
1075 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput($this->__toString() . '::' . __FUNCTION__ . ': socketResource[' . gettype($this->socketResource) . ']=' . $this->socketResource);
1076 return $this->socketResource;
1080 * Setter for helper instance
1082 * @param $helperInstance An instance of a helper class
1085 protected final function setHelperInstance (Helper $helperInstance) {
1086 $this->helperInstance = $helperInstance;
1090 * Getter for helper instance
1092 * @return $helperInstance An instance of a helper class
1094 public final function getHelperInstance () {
1095 return $this->helperInstance;
1099 * Setter for a Sourceable instance
1101 * @param $sourceInstance The Sourceable instance
1104 protected final function setSourceInstance (Sourceable $sourceInstance) {
1105 $this->sourceInstance = $sourceInstance;
1109 * Getter for a Sourceable instance
1111 * @return $sourceInstance The Sourceable instance
1113 protected final function getSourceInstance () {
1114 return $this->sourceInstance;
1118 * Getter for a InputStream instance
1120 * @param $inputStreamInstance The InputStream instance
1122 protected final function getInputStreamInstance () {
1123 return $this->inputStreamInstance;
1127 * Setter for a InputStream instance
1129 * @param $inputStreamInstance The InputStream instance
1132 protected final function setInputStreamInstance (InputStream $inputStreamInstance) {
1133 $this->inputStreamInstance = $inputStreamInstance;
1137 * Getter for a OutputStream instance
1139 * @param $outputStreamInstance The OutputStream instance
1141 protected final function getOutputStreamInstance () {
1142 return $this->outputStreamInstance;
1146 * Setter for a OutputStream instance
1148 * @param $outputStreamInstance The OutputStream instance
1151 protected final function setOutputStreamInstance (OutputStream $outputStreamInstance) {
1152 $this->outputStreamInstance = $outputStreamInstance;
1156 * Setter for handler instance
1158 * @param $handlerInstance An instance of a Handleable class
1161 protected final function setHandlerInstance (Handleable $handlerInstance) {
1162 $this->handlerInstance = $handlerInstance;
1166 * Getter for handler instance
1168 * @return $handlerInstance A Networkable instance
1170 protected final function getHandlerInstance () {
1171 return $this->handlerInstance;
1175 * Setter for visitor instance
1177 * @param $visitorInstance A Visitor instance
1180 protected final function setVisitorInstance (Visitor $visitorInstance) {
1181 $this->visitorInstance = $visitorInstance;
1185 * Getter for visitor instance
1187 * @return $visitorInstance A Visitor instance
1189 protected final function getVisitorInstance () {
1190 return $this->visitorInstance;
1194 * Setter for DHT instance
1196 * @param $dhtInstance A Distributable instance
1199 protected final function setDhtInstance (Distributable $dhtInstance) {
1200 $this->dhtInstance = $dhtInstance;
1204 * Getter for DHT instance
1206 * @return $dhtInstance A Distributable instance
1208 protected final function getDhtInstance () {
1209 return $this->dhtInstance;
1213 * Setter for raw package Data
1215 * @param $packageData Raw package Data
1218 public final function setPackageData (array $packageData) {
1219 $this->packageData = $packageData;
1223 * Getter for raw package Data
1225 * @return $packageData Raw package Data
1227 public function getPackageData () {
1228 return $this->packageData;
1233 * Setter for Iterator instance
1235 * @param $iteratorInstance An instance of an Iterator
1238 protected final function setIteratorInstance (Iterator $iteratorInstance) {
1239 $this->iteratorInstance = $iteratorInstance;
1243 * Getter for Iterator instance
1245 * @return $iteratorInstance An instance of an Iterator
1247 public final function getIteratorInstance () {
1248 return $this->iteratorInstance;
1252 * Setter for InputOutputPointer instance
1254 * @param $pointerInstance An instance of an InputOutputPointer class
1257 protected final function setPointerInstance (InputOutputPointer $pointerInstance) {
1258 $this->pointerInstance = $pointerInstance;
1262 * Getter for InputOutputPointer instance
1264 * @return $pointerInstance An instance of an InputOutputPointer class
1266 public final function getPointerInstance () {
1267 return $this->pointerInstance;
1271 * Setter for Indexable instance
1273 * @param $indexInstance An instance of an Indexable class
1276 protected final function setIndexInstance (Indexable $indexInstance) {
1277 $this->indexInstance = $indexInstance;
1281 * Getter for Indexable instance
1283 * @return $indexInstance An instance of an Indexable class
1285 public final function getIndexInstance () {
1286 return $this->indexInstance;
1290 * Setter for Block instance
1292 * @param $blockInstance An instance of an Block class
1295 protected final function setBlockInstance (Block $blockInstance) {
1296 $this->blockInstance = $blockInstance;
1300 * Getter for Block instance
1302 * @return $blockInstance An instance of an Block class
1304 public final function getBlockInstance () {
1305 return $this->blockInstance;
1309 * Setter for Minable instance
1311 * @param $minableInstance A Minable instance
1314 protected final function setMinableInstance (Minable $minableInstance) {
1315 $this->minableInstance = $minableInstance;
1319 * Getter for minable instance
1321 * @return $minableInstance A Minable instance
1323 protected final function getMinableInstance () {
1324 return $this->minableInstance;
1328 * Setter for FrameworkDirectory instance
1330 * @param $directoryInstance A FrameworkDirectoryPointer instance
1333 protected final function setDirectoryInstance (FrameworkDirectory $directoryInstance) {
1334 $this->directoryInstance = $directoryInstance;
1338 * Getter for FrameworkDirectory instance
1340 * @return $directoryInstance A FrameworkDirectory instance
1342 protected final function getDirectoryInstance () {
1343 return $this->directoryInstance;
1347 * Checks whether an object equals this object. You should overwrite this
1348 * method to implement own equality checks
1350 * @param $objectInstance An instance of a FrameworkInterface object
1351 * @return $equals Whether both objects equals
1353 public function equals (FrameworkInterface $objectInstance) {
1356 $this->__toString() == $objectInstance->__toString()
1358 $this->hashCode() == $objectInstance->hashCode()
1361 // Return the result
1366 * Generates a generic hash code of this class. You should really overwrite
1367 * this method with your own hash code generator code. But keep KISS in mind.
1369 * @return $hashCode A generic hash code respresenting this whole class
1371 public function hashCode () {
1373 return crc32($this->__toString());
1377 * Formats computer generated price values into human-understandable formats
1378 * with thousand and decimal separators.
1380 * @param $value The in computer format value for a price
1381 * @param $currency The currency symbol (use HTML-valid characters!)
1382 * @param $decNum Number of decimals after commata
1383 * @return $price The for the current language formated price string
1384 * @throws MissingDecimalsThousandsSeparatorException If decimals or
1385 * thousands separator
1388 public function formatCurrency ($value, $currency = '€', $decNum = 2) {
1389 // Are all required attriutes set?
1390 if ((!isset($this->decimals)) || (!isset($this->thousands))) {
1391 // Throw an exception
1392 throw new MissingDecimalsThousandsSeparatorException($this, self::EXCEPTION_ATTRIBUTES_ARE_MISSING);
1396 $value = (float) $value;
1398 // Reformat the US number
1399 $price = number_format($value, $decNum, $this->decimals, $this->thousands) . $currency;
1401 // Return as string...
1406 * Appends a trailing slash to a string
1408 * @param $str A string (maybe) without trailing slash
1409 * @return $str A string with an auto-appended trailing slash
1411 public final function addMissingTrailingSlash ($str) {
1412 // Is there a trailing slash?
1413 if (substr($str, -1, 1) != '/') {
1417 // Return string with trailing slash
1422 * Prepare the template engine (WebTemplateEngine by default) for a given
1423 * application helper instance (ApplicationHelper by default).
1425 * @param $applicationInstance An application helper instance or
1426 * null if we shall use the default
1427 * @return $templateInstance The template engine instance
1428 * @throws NullPointerException If the discovered application
1429 * instance is still null
1431 protected function prepareTemplateInstance (ManageableApplication $applicationInstance = NULL) {
1432 // Is the application instance set?
1433 if (is_null($applicationInstance)) {
1434 // Get the current instance
1435 $applicationInstance = $this->getApplicationInstance();
1438 if (is_null($applicationInstance)) {
1439 // Thrown an exception
1440 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
1444 // Initialize the template engine
1445 $templateInstance = ObjectFactory::createObjectByConfiguredName('web_template_class');
1447 // Return the prepared instance
1448 return $templateInstance;
1452 * Debugs this instance by putting out it's full content
1454 * @param $message Optional message to show in debug output
1457 public final function debugInstance ($message = '') {
1458 // Restore the error handler to avoid trouble with missing array elements or undeclared variables
1459 restore_error_handler();
1464 // Is a message set?
1465 if (!empty($message)) {
1466 // Construct message
1467 $content = sprintf('<div class="debug_message">Message: %s</div>' . PHP_EOL, $message);
1470 // Generate the output
1471 $content .= sprintf('<pre>%s</pre>',
1474 print_r($this, TRUE)
1480 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>',
1481 $this->__toString(),
1483 ClassLoader::getSelfInstance()->getPrintableIncludeList()
1488 * Replaces control characters with printable output
1490 * @param $str String with control characters
1491 * @return $str Replaced string
1493 protected function replaceControlCharacters ($str) {
1496 chr(13), '[r]', str_replace(
1497 chr(10), '[n]', str_replace(
1507 * Output a partial stub message for the caller method
1509 * @param $message An optional message to display
1512 protected function partialStub ($message = '') {
1513 // Get the backtrace
1514 $backtrace = debug_backtrace();
1516 // Generate the class::method string
1517 $methodName = 'UnknownClass->unknownMethod';
1518 if ((isset($backtrace[1]['class'])) && (isset($backtrace[1]['function']))) {
1519 $methodName = $backtrace[1]['class'] . '->' . $backtrace[1]['function'];
1522 // Construct the full message
1523 $stubMessage = sprintf('[%s:] Partial stub!',
1527 // Is the extra message given?
1528 if (!empty($message)) {
1529 // Then add it as well
1530 $stubMessage .= ' Message: ' . $message;
1533 // Debug instance is there?
1534 if (!is_null($this->getDebugInstance())) {
1535 // Output stub message
1536 self::createDebugInstance(__CLASS__)->debugOutput($stubMessage);
1539 trigger_error($stubMessage);
1545 * Outputs a debug backtrace and stops further script execution
1547 * @param $message An optional message to output
1548 * @param $doExit Whether exit the program (TRUE is default)
1551 public function debugBackTrace ($message = '', $doExit = TRUE) {
1552 // Sorry, there is no other way getting this nice backtrace
1553 if (!empty($message)) {
1555 printf('Message: %s<br />' . chr(10), $message);
1559 debug_print_backtrace();
1563 if ($doExit === TRUE) {
1569 * Creates an instance of a debugger instance
1571 * @param $className Name of the class (currently unsupported)
1572 * @return $debugInstance An instance of a debugger class
1574 public final static function createDebugInstance ($className) {
1575 // Is the instance set?
1576 if (!Registry::getRegistry()->instanceExists('debug')) {
1577 // Init debug instance
1578 $debugInstance = NULL;
1582 // Get a debugger instance
1583 $debugInstance = DebugMiddleware::createDebugMiddleware(FrameworkConfiguration::getSelfInstance()->getConfigEntry('debug_class'));
1584 } catch (NullPointerException $e) {
1585 // Didn't work, no instance there
1586 exit('Cannot create debugInstance! Exception=' . $e->__toString() . ', message=' . $e->getMessage());
1589 // Empty string should be ignored and used for testing the middleware
1590 DebugMiddleware::getSelfInstance()->output('');
1592 // Set it in its own class. This will set it in the registry
1593 $debugInstance->setDebugInstance($debugInstance);
1595 // Get instance from registry
1596 $debugInstance = Registry::getRegistry()->getDebugInstance();
1600 return $debugInstance;
1604 * Simple output of a message with line-break
1606 * @param $message Message to output
1609 public function outputLine ($message) {
1611 print($message . PHP_EOL);
1615 * Outputs a debug message whether to debug instance (should be set!) or
1616 * dies with or ptints the message. Do NEVER EVER rewrite the exit() call to
1617 * ApplicationEntryPoint::app_exit(), this would cause an endless loop.
1619 * @param $message Message we shall send out...
1620 * @param $doPrint Whether print or die here (default: print)
1621 * @paran $stripTags Whether to strip tags (default: FALSE)
1624 public function debugOutput ($message, $doPrint = TRUE, $stripTags = FALSE) {
1625 // Set debug instance to NULL
1626 $debugInstance = NULL;
1630 // Get debug instance
1631 $debugInstance = $this->getDebugInstance();
1632 } catch (NullPointerException $e) {
1633 // The debug instance is not set (yet)
1636 // Is the debug instance there?
1637 if (is_object($debugInstance)) {
1638 // Use debug output handler
1639 $debugInstance->output($message, $stripTags);
1641 if ($doPrint === FALSE) {
1642 // Die here if not printed
1646 // Are debug times enabled?
1647 if ($this->getConfigInstance()->getConfigEntry('debug_output_timings') == 'Y') {
1649 $message = $this->getPrintableExecutionTime() . $message;
1653 if ($doPrint === TRUE) {
1655 $this->outputLine($message);
1664 * Converts e.g. a command from URL to a valid class by keeping out bad characters
1666 * @param $str The string, what ever it is needs to be converted
1667 * @return $className Generated class name
1669 public function convertToClassName ($str) {
1673 // Convert all dashes in underscores
1674 $str = $this->convertDashesToUnderscores($str);
1676 // Now use that underscores to get classname parts for hungarian style
1677 foreach (explode('_', $str) as $strPart) {
1678 // Make the class name part lower case and first upper case
1679 $className .= ucfirst(strtolower($strPart));
1682 // Return class name
1687 * Converts dashes to underscores, e.g. useable for configuration entries
1689 * @param $str The string with maybe dashes inside
1690 * @return $str The converted string with no dashed, but underscores
1692 public final function convertDashesToUnderscores ($str) {
1694 $str = str_replace('-', '_', $str);
1696 // Return converted string
1701 * Marks up the code by adding e.g. line numbers
1703 * @param $phpCode Unmarked PHP code
1704 * @return $markedCode Marked PHP code
1706 public function markupCode ($phpCode) {
1711 $errorArray = error_get_last();
1713 // Init the code with error message
1714 if (is_array($errorArray)) {
1716 $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>',
1717 basename($errorArray['file']),
1718 $errorArray['line'],
1719 $errorArray['message'],
1724 // Add line number to the code
1725 foreach (explode(chr(10), $phpCode) as $lineNo => $code) {
1727 $markedCode .= sprintf('<span id="code_line">%s</span>: %s' . chr(10),
1729 htmlentities($code, ENT_QUOTES)
1738 * Filter a given GMT timestamp (non Uni* stamp!) to make it look more
1739 * beatiful for web-based front-ends. If null is given a message id
1740 * null_timestamp will be resolved and returned.
1742 * @param $timestamp Timestamp to prepare (filter) for display
1743 * @return $readable A readable timestamp
1745 public function doFilterFormatTimestamp ($timestamp) {
1746 // Default value to return
1749 // Is the timestamp null?
1750 if (is_null($timestamp)) {
1751 // Get a message string
1752 $readable = $this->getLanguageInstance()->getMessage('null_timestamp');
1754 switch ($this->getLanguageInstance()->getLanguageCode()) {
1755 case 'de': // German format is a bit different to default
1756 // Split the GMT stamp up
1757 $dateTime = explode(' ', $timestamp );
1758 $dateArray = explode('-', $dateTime[0]);
1759 $timeArray = explode(':', $dateTime[1]);
1761 // Construct the timestamp
1762 $readable = sprintf($this->getConfigInstance()->getConfigEntry('german_date_time'),
1772 default: // Default is pass-through
1773 $readable = $timestamp;
1783 * Filter a given number into a localized number
1785 * @param $value The raw value from e.g. database
1786 * @return $localized Localized value
1788 public function doFilterFormatNumber ($value) {
1789 // Generate it from config and localize dependencies
1790 switch ($this->getLanguageInstance()->getLanguageCode()) {
1791 case 'de': // German format is a bit different to default
1792 $localized = number_format($value, $this->getConfigInstance()->getConfigEntry('decimals'), ',', '.');
1795 default: // US, etc.
1796 $localized = number_format($value, $this->getConfigInstance()->getConfigEntry('decimals'), '.', ',');
1805 * "Getter" for databse entry
1807 * @return $entry An array with database entries
1808 * @throws NullPointerException If the database result is not found
1809 * @throws InvalidDatabaseResultException If the database result is invalid
1811 protected final function getDatabaseEntry () {
1812 // Is there an instance?
1813 if (is_null($this->getResultInstance())) {
1814 // Throw an exception here
1815 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
1819 $this->getResultInstance()->rewind();
1821 // Do we have an entry?
1822 if ($this->getResultInstance()->valid() === FALSE) {
1823 throw new InvalidDatabaseResultException(array($this, $this->getResultInstance()), DatabaseResult::EXCEPTION_INVALID_DATABASE_RESULT);
1827 $this->getResultInstance()->next();
1830 $entry = $this->getResultInstance()->current();
1837 * Getter for field name
1839 * @param $fieldName Field name which we shall get
1840 * @return $fieldValue Field value from the user
1841 * @throws NullPointerException If the result instance is null
1843 public final function getField ($fieldName) {
1844 // Default field value
1847 // Get result instance
1848 $resultInstance = $this->getResultInstance();
1850 // Is this instance null?
1851 if (is_null($resultInstance)) {
1852 // Then the user instance is no longer valid (expired cookies?)
1853 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
1856 // Get current array
1857 $fieldArray = $resultInstance->current();
1858 //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput($fieldName.':<pre>'.print_r($fieldArray, TRUE).'</pre>');
1860 // Convert dashes to underscore
1861 $fieldName = $this->convertDashesToUnderscores($fieldName);
1863 // Does the field exist?
1864 if (isset($fieldArray[$fieldName])) {
1866 $fieldValue = $fieldArray[$fieldName];
1868 // Missing field entry, may require debugging
1869 self::createDebugInstance(__CLASS__)->debugOutput($this->__toString() . ':fieldname=' . $fieldName . ' not found!');
1877 * Flushs all pending updates to the database layer
1881 public function flushPendingUpdates () {
1882 // Get result instance
1883 $resultInstance = $this->getResultInstance();
1885 // Do we have data to update?
1886 if ((is_object($resultInstance)) && ($resultInstance->ifDataNeedsFlush())) {
1887 // Get wrapper class name config entry
1888 $configEntry = $resultInstance->getUpdateInstance()->getWrapperConfigEntry();
1890 // Create object instance
1891 $wrapperInstance = ObjectFactory::createObjectByConfiguredName($configEntry);
1893 // Yes, then send the whole result to the database layer
1894 $wrapperInstance->doUpdateByResult($this->getResultInstance());
1899 * Outputs a deprecation warning to the developer.
1901 * @param $message The message we shall output to the developer
1903 * @todo Write a logging mechanism for productive mode
1905 public function deprecationWarning ($message) {
1906 // Is developer mode active?
1907 if (defined('DEVELOPER')) {
1908 // Debug instance is there?
1909 if (!is_null($this->getDebugInstance())) {
1910 // Output stub message
1911 self::createDebugInstance(__CLASS__)->debugOutput($message);
1914 trigger_error($message . "<br />\n");
1918 // @TODO Finish this part!
1919 $this->partialStub('Developer mode inactive. Message:' . $message);
1924 * Checks whether the given PHP extension is loaded
1926 * @param $phpExtension The PHP extension we shall check
1927 * @return $isLoaded Whether the PHP extension is loaded
1929 public final function isPhpExtensionLoaded ($phpExtension) {
1931 $isLoaded = in_array($phpExtension, get_loaded_extensions());
1938 * "Getter" as a time() replacement but with milliseconds. You should use this
1939 * method instead of the encapsulated getimeofday() function.
1941 * @return $milliTime Timestamp with milliseconds
1943 public function getMilliTime () {
1944 // Get the time of day as float
1945 $milliTime = gettimeofday(TRUE);
1952 * Idles (sleeps) for given milliseconds
1954 * @return $hasSlept Whether it goes fine
1956 public function idle ($milliSeconds) {
1957 // Sleep is fine by default
1960 // Idle so long with found function
1961 if (function_exists('time_sleep_until')) {
1962 // Get current time and add idle time
1963 $sleepUntil = $this->getMilliTime() + abs($milliSeconds) / 1000;
1965 // New PHP 5.1.0 function found, ignore errors
1966 $hasSlept = @time_sleep_until($sleepUntil);
1969 * My Sun station doesn't have that function even with latest PHP
1972 usleep($milliSeconds * 1000);
1979 * Converts a hexadecimal string, even with negative sign as first string to
1980 * a decimal number using BC functions.
1982 * This work is based on comment #86673 on php.net documentation page at:
1983 * <http://de.php.net/manual/en/function.dechex.php#86673>
1985 * @param $hex Hexadecimal string
1986 * @return $dec Decimal number
1988 protected function hex2dec ($hex) {
1989 // Convert to all lower-case
1990 $hex = strtolower($hex);
1992 // Detect sign (negative/positive numbers)
1994 if (substr($hex, 0, 1) == '-') {
1996 $hex = substr($hex, 1);
1999 // Decode the hexadecimal string into a decimal number
2001 for ($i = strlen($hex) - 1, $e = 1; $i >= 0; $i--, $e = bcmul($e, 16)) {
2002 $factor = self::$hexdec[substr($hex, $i, 1)];
2003 $dec = bcadd($dec, bcmul($factor, $e));
2006 // Return the decimal number
2007 return $sign . $dec;
2011 * Converts even very large decimal numbers, also signed, to a hexadecimal
2014 * This work is based on comment #97756 on php.net documentation page at:
2015 * <http://de.php.net/manual/en/function.hexdec.php#97756>
2017 * @param $dec Decimal number, even with negative sign
2018 * @param $maxLength Optional maximum length of the string
2019 * @return $hex Hexadecimal string
2021 protected function dec2hex ($dec, $maxLength = 0) {
2022 // maxLength can be zero or devideable by 2
2023 assert(($maxLength == 0) || (($maxLength % 2) == 0));
2025 // Detect sign (negative/positive numbers)
2032 // Encode the decimal number into a hexadecimal string
2035 $hex = self::$dechex[($dec % (2 ^ 4))] . $hex;
2037 } while ($dec >= 1);
2040 * Leading zeros are required for hex-decimal "numbers". In some
2041 * situations more leading zeros are wanted, so check for both
2044 if ($maxLength > 0) {
2045 // Prepend more zeros
2046 $hex = str_pad($hex, $maxLength, '0', STR_PAD_LEFT);
2047 } elseif ((strlen($hex) % 2) != 0) {
2048 // Only make string's length dividable by 2
2052 // Return the hexadecimal string
2053 return $sign . $hex;
2057 * Converts a ASCII string (0 to 255) into a decimal number.
2059 * @param $asc The ASCII string to be converted
2060 * @return $dec Decimal number
2062 protected function asc2dec ($asc) {
2063 // Convert it into a hexadecimal number
2064 $hex = bin2hex($asc);
2066 // And back into a decimal number
2067 $dec = $this->hex2dec($hex);
2074 * Converts a decimal number into an ASCII string.
2076 * @param $dec Decimal number
2077 * @return $asc An ASCII string
2079 protected function dec2asc ($dec) {
2080 // First convert the number into a hexadecimal string
2081 $hex = $this->dec2hex($dec);
2083 // Then convert it into the ASCII string
2084 $asc = $this->hex2asc($hex);
2091 * Converts a hexadecimal number into an ASCII string. Negative numbers
2094 * @param $hex Hexadecimal string
2095 * @return $asc An ASCII string
2097 protected function hex2asc ($hex) {
2098 // Check for length, it must be devideable by 2
2099 //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('hex='.$hex);
2100 assert((strlen($hex) % 2) == 0);
2104 for ($idx = 0; $idx < strlen($hex); $idx+=2) {
2105 // Get the decimal number of the chunk
2106 $part = hexdec(substr($hex, $idx, 2));
2108 // Add it to the final string
2112 // Return the final string
2117 * Checks whether the given encoded data was encoded with Base64
2119 * @param $encodedData Encoded data we shall check
2120 * @return $isBase64 Whether the encoded data is Base64
2122 protected function isBase64Encoded ($encodedData) {
2124 $isBase64 = (@base64_decode($encodedData, TRUE) !== FALSE);
2131 * "Getter" to get response/request type from analysis of the system.
2133 * @return $responseType Analyzed response type
2135 protected function getResponseTypeFromSystem () {
2136 // Default is console
2137 $responseType = 'console';
2139 // Is 'HTTP_HOST' set?
2140 if (isset($_SERVER['HTTP_HOST'])) {
2141 // Then it is a HTTP response/request
2142 $responseType = 'http';
2146 return $responseType;
2150 * Gets a cache key from Criteria instance
2152 * @param $criteriaInstance An instance of a Criteria class
2153 * @param $onlyKeys Only use these keys for a cache key
2154 * @return $cacheKey A cache key suitable for lookup/storage purposes
2156 protected function getCacheKeyByCriteria (Criteria $criteriaInstance, array $onlyKeys = array()) {
2158 $cacheKey = sprintf('%s@%s',
2159 $this->__toString(),
2160 $criteriaInstance->getCacheKey($onlyKeys)
2164 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput($this->__toString() . ': cacheKey=' . $cacheKey);
2169 * Getter for startup time in miliseconds
2171 * @return $startupTime Startup time in miliseconds
2173 protected function getStartupTime () {
2174 return self::$startupTime;
2178 * "Getter" for a printable currently execution time in nice braces
2180 * @return $executionTime Current execution time in nice braces
2182 protected function getPrintableExecutionTime () {
2183 // Caculate the execution time
2184 $executionTime = microtime(TRUE) - $this->getStartupTime();
2186 // Pack it in nice braces
2187 $executionTime = sprintf('[ %01.5f ] ', $executionTime);
2190 return $executionTime;
2194 * Hashes a given string with a simple but stronger hash function (no salt)
2195 * and hex-encode it.
2197 * @param $str The string to be hashed
2198 * @return $hash The hash from string $str
2200 public static final function hash ($str) {
2201 // Hash given string with (better secure) hasher
2202 $hash = bin2hex(mhash(MHASH_SHA256, $str));
2209 * "Getter" for length of hash() output. This will be "cached" to speed up
2212 * @return $length Length of hash() output
2214 public static final function getHashLength () {
2216 if (is_null(self::$hashLength)) {
2217 // No, then hash a string and save its length.
2218 self::$hashLength = strlen(self::hash('abc123'));
2222 return self::$hashLength;
2226 * Checks whether the given number is really a number (only chars 0-9).
2228 * @param $num A string consisting only chars between 0 and 9
2229 * @param $castValue Whether to cast the value to double. Do only use this to secure numbers from Requestable classes.
2230 * @param $assertMismatch Whether to assert mismatches
2231 * @return $ret The (hopefully) secured numbered value
2233 public function bigintval ($num, $castValue = TRUE, $assertMismatch = FALSE) {
2234 // Filter all numbers out
2235 $ret = preg_replace('/[^0123456789]/', '', $num);
2238 if ($castValue === TRUE) {
2239 // Cast to biggest numeric type
2240 $ret = (double) $ret;
2243 // Assert only if requested
2244 if ($assertMismatch === TRUE) {
2245 // Has the whole value changed?
2246 assert(('' . $ret . '' != '' . $num . '') && (!is_null($num)));
2254 * Checks whether the given hexadecimal number is really a hex-number (only chars 0-9,a-f).
2256 * @param $num A string consisting only chars between 0 and 9
2257 * @param $assertMismatch Whether to assert mismatches
2258 * @return $ret The (hopefully) secured hext-numbered value
2260 public function hexval ($num, $assertMismatch = FALSE) {
2261 // Filter all numbers out
2262 $ret = preg_replace('/[^0123456789abcdefABCDEF]/', '', $num);
2264 // Assert only if requested
2265 if ($assertMismatch === TRUE) {
2266 // Has the whole value changed?
2267 assert(('' . $ret . '' != '' . $num . '') && (!is_null($num)));
2275 * Checks whether start/end marker are set
2277 * @param $data Data to be checked
2278 * @return $isset Whether start/end marker are set
2280 public final function ifStartEndMarkersSet ($data) {
2282 $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));
2284 // ... and return it
2289 * Determines if an element is set in the generic array
2291 * @param $keyGroup Main group for the key
2292 * @param $subGroup Sub group for the key
2293 * @param $key Key to check
2294 * @param $element Element to check
2295 * @return $isset Whether the given key is set
2297 protected final function isGenericArrayElementSet ($keyGroup, $subGroup, $key, $element) {
2299 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element);
2302 $isset = isset($this->genericArray[$keyGroup][$subGroup][$key][$element]);
2308 * Determines if a key is set in the generic array
2310 * @param $keyGroup Main group for the key
2311 * @param $subGroup Sub group for the key
2312 * @param $key Key to check
2313 * @return $isset Whether the given key is set
2315 protected final function isGenericArrayKeySet ($keyGroup, $subGroup, $key) {
2317 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
2320 $isset = isset($this->genericArray[$keyGroup][$subGroup][$key]);
2328 * Determines if a group is set in the generic array
2330 * @param $keyGroup Main group
2331 * @param $subGroup Sub group
2332 * @return $isset Whether the given group is set
2334 protected final function isGenericArrayGroupSet ($keyGroup, $subGroup) {
2336 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup);
2339 $isset = isset($this->genericArray[$keyGroup][$subGroup]);
2346 * Getter for sub key group
2348 * @param $keyGroup Main key group
2349 * @param $subGroup Sub key group
2350 * @return $array An array with all array elements
2352 protected final function getGenericSubArray ($keyGroup, $subGroup) {
2354 if (!$this->isGenericArrayGroupSet($keyGroup, $subGroup)) {
2355 // No, then abort here
2356 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' not found.');
2361 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',value=' . print_r($this->genericArray[$keyGroup][$subGroup], TRUE));
2364 return $this->genericArray[$keyGroup][$subGroup];
2368 * Unsets a given key in generic array
2370 * @param $keyGroup Main group for the key
2371 * @param $subGroup Sub group for the key
2372 * @param $key Key to unset
2375 protected final function unsetGenericArrayKey ($keyGroup, $subGroup, $key) {
2377 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
2380 unset($this->genericArray[$keyGroup][$subGroup][$key]);
2384 * Unsets a given element in generic array
2386 * @param $keyGroup Main group for the key
2387 * @param $subGroup Sub group for the key
2388 * @param $key Key to unset
2389 * @param $element Element to unset
2392 protected final function unsetGenericArrayElement ($keyGroup, $subGroup, $key, $element) {
2394 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element);
2397 unset($this->genericArray[$keyGroup][$subGroup][$key][$element]);
2401 * Append a string to a given generic array key
2403 * @param $keyGroup Main group for the key
2404 * @param $subGroup Sub group for the key
2405 * @param $key Key to unset
2406 * @param $value Value to add/append
2409 protected final function appendStringToGenericArrayKey ($keyGroup, $subGroup, $key, $value, $appendGlue = '') {
2411 //* 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);
2413 // Is it already there?
2414 if ($this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
2416 $this->genericArray[$keyGroup][$subGroup][$key] .= $appendGlue . (string) $value;
2419 $this->genericArray[$keyGroup][$subGroup][$key] = (string) $value;
2424 * Append a string to a given generic array element
2426 * @param $keyGroup Main group for the key
2427 * @param $subGroup Sub group for the key
2428 * @param $key Key to unset
2429 * @param $element Element to check
2430 * @param $value Value to add/append
2433 protected final function appendStringToGenericArrayElement ($keyGroup, $subGroup, $key, $element, $value, $appendGlue = '') {
2435 //* 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);
2437 // Is it already there?
2438 if ($this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element)) {
2440 $this->genericArray[$keyGroup][$subGroup][$key][$element] .= $appendGlue . (string) $value;
2443 $this->genericArray[$keyGroup][$subGroup][$key][$element] = (string) $value;
2448 * Initializes given generic array group
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 initGenericArrayGroup ($keyGroup, $subGroup, $forceInit = FALSE) {
2458 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',forceInit=' . intval($forceInit));
2460 // Is it already set?
2461 if (($forceInit === FALSE) && ($this->isGenericArrayGroupSet($keyGroup, $subGroup))) {
2462 // Already initialized
2463 trigger_error(__METHOD__ . ':keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' already initialized.');
2468 $this->genericArray[$keyGroup][$subGroup] = array();
2472 * Initializes given generic array key
2474 * @param $keyGroup Main group for the key
2475 * @param $subGroup Sub group for the key
2476 * @param $key Key to use
2477 * @param $forceInit Optionally force initialization
2480 protected final function initGenericArrayKey ($keyGroup, $subGroup, $key, $forceInit = FALSE) {
2482 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',forceInit=' . intval($forceInit));
2484 // Is it already set?
2485 if (($forceInit === FALSE) && ($this->isGenericArrayKeySet($keyGroup, $subGroup, $key))) {
2486 // Already initialized
2487 trigger_error(__METHOD__ . ':keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' already initialized.');
2492 $this->genericArray[$keyGroup][$subGroup][$key] = array();
2496 * Initializes given generic array element
2498 * @param $keyGroup Main group for the key
2499 * @param $subGroup Sub group for the key
2500 * @param $key Key to use
2501 * @param $element Element to use
2502 * @param $forceInit Optionally force initialization
2505 protected final function initGenericArrayElement ($keyGroup, $subGroup, $key, $element, $forceInit = FALSE) {
2507 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element . ',forceInit=' . intval($forceInit));
2509 // Is it already set?
2510 if (($forceInit === FALSE) && ($this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element))) {
2511 // Already initialized
2512 trigger_error(__METHOD__ . ':keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element . ' already initialized.');
2517 $this->genericArray[$keyGroup][$subGroup][$key][$element] = array();
2521 * Pushes an element to a generic key
2523 * @param $keyGroup Main group for the key
2524 * @param $subGroup Sub group for the key
2525 * @param $key Key to use
2526 * @param $value Value to add/append
2527 * @return $count Number of array elements
2529 protected final function pushValueToGenericArrayKey ($keyGroup, $subGroup, $key, $value) {
2531 //* NOISY-DEBUG: */ if (!is_object($value)) $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',value[' . gettype($value) . ']=' . print_r($value, TRUE));
2534 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
2536 $this->initGenericArrayKey($keyGroup, $subGroup, $key);
2540 $count = array_push($this->genericArray[$keyGroup][$subGroup][$key], $value);
2543 //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], TRUE));
2544 //* DEBUG: */ print(__METHOD__ . ': count=' . $count . PHP_EOL);
2549 * Pushes an element to a generic array element
2551 * @param $keyGroup Main group for the key
2552 * @param $subGroup Sub group for the key
2553 * @param $key Key to use
2554 * @param $element Element to check
2555 * @param $value Value to add/append
2556 * @return $count Number of array elements
2558 protected final function pushValueToGenericArrayElement ($keyGroup, $subGroup, $key, $element, $value) {
2560 //* 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));
2563 if (!$this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element)) {
2565 $this->initGenericArrayElement($keyGroup, $subGroup, $key, $element);
2569 $count = array_push($this->genericArray[$keyGroup][$subGroup][$key][$element], $value);
2572 //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], TRUE));
2573 //* DEBUG: */ print(__METHOD__ . ': count=' . $count . PHP_EOL);
2578 * Pops an element from a generic group
2580 * @param $keyGroup Main group for the key
2581 * @param $subGroup Sub group for the key
2582 * @param $key Key to unset
2583 * @return $value Last "popped" value
2585 protected final function popGenericArrayElement ($keyGroup, $subGroup, $key) {
2587 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
2590 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
2592 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' not found.');
2597 $value = array_pop($this->genericArray[$keyGroup][$subGroup][$key]);
2600 //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], TRUE));
2601 //* DEBUG: */ print(__METHOD__ . ': value[' . gettype($value) . ']=' . print_r($value, TRUE) . PHP_EOL);
2606 * Shifts an element from a generic group
2608 * @param $keyGroup Main group for the key
2609 * @param $subGroup Sub group for the key
2610 * @param $key Key to unset
2611 * @return $value Last "popped" value
2613 protected final function shiftGenericArrayElement ($keyGroup, $subGroup, $key) {
2615 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
2618 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
2620 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' not found.');
2625 $value = array_shift($this->genericArray[$keyGroup][$subGroup][$key]);
2628 //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], TRUE));
2629 //* DEBUG: */ print(__METHOD__ . ': value[' . gettype($value) . ']=' . print_r($value, TRUE) . PHP_EOL);
2634 * Count generic array group
2636 * @param $keyGroup Main group for the key
2637 * @return $count Count of given group
2639 protected final function countGenericArray ($keyGroup) {
2641 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup);
2644 if (!isset($this->genericArray[$keyGroup])) {
2646 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ' not found.');
2651 $count = count($this->genericArray[$keyGroup]);
2654 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',count=' . $count);
2661 * Count generic array sub group
2663 * @param $keyGroup Main group for the key
2664 * @param $subGroup Sub group for the key
2665 * @return $count Count of given group
2667 protected final function countGenericArrayGroup ($keyGroup, $subGroup) {
2669 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup);
2672 if (!$this->isGenericArrayGroupSet($keyGroup, $subGroup)) {
2674 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' not found.');
2679 $count = count($this->genericArray[$keyGroup][$subGroup]);
2682 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',count=' . $count);
2689 * Count generic array elements
2691 * @param $keyGroup Main group for the key
2692 * @param $subGroup Sub group for the key
2693 * @para $key Key to count
2694 * @return $count Count of given key
2696 protected final function countGenericArrayElements ($keyGroup, $subGroup, $key) {
2698 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
2701 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
2703 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' not found.');
2705 } elseif (!$this->isValidGenericArrayGroup($keyGroup, $subGroup)) {
2707 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' is not an array.');
2712 $count = count($this->genericArray[$keyGroup][$subGroup][$key]);
2715 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',count=' . $count);
2722 * Getter for whole generic group array
2724 * @param $keyGroup Key group to get
2725 * @return $array Whole generic array group
2727 protected final function getGenericArray ($keyGroup) {
2729 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup);
2732 if (!isset($this->genericArray[$keyGroup])) {
2734 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ' does not exist.');
2739 return $this->genericArray[$keyGroup];
2743 * Setter for generic array key
2745 * @param $keyGroup Key group to get
2746 * @param $subGroup Sub group for the key
2747 * @param $key Key to unset
2748 * @param $value Mixed value from generic array element
2751 protected final function setGenericArrayKey ($keyGroup, $subGroup, $key, $value) {
2753 //* NOISY-DEBUG: */ if (!is_object($value)) $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',value[' . gettype($value) . ']=' . print_r($value, TRUE));
2756 $this->genericArray[$keyGroup][$subGroup][$key] = $value;
2760 * Getter for generic array key
2762 * @param $keyGroup Key group to get
2763 * @param $subGroup Sub group for the key
2764 * @param $key Key to unset
2765 * @return $value Mixed value from generic array element
2767 protected final function getGenericArrayKey ($keyGroup, $subGroup, $key) {
2769 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
2772 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
2774 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' does not exist.');
2779 return $this->genericArray[$keyGroup][$subGroup][$key];
2783 * Sets a value in given generic array key/element
2785 * @param $keyGroup Main group for the key
2786 * @param $subGroup Sub group for the key
2787 * @param $key Key to set
2788 * @param $element Element to set
2789 * @param $value Value to set
2792 protected final function setGenericArrayElement ($keyGroup, $subGroup, $key, $element, $value) {
2794 //* 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));
2797 $this->genericArray[$keyGroup][$subGroup][$key][$element] = $value;
2801 * Getter for generic array element
2803 * @param $keyGroup Key group to get
2804 * @param $subGroup Sub group for the key
2805 * @param $key Key to look for
2806 * @param $element Element to look for
2807 * @return $value Mixed value from generic array element
2809 protected final function getGenericArrayElement ($keyGroup, $subGroup, $key, $element) {
2811 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element);
2814 if (!$this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element)) {
2816 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element . ' does not exist.');
2821 return $this->genericArray[$keyGroup][$subGroup][$key][$element];
2825 * Checks if a given sub group is valid (array)
2827 * @param $keyGroup Key group to get
2828 * @param $subGroup Sub group for the key
2829 * @return $isValid Whether given sub group is valid
2831 protected final function isValidGenericArrayGroup ($keyGroup, $subGroup) {
2833 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup);
2836 $isValid = (($this->isGenericArrayGroupSet($keyGroup, $subGroup)) && (is_array($this->getGenericSubArray($keyGroup, $subGroup))));
2843 * Checks if a given key is valid (array)
2845 * @param $keyGroup Key group to get
2846 * @param $subGroup Sub group for the key
2847 * @param $key Key to check
2848 * @return $isValid Whether given sub group is valid
2850 protected final function isValidGenericArrayKey ($keyGroup, $subGroup, $key) {
2852 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
2855 $isValid = (($this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) && (is_array($this->getGenericArrayKey($keyGroup, $subGroup, $key))));
2862 * Translates boolean TRUE to 'Y' and FALSE to 'N'
2864 * @param $boolean Boolean value
2865 * @return $translated Translated boolean value
2867 public static final function translateBooleanToYesNo ($boolean) {
2868 // Make sure it is really boolean
2869 assert(is_bool($boolean));
2872 $translated = ($boolean === TRUE) ? 'Y' : 'N';
2874 // ... and return it