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;
209 private $listenerInstance = NULL;
212 * Thousands separator
214 private $thousands = '.'; // German
219 private $decimals = ','; // German
224 private $socketResource = FALSE;
227 * Regular expression to use for validation
229 private $regularExpression = '';
234 private $packageData = array();
239 private $genericArray = array();
241 /***********************
242 * Exception codes.... *
243 ***********************/
245 // @todo Try to clean these constants up
246 const EXCEPTION_IS_NULL_POINTER = 0x001;
247 const EXCEPTION_IS_NO_OBJECT = 0x002;
248 const EXCEPTION_IS_NO_ARRAY = 0x003;
249 const EXCEPTION_MISSING_METHOD = 0x004;
250 const EXCEPTION_CLASSES_NOT_MATCHING = 0x005;
251 const EXCEPTION_INDEX_OUT_OF_BOUNDS = 0x006;
252 const EXCEPTION_DIMENSION_ARRAY_INVALID = 0x007;
253 const EXCEPTION_ITEM_NOT_TRADEABLE = 0x008;
254 const EXCEPTION_ITEM_NOT_IN_PRICE_LIST = 0x009;
255 const EXCEPTION_GENDER_IS_WRONG = 0x00a;
256 const EXCEPTION_BIRTH_DATE_IS_INVALID = 0x00b;
257 const EXCEPTION_EMPTY_STRUCTURES_ARRAY = 0x00c;
258 const EXCEPTION_HAS_ALREADY_PERSONELL_LIST = 0x00d;
259 const EXCEPTION_NOT_ENOUGTH_UNEMPLOYEES = 0x00e;
260 const EXCEPTION_TOTAL_PRICE_NOT_CALCULATED = 0x00f;
261 const EXCEPTION_HARBOR_HAS_NO_SHIPYARDS = 0x010;
262 const EXCEPTION_CONTRACT_PARTNER_INVALID = 0x011;
263 const EXCEPTION_CONTRACT_PARTNER_MISMATCH = 0x012;
264 const EXCEPTION_CONTRACT_ALREADY_SIGNED = 0x013;
265 const EXCEPTION_UNEXPECTED_EMPTY_STRING = 0x014;
266 const EXCEPTION_PATH_NOT_FOUND = 0x015;
267 const EXCEPTION_INVALID_PATH_NAME = 0x016;
268 const EXCEPTION_READ_PROTECED_PATH = 0x017;
269 const EXCEPTION_WRITE_PROTECED_PATH = 0x018;
270 const EXCEPTION_DIR_POINTER_INVALID = 0x019;
271 const EXCEPTION_FILE_POINTER_INVALID = 0x01a;
272 const EXCEPTION_INVALID_RESOURCE = 0x01b;
273 const EXCEPTION_UNEXPECTED_OBJECT = 0x01c;
274 const EXCEPTION_LIMIT_ELEMENT_IS_UNSUPPORTED = 0x01d;
275 const EXCEPTION_GETTER_IS_MISSING = 0x01e;
276 const EXCEPTION_ARRAY_EXPECTED = 0x01f;
277 const EXCEPTION_ARRAY_HAS_INVALID_COUNT = 0x020;
278 const EXCEPTION_ID_IS_INVALID_FORMAT = 0x021;
279 const EXCEPTION_MD5_CHECKSUMS_MISMATCH = 0x022;
280 const EXCEPTION_UNEXPECTED_STRING_SIZE = 0x023;
281 const EXCEPTION_SIMULATOR_ID_INVALID = 0x024;
282 const EXCEPTION_MISMATCHING_COMPRESSORS = 0x025;
283 const EXCEPTION_CONTAINER_ITEM_IS_NULL = 0x026;
284 const EXCEPTION_ITEM_IS_NO_ARRAY = 0x027;
285 const EXCEPTION_CONTAINER_MAYBE_DAMAGED = 0x028;
286 const EXCEPTION_INVALID_STRING = 0x029;
287 const EXCEPTION_VARIABLE_NOT_SET = 0x02a;
288 const EXCEPTION_ATTRIBUTES_ARE_MISSING = 0x02b;
289 const EXCEPTION_ARRAY_ELEMENTS_MISSING = 0x02c;
290 const EXCEPTION_TEMPLATE_ENGINE_UNSUPPORTED = 0x02d;
291 const EXCEPTION_UNSPPORTED_OPERATION = 0x02e;
292 const EXCEPTION_FACTORY_REQUIRE_PARAMETER = 0x02f;
293 const EXCEPTION_MISSING_ELEMENT = 0x030;
294 const EXCEPTION_HEADERS_ALREADY_SENT = 0x031;
295 const EXCEPTION_DEFAULT_CONTROLLER_GONE = 0x032;
296 const EXCEPTION_CLASS_NOT_FOUND = 0x033;
297 const EXCEPTION_REQUIRED_INTERFACE_MISSING = 0x034;
298 const EXCEPTION_FATAL_ERROR = 0x035;
299 const EXCEPTION_FILE_NOT_FOUND = 0x036;
300 const EXCEPTION_ASSERTION_FAILED = 0x037;
301 const EXCEPTION_FILE_CANNOT_BE_READ = 0x038;
302 const EXCEPTION_DATABASE_UPDATED_NOT_ALLOWED = 0x039;
303 const EXCEPTION_FILTER_CHAIN_INTERCEPTED = 0x03a;
306 * Hexadecimal->Decimal translation array
308 private static $hexdec = array(
328 * Decimal->hexadecimal translation array
330 private static $dechex = array(
350 * Startup time in miliseconds
352 private static $startupTime = 0;
355 * Protected super constructor
357 * @param $className Name of the class
360 protected function __construct ($className) {
362 $this->setRealClass($className);
364 // Set configuration instance if no registry ...
365 if (!$this instanceof Register) {
366 // ... because registries doesn't need to be configured
367 $this->setConfigInstance(FrameworkConfiguration::getSelfInstance());
370 // Is the startup time set? (0 cannot be TRUE anymore)
371 if (self::$startupTime == 0) {
373 self::$startupTime = microtime(TRUE);
378 * Destructor for all classes
382 public function __destruct () {
383 // Flush any updated entries to the database
384 $this->flushPendingUpdates();
386 // Is this object already destroyed?
387 if ($this->__toString() != 'DestructedObject') {
388 // Destroy all informations about this class but keep some text about it alive
389 $this->setRealClass('DestructedObject');
390 } elseif ((defined('DEBUG_DESTRUCTOR')) && (is_object($this->getDebugInstance()))) {
391 // Already destructed object
392 self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:] The object <span class="object_name">%s</span> is already destroyed.',
397 // Do not call this twice
398 trigger_error(__METHOD__ . ': Called twice.');
404 * The __call() method where all non-implemented methods end up
406 * @param $methodName Name of the missing method
407 * @args $args Arguments passed to the method
410 public final function __call ($methodName, $args) {
411 return self::__callStatic($methodName, $args);
415 * The __callStatic() method where all non-implemented static methods end up
417 * @param $methodName Name of the missing method
418 * @args $args Arguments passed to the method
421 public static final function __callStatic ($methodName, $args) {
422 // Init argument string
425 // Is it empty or an array?
428 $argsString = 'NULL';
429 } elseif (is_array($args)) {
430 // Some arguments are there
431 foreach ($args as $arg) {
432 // Add the value itself if not array. This prevents 'array to string conversion' message
433 if (is_array($arg)) {
434 $argsString .= 'Array';
439 // Add data about the argument
440 $argsString .= ' (' . gettype($arg);
442 if (is_string($arg)) {
443 // Add length for strings
444 $argsString .= ', ' . strlen($arg);
445 } elseif (is_array($arg)) {
446 // .. or size if array
447 $argsString .= ', ' . count($arg);
448 } elseif ($arg === TRUE) {
449 // ... is boolean 'TRUE'
450 $argsString .= ', TRUE';
451 } elseif ($arg === FALSE) {
452 // ... is boolean 'FALSE'
453 $argsString .= ', FALSE';
457 $argsString .= '), ';
461 if (substr($argsString, -2, 1) == ',') {
462 $argsString = substr($argsString, 0, -2);
465 // Invalid arguments!
466 $argsString = '!INVALID:' . gettype($args) . '!';
469 // Output stub message
470 // @TODO __CLASS__ does always return BaseFrameworkSystem but not the extending (=child) class
471 self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[unknown::%s:] Stub! Args: %s',
481 * Getter for $realClass
483 * @return $realClass The name of the real class (not BaseFrameworkSystem)
485 public function __toString () {
486 return $this->realClass;
490 * Magic function to catch setting of missing but set class fields/attributes
492 * @param $name Name of the field/attribute
493 * @param $value Value to store
496 public final function __set ($name, $value) {
497 $this->debugBackTrace(sprintf('Tried to set a missing field. name=%s, value[%s]=%s',
500 print_r($value, TRUE)
505 * Magic function to catch getting of missing fields/attributes
507 * @param $name Name of the field/attribute
510 public final function __get ($name) {
511 $this->debugBackTrace(sprintf('Tried to get a missing field. name=%s',
517 * Magic function to catch unsetting of missing fields/attributes
519 * @param $name Name of the field/attribute
522 public final function __unset ($name) {
523 $this->debugBackTrace(sprintf('Tried to unset a missing field. name=%s',
529 * Setter for the real class name
531 * @param $realClass Class name (string)
534 public final function setRealClass ($realClass) {
536 $this->realClass = (string) $realClass;
540 * Setter for database result instance
542 * @param $resultInstance An instance of a database result class
544 * @todo SearchableResult and UpdateableResult shall have a super interface to use here
546 protected final function setResultInstance (SearchableResult $resultInstance) {
547 $this->resultInstance = $resultInstance;
551 * Getter for database result instance
553 * @return $resultInstance An instance of a database result class
555 public final function getResultInstance () {
556 return $this->resultInstance;
560 * Setter for template engine instances
562 * @param $templateInstance An instance of a template engine class
565 protected final function setTemplateInstance (CompileableTemplate $templateInstance) {
566 $this->templateInstance = $templateInstance;
570 * Getter for template engine instances
572 * @return $templateInstance An instance of a template engine class
574 protected final function getTemplateInstance () {
575 return $this->templateInstance;
579 * Setter for search instance
581 * @param $searchInstance Searchable criteria instance
584 public final function setSearchInstance (LocalSearchCriteria $searchInstance) {
585 $this->searchInstance = $searchInstance;
589 * Getter for search instance
591 * @return $searchInstance Searchable criteria instance
593 public final function getSearchInstance () {
594 return $this->searchInstance;
598 * Setter for update instance
600 * @param $updateInstance Searchable criteria instance
603 public final function setUpdateInstance (LocalUpdateCriteria $updateInstance) {
604 $this->updateInstance = $updateInstance;
608 * Getter for update instance
610 * @return $updateInstance Updateable criteria instance
612 public final function getUpdateInstance () {
613 return $this->updateInstance;
617 * Setter for resolver instance
619 * @param $resolverInstance Instance of a command resolver class
622 public final function setResolverInstance (Resolver $resolverInstance) {
623 $this->resolverInstance = $resolverInstance;
627 * Getter for resolver instance
629 * @return $resolverInstance Instance of a command resolver class
631 public final function getResolverInstance () {
632 return $this->resolverInstance;
636 * Setter for language instance
638 * @param $configInstance The configuration instance which shall
639 * be FrameworkConfiguration
642 public final function setConfigInstance (FrameworkConfiguration $configInstance) {
643 Registry::getRegistry()->addInstance('config', $configInstance);
647 * Getter for configuration instance
649 * @return $configInstance Configuration instance
651 public final function getConfigInstance () {
652 $configInstance = Registry::getRegistry()->getInstance('config');
653 return $configInstance;
657 * Setter for debug instance
659 * @param $debugInstance The instance for debug output class
662 public final function setDebugInstance (DebugMiddleware $debugInstance) {
663 Registry::getRegistry()->addInstance('debug', $debugInstance);
667 * Getter for debug instance
669 * @return $debugInstance Instance to class DebugConsoleOutput or DebugWebOutput
671 public final function getDebugInstance () {
672 // Get debug instance
673 $debugInstance = Registry::getRegistry()->getInstance('debug');
676 return $debugInstance;
680 * Setter for web output instance
682 * @param $webInstance The instance for web output class
685 public final function setWebOutputInstance (OutputStreamer $webInstance) {
686 Registry::getRegistry()->addInstance('web_output', $webInstance);
690 * Getter for web output instance
692 * @return $webOutputInstance - Instance to class WebOutput
694 public final function getWebOutputInstance () {
695 $webOutputInstance = Registry::getRegistry()->getInstance('web_output');
696 return $webOutputInstance;
700 * Setter for database instance
702 * @param $databaseInstance The instance for the database connection (forced DatabaseConnection)
705 public final function setDatabaseInstance (DatabaseConnection $databaseInstance) {
706 Registry::getRegistry()->addInstance('db_instance', $databaseInstance);
710 * Getter for database layer
712 * @return $databaseInstance The database layer instance
714 public final function getDatabaseInstance () {
716 $databaseInstance = Registry::getRegistry()->getInstance('db_instance');
719 return $databaseInstance;
723 * Setter for compressor channel
725 * @param $compressorInstance An instance of CompressorChannel
728 public final function setCompressorChannel (CompressorChannel $compressorInstance) {
729 Registry::getRegistry()->addInstance('compressor', $compressorInstance);
733 * Getter for compressor channel
735 * @return $compressorInstance The compressor channel
737 public final function getCompressorChannel () {
738 $compressorInstance = Registry::getRegistry()->getInstance('compressor');
739 return $compressorInstance;
743 * Protected getter for a manageable application helper class
745 * @return $applicationInstance An instance of a manageable application helper class
747 protected final function getApplicationInstance () {
748 $applicationInstance = Registry::getRegistry()->getInstance('application');
749 return $applicationInstance;
753 * Setter for a manageable application helper class
755 * @param $applicationInstance An instance of a manageable application helper class
758 public final function setApplicationInstance (ManageableApplication $applicationInstance) {
759 Registry::getRegistry()->addInstance('application', $applicationInstance);
763 * Setter for request instance
765 * @param $requestInstance An instance of a Requestable class
768 public final function setRequestInstance (Requestable $requestInstance) {
769 $this->requestInstance = $requestInstance;
773 * Getter for request instance
775 * @return $requestInstance An instance of a Requestable class
777 public final function getRequestInstance () {
778 return $this->requestInstance;
782 * Setter for response instance
784 * @param $responseInstance An instance of a Responseable class
787 public final function setResponseInstance (Responseable $responseInstance) {
788 $this->responseInstance = $responseInstance;
792 * Getter for response instance
794 * @return $responseInstance An instance of a Responseable class
796 public final function getResponseInstance () {
797 return $this->responseInstance;
801 * Private getter for language instance
803 * @return $langInstance An instance to the language sub-system
805 protected final function getLanguageInstance () {
806 $langInstance = Registry::getRegistry()->getInstance('language');
807 return $langInstance;
811 * Setter for language instance
813 * @param $langInstance An instance to the language sub-system
815 * @see LanguageSystem
817 public final function setLanguageInstance (ManageableLanguage $langInstance) {
818 Registry::getRegistry()->addInstance('language', $langInstance);
822 * Private getter for file IO instance
824 * @return $fileIoInstance An instance to the file I/O sub-system
826 protected final function getFileIoInstance () {
827 return $this->fileIoInstance;
831 * Setter for file I/O instance
833 * @param $fileIoInstance An instance to the file I/O sub-system
836 public final function setFileIoInstance (IoHandler $fileIoInstance) {
837 $this->fileIoInstance = $fileIoInstance;
841 * Protected setter for user instance
843 * @param $userInstance An instance of a user class
846 protected final function setUserInstance (ManageableAccount $userInstance) {
847 $this->userInstance = $userInstance;
851 * Getter for user instance
853 * @return $userInstance An instance of a user class
855 public final function getUserInstance () {
856 return $this->userInstance;
860 * Setter for controller instance (this surely breaks a bit the MVC patterm)
862 * @param $controllerInstance An instance of the controller
865 public final function setControllerInstance (Controller $controllerInstance) {
866 $this->controllerInstance = $controllerInstance;
870 * Getter for controller instance (this surely breaks a bit the MVC patterm)
872 * @return $controllerInstance An instance of the controller
874 public final function getControllerInstance () {
875 return $this->controllerInstance;
879 * Setter for RNG instance
881 * @param $rngInstance An instance of a random number generator (RNG)
884 protected final function setRngInstance (RandomNumberGenerator $rngInstance) {
885 $this->rngInstance = $rngInstance;
889 * Getter for RNG instance
891 * @return $rngInstance An instance of a random number generator (RNG)
893 public final function getRngInstance () {
894 return $this->rngInstance;
898 * Setter for Cryptable instance
900 * @param $cryptoInstance An instance of a Cryptable class
903 protected final function setCryptoInstance (Cryptable $cryptoInstance) {
904 $this->cryptoInstance = $cryptoInstance;
908 * Getter for Cryptable instance
910 * @return $cryptoInstance An instance of a Cryptable class
912 public final function getCryptoInstance () {
913 return $this->cryptoInstance;
917 * Setter for the list instance
919 * @param $listInstance A list of Listable
922 protected final function setListInstance (Listable $listInstance) {
923 $this->listInstance = $listInstance;
927 * Getter for the list instance
929 * @return $listInstance A list of Listable
931 protected final function getListInstance () {
932 return $this->listInstance;
936 * Setter for the menu instance
938 * @param $menuInstance A RenderableMenu instance
941 protected final function setMenuInstance (RenderableMenu $menuInstance) {
942 $this->menuInstance = $menuInstance;
946 * Getter for the menu instance
948 * @return $menuInstance A RenderableMenu instance
950 protected final function getMenuInstance () {
951 return $this->menuInstance;
955 * Setter for image instance
957 * @param $imageInstance An instance of an image
960 public final function setImageInstance (BaseImage $imageInstance) {
961 $this->imageInstance = $imageInstance;
965 * Getter for image instance
967 * @return $imageInstance An instance of an image
969 public final function getImageInstance () {
970 return $this->imageInstance;
974 * Setter for stacker instance
976 * @param $stackInstance An instance of an stacker
979 public final function setStackInstance (Stackable $stackInstance) {
980 $this->stackInstance = $stackInstance;
984 * Getter for stacker instance
986 * @return $stackInstance An instance of an stacker
988 public final function getStackInstance () {
989 return $this->stackInstance;
993 * Setter for compressor instance
995 * @param $compressorInstance An instance of an compressor
998 public final function setCompressorInstance (Compressor $compressorInstance) {
999 $this->compressorInstance = $compressorInstance;
1003 * Getter for compressor instance
1005 * @return $compressorInstance An instance of an compressor
1007 public final function getCompressorInstance () {
1008 return $this->compressorInstance;
1012 * Setter for Parseable instance
1014 * @param $parserInstance An instance of an Parseable
1017 public final function setParserInstance (Parseable $parserInstance) {
1018 $this->parserInstance = $parserInstance;
1022 * Getter for Parseable instance
1024 * @return $parserInstance An instance of an Parseable
1026 public final function getParserInstance () {
1027 return $this->parserInstance;
1031 * Setter for HandleableProtocol instance
1033 * @param $protocolInstance An instance of an HandleableProtocol
1036 public final function setProtocolInstance (HandleableProtocol $protocolInstance = NULL) {
1037 $this->protocolInstance = $protocolInstance;
1041 * Getter for HandleableProtocol instance
1043 * @return $protocolInstance An instance of an HandleableProtocol
1045 public final function getProtocolInstance () {
1046 return $this->protocolInstance;
1050 * Setter for DatabaseWrapper instance
1052 * @param $wrapperInstance An instance of an DatabaseWrapper
1055 public final function setWrapperInstance (DatabaseWrapper $wrapperInstance) {
1056 $this->wrapperInstance = $wrapperInstance;
1060 * Getter for DatabaseWrapper instance
1062 * @return $wrapperInstance An instance of an DatabaseWrapper
1064 public final function getWrapperInstance () {
1065 return $this->wrapperInstance;
1069 * Setter for socket resource
1071 * @param $socketResource A valid socket resource
1074 public final function setSocketResource ($socketResource) {
1075 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput($this->__toString() . '::' . __FUNCTION__ . ': socketResource=' . $socketResource . ',previous[' . gettype($this->socketResource) . ']=' . $this->socketResource);
1076 $this->socketResource = $socketResource;
1080 * Getter for socket resource
1082 * @return $socketResource A valid socket resource
1084 public final function getSocketResource () {
1085 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput($this->__toString() . '::' . __FUNCTION__ . ': socketResource[' . gettype($this->socketResource) . ']=' . $this->socketResource);
1086 return $this->socketResource;
1090 * Setter for regular expression
1092 * @param $regularExpression A valid regular expression
1095 public final function setRegularExpression ($regularExpression) {
1096 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput($this->__toString() . '::' . __FUNCTION__ . ': regularExpression=' . $regularExpression . ',previous[' . gettype($this->regularExpression) . ']=' . $this->regularExpression);
1097 $this->regularExpression = $regularExpression;
1101 * Getter for regular expression
1103 * @return $regularExpression A valid regular expression
1105 public final function getRegularExpression () {
1106 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput($this->__toString() . '::' . __FUNCTION__ . ': regularExpression[' . gettype($this->regularExpression) . ']=' . $this->regularExpression);
1107 return $this->regularExpression;
1111 * Setter for helper instance
1113 * @param $helperInstance An instance of a helper class
1116 protected final function setHelperInstance (Helper $helperInstance) {
1117 $this->helperInstance = $helperInstance;
1121 * Getter for helper instance
1123 * @return $helperInstance An instance of a helper class
1125 public final function getHelperInstance () {
1126 return $this->helperInstance;
1130 * Setter for a Sourceable instance
1132 * @param $sourceInstance The Sourceable instance
1135 protected final function setSourceInstance (Sourceable $sourceInstance) {
1136 $this->sourceInstance = $sourceInstance;
1140 * Getter for a Sourceable instance
1142 * @return $sourceInstance The Sourceable instance
1144 protected final function getSourceInstance () {
1145 return $this->sourceInstance;
1149 * Getter for a InputStream instance
1151 * @param $inputStreamInstance The InputStream instance
1153 protected final function getInputStreamInstance () {
1154 return $this->inputStreamInstance;
1158 * Setter for a InputStream instance
1160 * @param $inputStreamInstance The InputStream instance
1163 protected final function setInputStreamInstance (InputStream $inputStreamInstance) {
1164 $this->inputStreamInstance = $inputStreamInstance;
1168 * Getter for a OutputStream instance
1170 * @param $outputStreamInstance The OutputStream instance
1172 protected final function getOutputStreamInstance () {
1173 return $this->outputStreamInstance;
1177 * Setter for a OutputStream instance
1179 * @param $outputStreamInstance The OutputStream instance
1182 protected final function setOutputStreamInstance (OutputStream $outputStreamInstance) {
1183 $this->outputStreamInstance = $outputStreamInstance;
1187 * Setter for handler instance
1189 * @param $handlerInstance An instance of a Handleable class
1192 protected final function setHandlerInstance (Handleable $handlerInstance) {
1193 $this->handlerInstance = $handlerInstance;
1197 * Getter for handler instance
1199 * @return $handlerInstance A Networkable instance
1201 protected final function getHandlerInstance () {
1202 return $this->handlerInstance;
1206 * Setter for visitor instance
1208 * @param $visitorInstance A Visitor instance
1211 protected final function setVisitorInstance (Visitor $visitorInstance) {
1212 $this->visitorInstance = $visitorInstance;
1216 * Getter for visitor instance
1218 * @return $visitorInstance A Visitor instance
1220 protected final function getVisitorInstance () {
1221 return $this->visitorInstance;
1225 * Setter for DHT instance
1227 * @param $dhtInstance A Distributable instance
1230 protected final function setDhtInstance (Distributable $dhtInstance) {
1231 $this->dhtInstance = $dhtInstance;
1235 * Getter for DHT instance
1237 * @return $dhtInstance A Distributable instance
1239 protected final function getDhtInstance () {
1240 return $this->dhtInstance;
1244 * Setter for raw package Data
1246 * @param $packageData Raw package Data
1249 public final function setPackageData (array $packageData) {
1250 $this->packageData = $packageData;
1254 * Getter for raw package Data
1256 * @return $packageData Raw package Data
1258 public function getPackageData () {
1259 return $this->packageData;
1264 * Setter for Iterator instance
1266 * @param $iteratorInstance An instance of an Iterator
1269 protected final function setIteratorInstance (Iterator $iteratorInstance) {
1270 $this->iteratorInstance = $iteratorInstance;
1274 * Getter for Iterator instance
1276 * @return $iteratorInstance An instance of an Iterator
1278 public final function getIteratorInstance () {
1279 return $this->iteratorInstance;
1283 * Setter for FilePointer instance
1285 * @param $pointerInstance An instance of an FilePointer class
1288 protected final function setPointerInstance (FilePointer $pointerInstance) {
1289 $this->pointerInstance = $pointerInstance;
1293 * Getter for FilePointer instance
1295 * @return $pointerInstance An instance of an FilePointer class
1297 public final function getPointerInstance () {
1298 return $this->pointerInstance;
1302 * Setter for Indexable instance
1304 * @param $indexInstance An instance of an Indexable class
1307 protected final function setIndexInstance (Indexable $indexInstance) {
1308 $this->indexInstance = $indexInstance;
1312 * Getter for Indexable instance
1314 * @return $indexInstance An instance of an Indexable class
1316 public final function getIndexInstance () {
1317 return $this->indexInstance;
1321 * Setter for Block instance
1323 * @param $blockInstance An instance of an Block class
1326 protected final function setBlockInstance (Block $blockInstance) {
1327 $this->blockInstance = $blockInstance;
1331 * Getter for Block instance
1333 * @return $blockInstance An instance of an Block class
1335 public final function getBlockInstance () {
1336 return $this->blockInstance;
1340 * Setter for Minable instance
1342 * @param $minableInstance A Minable instance
1345 protected final function setMinableInstance (Minable $minableInstance) {
1346 $this->minableInstance = $minableInstance;
1350 * Getter for minable instance
1352 * @return $minableInstance A Minable instance
1354 protected final function getMinableInstance () {
1355 return $this->minableInstance;
1359 * Setter for FrameworkDirectory instance
1361 * @param $directoryInstance A FrameworkDirectoryPointer instance
1364 protected final function setDirectoryInstance (FrameworkDirectory $directoryInstance) {
1365 $this->directoryInstance = $directoryInstance;
1369 * Getter for FrameworkDirectory instance
1371 * @return $directoryInstance A FrameworkDirectory instance
1373 protected final function getDirectoryInstance () {
1374 return $this->directoryInstance;
1378 * Setter for listener instance
1380 * @param $listenerInstance A Listenable instance
1383 protected final function setListenerInstance (Listenable $listenerInstance) {
1384 $this->listenerInstance = $listenerInstance;
1388 * Getter for listener instance
1390 * @return $listenerInstance A Listenable instance
1392 protected final function getListenerInstance () {
1393 return $this->listenerInstance;
1397 * Checks whether an object equals this object. You should overwrite this
1398 * method to implement own equality checks
1400 * @param $objectInstance An instance of a FrameworkInterface object
1401 * @return $equals Whether both objects equals
1403 public function equals (FrameworkInterface $objectInstance) {
1406 $this->__toString() == $objectInstance->__toString()
1408 $this->hashCode() == $objectInstance->hashCode()
1411 // Return the result
1416 * Generates a generic hash code of this class. You should really overwrite
1417 * this method with your own hash code generator code. But keep KISS in mind.
1419 * @return $hashCode A generic hash code respresenting this whole class
1421 public function hashCode () {
1423 return crc32($this->__toString());
1427 * Formats computer generated price values into human-understandable formats
1428 * with thousand and decimal separators.
1430 * @param $value The in computer format value for a price
1431 * @param $currency The currency symbol (use HTML-valid characters!)
1432 * @param $decNum Number of decimals after commata
1433 * @return $price The for the current language formated price string
1434 * @throws MissingDecimalsThousandsSeparatorException If decimals or
1435 * thousands separator
1438 public function formatCurrency ($value, $currency = '€', $decNum = 2) {
1439 // Are all required attriutes set?
1440 if ((!isset($this->decimals)) || (!isset($this->thousands))) {
1441 // Throw an exception
1442 throw new MissingDecimalsThousandsSeparatorException($this, self::EXCEPTION_ATTRIBUTES_ARE_MISSING);
1446 $value = (float) $value;
1448 // Reformat the US number
1449 $price = number_format($value, $decNum, $this->decimals, $this->thousands) . $currency;
1451 // Return as string...
1456 * Appends a trailing slash to a string
1458 * @param $str A string (maybe) without trailing slash
1459 * @return $str A string with an auto-appended trailing slash
1461 public final function addMissingTrailingSlash ($str) {
1462 // Is there a trailing slash?
1463 if (substr($str, -1, 1) != '/') {
1467 // Return string with trailing slash
1472 * Prepare the template engine (WebTemplateEngine by default) for a given
1473 * application helper instance (ApplicationHelper by default).
1475 * @param $applicationInstance An application helper instance or
1476 * null if we shall use the default
1477 * @return $templateInstance The template engine instance
1478 * @throws NullPointerException If the discovered application
1479 * instance is still null
1481 protected function prepareTemplateInstance (ManageableApplication $applicationInstance = NULL) {
1482 // Is the application instance set?
1483 if (is_null($applicationInstance)) {
1484 // Get the current instance
1485 $applicationInstance = $this->getApplicationInstance();
1488 if (is_null($applicationInstance)) {
1489 // Thrown an exception
1490 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
1494 // Initialize the template engine
1495 $templateInstance = ObjectFactory::createObjectByConfiguredName('web_template_class');
1497 // Return the prepared instance
1498 return $templateInstance;
1502 * Debugs this instance by putting out it's full content
1504 * @param $message Optional message to show in debug output
1507 public final function debugInstance ($message = '') {
1508 // Restore the error handler to avoid trouble with missing array elements or undeclared variables
1509 restore_error_handler();
1514 // Is a message set?
1515 if (!empty($message)) {
1516 // Construct message
1517 $content = sprintf('<div class="debug_message">Message: %s</div>' . PHP_EOL, $message);
1520 // Generate the output
1521 $content .= sprintf('<pre>%s</pre>',
1524 print_r($this, TRUE)
1530 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>',
1531 $this->__toString(),
1533 ClassLoader::getSelfInstance()->getPrintableIncludeList()
1538 * Replaces control characters with printable output
1540 * @param $str String with control characters
1541 * @return $str Replaced string
1543 protected function replaceControlCharacters ($str) {
1546 chr(13), '[r]', str_replace(
1547 chr(10), '[n]', str_replace(
1557 * Output a partial stub message for the caller method
1559 * @param $message An optional message to display
1562 protected function partialStub ($message = '') {
1563 // Get the backtrace
1564 $backtrace = debug_backtrace();
1566 // Generate the class::method string
1567 $methodName = 'UnknownClass->unknownMethod';
1568 if ((isset($backtrace[1]['class'])) && (isset($backtrace[1]['function']))) {
1569 $methodName = $backtrace[1]['class'] . '->' . $backtrace[1]['function'];
1572 // Construct the full message
1573 $stubMessage = sprintf('[%s:] Partial stub!',
1577 // Is the extra message given?
1578 if (!empty($message)) {
1579 // Then add it as well
1580 $stubMessage .= ' Message: ' . $message;
1583 // Debug instance is there?
1584 if (!is_null($this->getDebugInstance())) {
1585 // Output stub message
1586 self::createDebugInstance(__CLASS__)->debugOutput($stubMessage);
1589 trigger_error($stubMessage);
1595 * Outputs a debug backtrace and stops further script execution
1597 * @param $message An optional message to output
1598 * @param $doExit Whether exit the program (TRUE is default)
1601 public function debugBackTrace ($message = '', $doExit = TRUE) {
1602 // Sorry, there is no other way getting this nice backtrace
1603 if (!empty($message)) {
1605 printf('Message: %s<br />' . chr(10), $message);
1609 debug_print_backtrace();
1613 if ($doExit === TRUE) {
1619 * Creates an instance of a debugger instance
1621 * @param $className Name of the class (currently unsupported)
1622 * @return $debugInstance An instance of a debugger class
1624 public final static function createDebugInstance ($className) {
1625 // Is the instance set?
1626 if (!Registry::getRegistry()->instanceExists('debug')) {
1627 // Init debug instance
1628 $debugInstance = NULL;
1632 // Get a debugger instance
1633 $debugInstance = DebugMiddleware::createDebugMiddleware(FrameworkConfiguration::getSelfInstance()->getConfigEntry('debug_class'));
1634 } catch (NullPointerException $e) {
1635 // Didn't work, no instance there
1636 exit('Cannot create debugInstance! Exception=' . $e->__toString() . ', message=' . $e->getMessage());
1639 // Empty string should be ignored and used for testing the middleware
1640 DebugMiddleware::getSelfInstance()->output('');
1642 // Set it in its own class. This will set it in the registry
1643 $debugInstance->setDebugInstance($debugInstance);
1645 // Get instance from registry
1646 $debugInstance = Registry::getRegistry()->getDebugInstance();
1650 return $debugInstance;
1654 * Simple output of a message with line-break
1656 * @param $message Message to output
1659 public function outputLine ($message) {
1661 print($message . PHP_EOL);
1665 * Outputs a debug message whether to debug instance (should be set!) or
1666 * dies with or ptints the message. Do NEVER EVER rewrite the exit() call to
1667 * ApplicationEntryPoint::app_exit(), this would cause an endless loop.
1669 * @param $message Message we shall send out...
1670 * @param $doPrint Whether print or die here (default: print)
1671 * @paran $stripTags Whether to strip tags (default: FALSE)
1674 public function debugOutput ($message, $doPrint = TRUE, $stripTags = FALSE) {
1675 // Set debug instance to NULL
1676 $debugInstance = NULL;
1680 // Get debug instance
1681 $debugInstance = $this->getDebugInstance();
1682 } catch (NullPointerException $e) {
1683 // The debug instance is not set (yet)
1686 // Is the debug instance there?
1687 if (is_object($debugInstance)) {
1688 // Use debug output handler
1689 $debugInstance->output($message, $stripTags);
1691 if ($doPrint === FALSE) {
1692 // Die here if not printed
1696 // Are debug times enabled?
1697 if ($this->getConfigInstance()->getConfigEntry('debug_output_timings') == 'Y') {
1699 $message = $this->getPrintableExecutionTime() . $message;
1703 if ($doPrint === TRUE) {
1705 $this->outputLine($message);
1714 * Converts e.g. a command from URL to a valid class by keeping out bad characters
1716 * @param $str The string, what ever it is needs to be converted
1717 * @return $className Generated class name
1719 public function convertToClassName ($str) {
1723 // Convert all dashes in underscores
1724 $str = $this->convertDashesToUnderscores($str);
1726 // Now use that underscores to get classname parts for hungarian style
1727 foreach (explode('_', $str) as $strPart) {
1728 // Make the class name part lower case and first upper case
1729 $className .= ucfirst(strtolower($strPart));
1732 // Return class name
1737 * Converts dashes to underscores, e.g. useable for configuration entries
1739 * @param $str The string with maybe dashes inside
1740 * @return $str The converted string with no dashed, but underscores
1742 public final function convertDashesToUnderscores ($str) {
1744 $str = str_replace('-', '_', $str);
1746 // Return converted string
1751 * Marks up the code by adding e.g. line numbers
1753 * @param $phpCode Unmarked PHP code
1754 * @return $markedCode Marked PHP code
1756 public function markupCode ($phpCode) {
1761 $errorArray = error_get_last();
1763 // Init the code with error message
1764 if (is_array($errorArray)) {
1766 $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>',
1767 basename($errorArray['file']),
1768 $errorArray['line'],
1769 $errorArray['message'],
1774 // Add line number to the code
1775 foreach (explode(chr(10), $phpCode) as $lineNo => $code) {
1777 $markedCode .= sprintf('<span id="code_line">%s</span>: %s' . chr(10),
1779 htmlentities($code, ENT_QUOTES)
1788 * Filter a given GMT timestamp (non Uni* stamp!) to make it look more
1789 * beatiful for web-based front-ends. If null is given a message id
1790 * null_timestamp will be resolved and returned.
1792 * @param $timestamp Timestamp to prepare (filter) for display
1793 * @return $readable A readable timestamp
1795 public function doFilterFormatTimestamp ($timestamp) {
1796 // Default value to return
1799 // Is the timestamp null?
1800 if (is_null($timestamp)) {
1801 // Get a message string
1802 $readable = $this->getLanguageInstance()->getMessage('null_timestamp');
1804 switch ($this->getLanguageInstance()->getLanguageCode()) {
1805 case 'de': // German format is a bit different to default
1806 // Split the GMT stamp up
1807 $dateTime = explode(' ', $timestamp );
1808 $dateArray = explode('-', $dateTime[0]);
1809 $timeArray = explode(':', $dateTime[1]);
1811 // Construct the timestamp
1812 $readable = sprintf($this->getConfigInstance()->getConfigEntry('german_date_time'),
1822 default: // Default is pass-through
1823 $readable = $timestamp;
1833 * Filter a given number into a localized number
1835 * @param $value The raw value from e.g. database
1836 * @return $localized Localized value
1838 public function doFilterFormatNumber ($value) {
1839 // Generate it from config and localize dependencies
1840 switch ($this->getLanguageInstance()->getLanguageCode()) {
1841 case 'de': // German format is a bit different to default
1842 $localized = number_format($value, $this->getConfigInstance()->getConfigEntry('decimals'), ',', '.');
1845 default: // US, etc.
1846 $localized = number_format($value, $this->getConfigInstance()->getConfigEntry('decimals'), '.', ',');
1855 * "Getter" for databse entry
1857 * @return $entry An array with database entries
1858 * @throws NullPointerException If the database result is not found
1859 * @throws InvalidDatabaseResultException If the database result is invalid
1861 protected final function getDatabaseEntry () {
1862 // Is there an instance?
1863 if (is_null($this->getResultInstance())) {
1864 // Throw an exception here
1865 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
1869 $this->getResultInstance()->rewind();
1871 // Do we have an entry?
1872 if ($this->getResultInstance()->valid() === FALSE) {
1873 throw new InvalidDatabaseResultException(array($this, $this->getResultInstance()), DatabaseResult::EXCEPTION_INVALID_DATABASE_RESULT);
1877 $this->getResultInstance()->next();
1880 $entry = $this->getResultInstance()->current();
1887 * Getter for field name
1889 * @param $fieldName Field name which we shall get
1890 * @return $fieldValue Field value from the user
1891 * @throws NullPointerException If the result instance is null
1893 public final function getField ($fieldName) {
1894 // Default field value
1897 // Get result instance
1898 $resultInstance = $this->getResultInstance();
1900 // Is this instance null?
1901 if (is_null($resultInstance)) {
1902 // Then the user instance is no longer valid (expired cookies?)
1903 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
1906 // Get current array
1907 $fieldArray = $resultInstance->current();
1908 //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput($fieldName.':<pre>'.print_r($fieldArray, TRUE).'</pre>');
1910 // Convert dashes to underscore
1911 $fieldName = $this->convertDashesToUnderscores($fieldName);
1913 // Does the field exist?
1914 if (isset($fieldArray[$fieldName])) {
1916 $fieldValue = $fieldArray[$fieldName];
1918 // Missing field entry, may require debugging
1919 self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']:fieldName=' . $fieldName . ' not found!');
1927 * Flushs all pending updates to the database layer
1931 public function flushPendingUpdates () {
1932 // Get result instance
1933 $resultInstance = $this->getResultInstance();
1935 // Do we have data to update?
1936 if ((is_object($resultInstance)) && ($resultInstance->ifDataNeedsFlush())) {
1937 // Get wrapper class name config entry
1938 $configEntry = $resultInstance->getUpdateInstance()->getWrapperConfigEntry();
1940 // Create object instance
1941 $wrapperInstance = ObjectFactory::createObjectByConfiguredName($configEntry);
1943 // Yes, then send the whole result to the database layer
1944 $wrapperInstance->doUpdateByResult($this->getResultInstance());
1949 * Outputs a deprecation warning to the developer.
1951 * @param $message The message we shall output to the developer
1953 * @todo Write a logging mechanism for productive mode
1955 public function deprecationWarning ($message) {
1956 // Is developer mode active?
1957 if (defined('DEVELOPER')) {
1958 // Debug instance is there?
1959 if (!is_null($this->getDebugInstance())) {
1960 // Output stub message
1961 self::createDebugInstance(__CLASS__)->debugOutput($message);
1964 trigger_error($message . "<br />\n");
1968 // @TODO Finish this part!
1969 $this->partialStub('Developer mode inactive. Message:' . $message);
1974 * Checks whether the given PHP extension is loaded
1976 * @param $phpExtension The PHP extension we shall check
1977 * @return $isLoaded Whether the PHP extension is loaded
1979 public final function isPhpExtensionLoaded ($phpExtension) {
1981 $isLoaded = in_array($phpExtension, get_loaded_extensions());
1988 * "Getter" as a time() replacement but with milliseconds. You should use this
1989 * method instead of the encapsulated getimeofday() function.
1991 * @return $milliTime Timestamp with milliseconds
1993 public function getMilliTime () {
1994 // Get the time of day as float
1995 $milliTime = gettimeofday(TRUE);
2002 * Idles (sleeps) for given milliseconds
2004 * @return $hasSlept Whether it goes fine
2006 public function idle ($milliSeconds) {
2007 // Sleep is fine by default
2010 // Idle so long with found function
2011 if (function_exists('time_sleep_until')) {
2012 // Get current time and add idle time
2013 $sleepUntil = $this->getMilliTime() + abs($milliSeconds) / 1000;
2015 // New PHP 5.1.0 function found, ignore errors
2016 $hasSlept = @time_sleep_until($sleepUntil);
2019 * My Sun station doesn't have that function even with latest PHP
2022 usleep($milliSeconds * 1000);
2029 * Converts a hexadecimal string, even with negative sign as first string to
2030 * a decimal number using BC functions.
2032 * This work is based on comment #86673 on php.net documentation page at:
2033 * <http://de.php.net/manual/en/function.dechex.php#86673>
2035 * @param $hex Hexadecimal string
2036 * @return $dec Decimal number
2038 protected function hex2dec ($hex) {
2039 // Convert to all lower-case
2040 $hex = strtolower($hex);
2042 // Detect sign (negative/positive numbers)
2044 if (substr($hex, 0, 1) == '-') {
2046 $hex = substr($hex, 1);
2049 // Decode the hexadecimal string into a decimal number
2051 for ($i = strlen($hex) - 1, $e = 1; $i >= 0; $i--, $e = bcmul($e, 16)) {
2052 $factor = self::$hexdec[substr($hex, $i, 1)];
2053 $dec = bcadd($dec, bcmul($factor, $e));
2056 // Return the decimal number
2057 return $sign . $dec;
2061 * Converts even very large decimal numbers, also signed, to a hexadecimal
2064 * This work is based on comment #97756 on php.net documentation page at:
2065 * <http://de.php.net/manual/en/function.hexdec.php#97756>
2067 * @param $dec Decimal number, even with negative sign
2068 * @param $maxLength Optional maximum length of the string
2069 * @return $hex Hexadecimal string
2071 protected function dec2hex ($dec, $maxLength = 0) {
2072 // maxLength can be zero or devideable by 2
2073 assert(($maxLength == 0) || (($maxLength % 2) == 0));
2075 // Detect sign (negative/positive numbers)
2082 // Encode the decimal number into a hexadecimal string
2085 $hex = self::$dechex[($dec % (2 ^ 4))] . $hex;
2087 } while ($dec >= 1);
2090 * Leading zeros are required for hex-decimal "numbers". In some
2091 * situations more leading zeros are wanted, so check for both
2094 if ($maxLength > 0) {
2095 // Prepend more zeros
2096 $hex = str_pad($hex, $maxLength, '0', STR_PAD_LEFT);
2097 } elseif ((strlen($hex) % 2) != 0) {
2098 // Only make string's length dividable by 2
2102 // Return the hexadecimal string
2103 return $sign . $hex;
2107 * Converts a ASCII string (0 to 255) into a decimal number.
2109 * @param $asc The ASCII string to be converted
2110 * @return $dec Decimal number
2112 protected function asc2dec ($asc) {
2113 // Convert it into a hexadecimal number
2114 $hex = bin2hex($asc);
2116 // And back into a decimal number
2117 $dec = $this->hex2dec($hex);
2124 * Converts a decimal number into an ASCII string.
2126 * @param $dec Decimal number
2127 * @return $asc An ASCII string
2129 protected function dec2asc ($dec) {
2130 // First convert the number into a hexadecimal string
2131 $hex = $this->dec2hex($dec);
2133 // Then convert it into the ASCII string
2134 $asc = $this->hex2asc($hex);
2141 * Converts a hexadecimal number into an ASCII string. Negative numbers
2144 * @param $hex Hexadecimal string
2145 * @return $asc An ASCII string
2147 protected function hex2asc ($hex) {
2148 // Check for length, it must be devideable by 2
2149 //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('hex='.$hex);
2150 assert((strlen($hex) % 2) == 0);
2154 for ($idx = 0; $idx < strlen($hex); $idx+=2) {
2155 // Get the decimal number of the chunk
2156 $part = hexdec(substr($hex, $idx, 2));
2158 // Add it to the final string
2162 // Return the final string
2167 * Checks whether the given encoded data was encoded with Base64
2169 * @param $encodedData Encoded data we shall check
2170 * @return $isBase64 Whether the encoded data is Base64
2172 protected function isBase64Encoded ($encodedData) {
2174 $isBase64 = (@base64_decode($encodedData, TRUE) !== FALSE);
2181 * "Getter" to get response/request type from analysis of the system.
2183 * @return $responseType Analyzed response type
2185 protected function getResponseTypeFromSystem () {
2186 // Default is console
2187 $responseType = 'console';
2189 // Is 'HTTP_HOST' set?
2190 if (isset($_SERVER['HTTP_HOST'])) {
2191 // Then it is a HTTP response/request
2192 $responseType = 'http';
2196 return $responseType;
2200 * Gets a cache key from Criteria instance
2202 * @param $criteriaInstance An instance of a Criteria class
2203 * @param $onlyKeys Only use these keys for a cache key
2204 * @return $cacheKey A cache key suitable for lookup/storage purposes
2206 protected function getCacheKeyByCriteria (Criteria $criteriaInstance, array $onlyKeys = array()) {
2208 $cacheKey = sprintf('%s@%s',
2209 $this->__toString(),
2210 $criteriaInstance->getCacheKey($onlyKeys)
2214 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput($this->__toString() . ': cacheKey=' . $cacheKey);
2219 * Getter for startup time in miliseconds
2221 * @return $startupTime Startup time in miliseconds
2223 protected function getStartupTime () {
2224 return self::$startupTime;
2228 * "Getter" for a printable currently execution time in nice braces
2230 * @return $executionTime Current execution time in nice braces
2232 protected function getPrintableExecutionTime () {
2233 // Caculate the execution time
2234 $executionTime = microtime(TRUE) - $this->getStartupTime();
2236 // Pack it in nice braces
2237 $executionTime = sprintf('[ %01.5f ] ', $executionTime);
2240 return $executionTime;
2244 * Hashes a given string with a simple but stronger hash function (no salt)
2245 * and hex-encode it.
2247 * @param $str The string to be hashed
2248 * @return $hash The hash from string $str
2250 public static final function hash ($str) {
2251 // Hash given string with (better secure) hasher
2252 $hash = bin2hex(mhash(MHASH_SHA256, $str));
2259 * "Getter" for length of hash() output. This will be "cached" to speed up
2262 * @return $length Length of hash() output
2264 public static final function getHashLength () {
2266 if (is_null(self::$hashLength)) {
2267 // No, then hash a string and save its length.
2268 self::$hashLength = strlen(self::hash('abc123'));
2272 return self::$hashLength;
2276 * Checks whether the given number is really a number (only chars 0-9).
2278 * @param $num A string consisting only chars between 0 and 9
2279 * @param $castValue Whether to cast the value to double. Do only use this to secure numbers from Requestable classes.
2280 * @param $assertMismatch Whether to assert mismatches
2281 * @return $ret The (hopefully) secured numbered value
2283 public function bigintval ($num, $castValue = TRUE, $assertMismatch = FALSE) {
2284 // Filter all numbers out
2285 $ret = preg_replace('/[^0123456789]/', '', $num);
2288 if ($castValue === TRUE) {
2289 // Cast to biggest numeric type
2290 $ret = (double) $ret;
2293 // Assert only if requested
2294 if ($assertMismatch === TRUE) {
2295 // Has the whole value changed?
2296 assert(('' . $ret . '' != '' . $num . '') && (!is_null($num)));
2304 * Checks whether the given hexadecimal number is really a hex-number (only chars 0-9,a-f).
2306 * @param $num A string consisting only chars between 0 and 9
2307 * @param $assertMismatch Whether to assert mismatches
2308 * @return $ret The (hopefully) secured hext-numbered value
2310 public function hexval ($num, $assertMismatch = FALSE) {
2311 // Filter all numbers out
2312 $ret = preg_replace('/[^0123456789abcdefABCDEF]/', '', $num);
2314 // Assert only if requested
2315 if ($assertMismatch === TRUE) {
2316 // Has the whole value changed?
2317 assert(('' . $ret . '' != '' . $num . '') && (!is_null($num)));
2325 * Checks whether start/end marker are set
2327 * @param $data Data to be checked
2328 * @return $isset Whether start/end marker are set
2330 public final function ifStartEndMarkersSet ($data) {
2332 $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));
2334 // ... and return it
2339 * Determines if an element is set in the generic array
2341 * @param $keyGroup Main group for the key
2342 * @param $subGroup Sub group for the key
2343 * @param $key Key to check
2344 * @param $element Element to check
2345 * @return $isset Whether the given key is set
2347 protected final function isGenericArrayElementSet ($keyGroup, $subGroup, $key, $element) {
2349 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element);
2352 $isset = isset($this->genericArray[$keyGroup][$subGroup][$key][$element]);
2358 * Determines if a key is set in the generic array
2360 * @param $keyGroup Main group for the key
2361 * @param $subGroup Sub group for the key
2362 * @param $key Key to check
2363 * @return $isset Whether the given key is set
2365 protected final function isGenericArrayKeySet ($keyGroup, $subGroup, $key) {
2367 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
2370 $isset = isset($this->genericArray[$keyGroup][$subGroup][$key]);
2378 * Determines if a group is set in the generic array
2380 * @param $keyGroup Main group
2381 * @param $subGroup Sub group
2382 * @return $isset Whether the given group is set
2384 protected final function isGenericArrayGroupSet ($keyGroup, $subGroup) {
2386 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup);
2389 $isset = isset($this->genericArray[$keyGroup][$subGroup]);
2396 * Getter for sub key group
2398 * @param $keyGroup Main key group
2399 * @param $subGroup Sub key group
2400 * @return $array An array with all array elements
2402 protected final function getGenericSubArray ($keyGroup, $subGroup) {
2404 if (!$this->isGenericArrayGroupSet($keyGroup, $subGroup)) {
2405 // No, then abort here
2406 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' not found.');
2411 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',value=' . print_r($this->genericArray[$keyGroup][$subGroup], TRUE));
2414 return $this->genericArray[$keyGroup][$subGroup];
2418 * Unsets a given key in generic array
2420 * @param $keyGroup Main group for the key
2421 * @param $subGroup Sub group for the key
2422 * @param $key Key to unset
2425 protected final function unsetGenericArrayKey ($keyGroup, $subGroup, $key) {
2427 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
2430 unset($this->genericArray[$keyGroup][$subGroup][$key]);
2434 * Unsets a given element in generic array
2436 * @param $keyGroup Main group for the key
2437 * @param $subGroup Sub group for the key
2438 * @param $key Key to unset
2439 * @param $element Element to unset
2442 protected final function unsetGenericArrayElement ($keyGroup, $subGroup, $key, $element) {
2444 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element);
2447 unset($this->genericArray[$keyGroup][$subGroup][$key][$element]);
2451 * Append a string to a given generic array key
2453 * @param $keyGroup Main group for the key
2454 * @param $subGroup Sub group for the key
2455 * @param $key Key to unset
2456 * @param $value Value to add/append
2459 protected final function appendStringToGenericArrayKey ($keyGroup, $subGroup, $key, $value, $appendGlue = '') {
2461 //* 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);
2463 // Is it already there?
2464 if ($this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
2466 $this->genericArray[$keyGroup][$subGroup][$key] .= $appendGlue . (string) $value;
2469 $this->genericArray[$keyGroup][$subGroup][$key] = (string) $value;
2474 * Append a string to a given generic array element
2476 * @param $keyGroup Main group for the key
2477 * @param $subGroup Sub group for the key
2478 * @param $key Key to unset
2479 * @param $element Element to check
2480 * @param $value Value to add/append
2483 protected final function appendStringToGenericArrayElement ($keyGroup, $subGroup, $key, $element, $value, $appendGlue = '') {
2485 //* 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);
2487 // Is it already there?
2488 if ($this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element)) {
2490 $this->genericArray[$keyGroup][$subGroup][$key][$element] .= $appendGlue . (string) $value;
2493 $this->genericArray[$keyGroup][$subGroup][$key][$element] = (string) $value;
2498 * Initializes given generic array group
2500 * @param $keyGroup Main group for the key
2501 * @param $subGroup Sub group for the key
2502 * @param $key Key to use
2503 * @param $forceInit Optionally force initialization
2506 protected final function initGenericArrayGroup ($keyGroup, $subGroup, $forceInit = FALSE) {
2508 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',forceInit=' . intval($forceInit));
2510 // Is it already set?
2511 if (($forceInit === FALSE) && ($this->isGenericArrayGroupSet($keyGroup, $subGroup))) {
2512 // Already initialized
2513 trigger_error(__METHOD__ . ':keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' already initialized.');
2518 $this->genericArray[$keyGroup][$subGroup] = array();
2522 * Initializes given generic array key
2524 * @param $keyGroup Main group for the key
2525 * @param $subGroup Sub group for the key
2526 * @param $key Key to use
2527 * @param $forceInit Optionally force initialization
2530 protected final function initGenericArrayKey ($keyGroup, $subGroup, $key, $forceInit = FALSE) {
2532 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',forceInit=' . intval($forceInit));
2534 // Is it already set?
2535 if (($forceInit === FALSE) && ($this->isGenericArrayKeySet($keyGroup, $subGroup, $key))) {
2536 // Already initialized
2537 trigger_error(__METHOD__ . ':keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' already initialized.');
2542 $this->genericArray[$keyGroup][$subGroup][$key] = array();
2546 * Initializes given generic array element
2548 * @param $keyGroup Main group for the key
2549 * @param $subGroup Sub group for the key
2550 * @param $key Key to use
2551 * @param $element Element to use
2552 * @param $forceInit Optionally force initialization
2555 protected final function initGenericArrayElement ($keyGroup, $subGroup, $key, $element, $forceInit = FALSE) {
2557 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element . ',forceInit=' . intval($forceInit));
2559 // Is it already set?
2560 if (($forceInit === FALSE) && ($this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element))) {
2561 // Already initialized
2562 trigger_error(__METHOD__ . ':keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element . ' already initialized.');
2567 $this->genericArray[$keyGroup][$subGroup][$key][$element] = array();
2571 * Pushes an element to a generic key
2573 * @param $keyGroup Main group for the key
2574 * @param $subGroup Sub group for the key
2575 * @param $key Key to use
2576 * @param $value Value to add/append
2577 * @return $count Number of array elements
2579 protected final function pushValueToGenericArrayKey ($keyGroup, $subGroup, $key, $value) {
2581 //* NOISY-DEBUG: */ if (!is_object($value)) $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',value[' . gettype($value) . ']=' . print_r($value, TRUE));
2584 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
2586 $this->initGenericArrayKey($keyGroup, $subGroup, $key);
2590 $count = array_push($this->genericArray[$keyGroup][$subGroup][$key], $value);
2593 //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], TRUE));
2594 //* DEBUG: */ print(__METHOD__ . ': count=' . $count . PHP_EOL);
2599 * Pushes an element to a generic array element
2601 * @param $keyGroup Main group for the key
2602 * @param $subGroup Sub group for the key
2603 * @param $key Key to use
2604 * @param $element Element to check
2605 * @param $value Value to add/append
2606 * @return $count Number of array elements
2608 protected final function pushValueToGenericArrayElement ($keyGroup, $subGroup, $key, $element, $value) {
2610 //* 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));
2613 if (!$this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element)) {
2615 $this->initGenericArrayElement($keyGroup, $subGroup, $key, $element);
2619 $count = array_push($this->genericArray[$keyGroup][$subGroup][$key][$element], $value);
2622 //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], TRUE));
2623 //* DEBUG: */ print(__METHOD__ . ': count=' . $count . PHP_EOL);
2628 * Pops an element from a generic group
2630 * @param $keyGroup Main group for the key
2631 * @param $subGroup Sub group for the key
2632 * @param $key Key to unset
2633 * @return $value Last "popped" value
2635 protected final function popGenericArrayElement ($keyGroup, $subGroup, $key) {
2637 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
2640 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
2642 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' not found.');
2647 $value = array_pop($this->genericArray[$keyGroup][$subGroup][$key]);
2650 //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], TRUE));
2651 //* DEBUG: */ print(__METHOD__ . ': value[' . gettype($value) . ']=' . print_r($value, TRUE) . PHP_EOL);
2656 * Shifts an element from a generic group
2658 * @param $keyGroup Main group for the key
2659 * @param $subGroup Sub group for the key
2660 * @param $key Key to unset
2661 * @return $value Last "popped" value
2663 protected final function shiftGenericArrayElement ($keyGroup, $subGroup, $key) {
2665 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
2668 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
2670 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' not found.');
2675 $value = array_shift($this->genericArray[$keyGroup][$subGroup][$key]);
2678 //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], TRUE));
2679 //* DEBUG: */ print(__METHOD__ . ': value[' . gettype($value) . ']=' . print_r($value, TRUE) . PHP_EOL);
2684 * Count generic array group
2686 * @param $keyGroup Main group for the key
2687 * @return $count Count of given group
2689 protected final function countGenericArray ($keyGroup) {
2691 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup);
2694 if (!isset($this->genericArray[$keyGroup])) {
2696 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ' not found.');
2701 $count = count($this->genericArray[$keyGroup]);
2704 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',count=' . $count);
2711 * Count generic array sub group
2713 * @param $keyGroup Main group for the key
2714 * @param $subGroup Sub group for the key
2715 * @return $count Count of given group
2717 protected final function countGenericArrayGroup ($keyGroup, $subGroup) {
2719 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup);
2722 if (!$this->isGenericArrayGroupSet($keyGroup, $subGroup)) {
2724 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' not found.');
2729 $count = count($this->genericArray[$keyGroup][$subGroup]);
2732 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',count=' . $count);
2739 * Count generic array elements
2741 * @param $keyGroup Main group for the key
2742 * @param $subGroup Sub group for the key
2743 * @para $key Key to count
2744 * @return $count Count of given key
2746 protected final function countGenericArrayElements ($keyGroup, $subGroup, $key) {
2748 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
2751 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
2753 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' not found.');
2755 } elseif (!$this->isValidGenericArrayGroup($keyGroup, $subGroup)) {
2757 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' is not an array.');
2762 $count = count($this->genericArray[$keyGroup][$subGroup][$key]);
2765 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',count=' . $count);
2772 * Getter for whole generic group array
2774 * @param $keyGroup Key group to get
2775 * @return $array Whole generic array group
2777 protected final function getGenericArray ($keyGroup) {
2779 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup);
2782 if (!isset($this->genericArray[$keyGroup])) {
2784 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ' does not exist.');
2789 return $this->genericArray[$keyGroup];
2793 * Setter for generic array key
2795 * @param $keyGroup Key group to get
2796 * @param $subGroup Sub group for the key
2797 * @param $key Key to unset
2798 * @param $value Mixed value from generic array element
2801 protected final function setGenericArrayKey ($keyGroup, $subGroup, $key, $value) {
2803 //* NOISY-DEBUG: */ if (!is_object($value)) $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',value[' . gettype($value) . ']=' . print_r($value, TRUE));
2806 $this->genericArray[$keyGroup][$subGroup][$key] = $value;
2810 * Getter for generic array key
2812 * @param $keyGroup Key group to get
2813 * @param $subGroup Sub group for the key
2814 * @param $key Key to unset
2815 * @return $value Mixed value from generic array element
2817 protected final function getGenericArrayKey ($keyGroup, $subGroup, $key) {
2819 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
2822 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
2824 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' does not exist.');
2829 return $this->genericArray[$keyGroup][$subGroup][$key];
2833 * Sets a value in given generic array key/element
2835 * @param $keyGroup Main group for the key
2836 * @param $subGroup Sub group for the key
2837 * @param $key Key to set
2838 * @param $element Element to set
2839 * @param $value Value to set
2842 protected final function setGenericArrayElement ($keyGroup, $subGroup, $key, $element, $value) {
2844 //* 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));
2847 $this->genericArray[$keyGroup][$subGroup][$key][$element] = $value;
2851 * Getter for generic array element
2853 * @param $keyGroup Key group to get
2854 * @param $subGroup Sub group for the key
2855 * @param $key Key to look for
2856 * @param $element Element to look for
2857 * @return $value Mixed value from generic array element
2859 protected final function getGenericArrayElement ($keyGroup, $subGroup, $key, $element) {
2861 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element);
2864 if (!$this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element)) {
2866 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element . ' does not exist.');
2871 return $this->genericArray[$keyGroup][$subGroup][$key][$element];
2875 * Checks if a given sub group is valid (array)
2877 * @param $keyGroup Key group to get
2878 * @param $subGroup Sub group for the key
2879 * @return $isValid Whether given sub group is valid
2881 protected final function isValidGenericArrayGroup ($keyGroup, $subGroup) {
2883 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup);
2886 $isValid = (($this->isGenericArrayGroupSet($keyGroup, $subGroup)) && (is_array($this->getGenericSubArray($keyGroup, $subGroup))));
2893 * Checks if a given key is valid (array)
2895 * @param $keyGroup Key group to get
2896 * @param $subGroup Sub group for the key
2897 * @param $key Key to check
2898 * @return $isValid Whether given sub group is valid
2900 protected final function isValidGenericArrayKey ($keyGroup, $subGroup, $key) {
2902 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
2905 $isValid = (($this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) && (is_array($this->getGenericArrayKey($keyGroup, $subGroup, $key))));
2912 * Translates boolean TRUE to 'Y' and FALSE to 'N'
2914 * @param $boolean Boolean value
2915 * @return $translated Translated boolean value
2917 public static final function translateBooleanToYesNo ($boolean) {
2918 // Make sure it is really boolean
2919 assert(is_bool($boolean));
2922 $translated = ($boolean === TRUE) ? 'Y' : 'N';
2924 // ... and return it