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 - 2015 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 UrlSource class
154 private $urlSourceInstance = NULL;
157 * An instance of a InputStream class
159 private $inputStreamInstance = NULL;
162 * An instance of a OutputStream class
164 private $outputStreamInstance = NULL;
167 * Networkable handler instance
169 private $handlerInstance = NULL;
172 * Visitor handler instance
174 private $visitorInstance = NULL;
179 private $dhtInstance = NULL;
182 * An instance of a database wrapper class
184 private $wrapperInstance = NULL;
187 * An instance of a file I/O pointer class (not handler)
189 private $pointerInstance = NULL;
192 * An instance of an Indexable class
194 private $indexInstance = NULL;
197 * An instance of a Block class
199 private $blockInstance = NULL;
204 private $minableInstance = NULL;
207 * A FrameworkDirectory instance
209 private $directoryInstance = NULL;
214 private $listenerInstance = NULL;
217 * Thousands separator
219 private $thousands = '.'; // German
224 private $decimals = ','; // German
229 private $socketResource = FALSE;
232 * Regular expression to use for validation
234 private $regularExpression = '';
239 private $packageData = array();
244 private $genericArray = array();
246 /***********************
247 * Exception codes.... *
248 ***********************/
250 // @todo Try to clean these constants up
251 const EXCEPTION_IS_NULL_POINTER = 0x001;
252 const EXCEPTION_IS_NO_OBJECT = 0x002;
253 const EXCEPTION_IS_NO_ARRAY = 0x003;
254 const EXCEPTION_MISSING_METHOD = 0x004;
255 const EXCEPTION_CLASSES_NOT_MATCHING = 0x005;
256 const EXCEPTION_INDEX_OUT_OF_BOUNDS = 0x006;
257 const EXCEPTION_DIMENSION_ARRAY_INVALID = 0x007;
258 const EXCEPTION_ITEM_NOT_TRADEABLE = 0x008;
259 const EXCEPTION_ITEM_NOT_IN_PRICE_LIST = 0x009;
260 const EXCEPTION_GENDER_IS_WRONG = 0x00a;
261 const EXCEPTION_BIRTH_DATE_IS_INVALID = 0x00b;
262 const EXCEPTION_EMPTY_STRUCTURES_ARRAY = 0x00c;
263 const EXCEPTION_HAS_ALREADY_PERSONELL_LIST = 0x00d;
264 const EXCEPTION_NOT_ENOUGTH_UNEMPLOYEES = 0x00e;
265 const EXCEPTION_TOTAL_PRICE_NOT_CALCULATED = 0x00f;
266 const EXCEPTION_HARBOR_HAS_NO_SHIPYARDS = 0x010;
267 const EXCEPTION_CONTRACT_PARTNER_INVALID = 0x011;
268 const EXCEPTION_CONTRACT_PARTNER_MISMATCH = 0x012;
269 const EXCEPTION_CONTRACT_ALREADY_SIGNED = 0x013;
270 const EXCEPTION_UNEXPECTED_EMPTY_STRING = 0x014;
271 const EXCEPTION_PATH_NOT_FOUND = 0x015;
272 const EXCEPTION_INVALID_PATH_NAME = 0x016;
273 const EXCEPTION_READ_PROTECED_PATH = 0x017;
274 const EXCEPTION_WRITE_PROTECED_PATH = 0x018;
275 const EXCEPTION_DIR_POINTER_INVALID = 0x019;
276 const EXCEPTION_FILE_POINTER_INVALID = 0x01a;
277 const EXCEPTION_INVALID_RESOURCE = 0x01b;
278 const EXCEPTION_UNEXPECTED_OBJECT = 0x01c;
279 const EXCEPTION_LIMIT_ELEMENT_IS_UNSUPPORTED = 0x01d;
280 const EXCEPTION_GETTER_IS_MISSING = 0x01e;
281 const EXCEPTION_ARRAY_EXPECTED = 0x01f;
282 const EXCEPTION_ARRAY_HAS_INVALID_COUNT = 0x020;
283 const EXCEPTION_ID_IS_INVALID_FORMAT = 0x021;
284 const EXCEPTION_MD5_CHECKSUMS_MISMATCH = 0x022;
285 const EXCEPTION_UNEXPECTED_STRING_SIZE = 0x023;
286 const EXCEPTION_SIMULATOR_ID_INVALID = 0x024;
287 const EXCEPTION_MISMATCHING_COMPRESSORS = 0x025;
288 const EXCEPTION_CONTAINER_ITEM_IS_NULL = 0x026;
289 const EXCEPTION_ITEM_IS_NO_ARRAY = 0x027;
290 const EXCEPTION_CONTAINER_MAYBE_DAMAGED = 0x028;
291 const EXCEPTION_INVALID_STRING = 0x029;
292 const EXCEPTION_VARIABLE_NOT_SET = 0x02a;
293 const EXCEPTION_ATTRIBUTES_ARE_MISSING = 0x02b;
294 const EXCEPTION_ARRAY_ELEMENTS_MISSING = 0x02c;
295 const EXCEPTION_TEMPLATE_ENGINE_UNSUPPORTED = 0x02d;
296 const EXCEPTION_UNSPPORTED_OPERATION = 0x02e;
297 const EXCEPTION_FACTORY_REQUIRE_PARAMETER = 0x02f;
298 const EXCEPTION_MISSING_ELEMENT = 0x030;
299 const EXCEPTION_HEADERS_ALREADY_SENT = 0x031;
300 const EXCEPTION_DEFAULT_CONTROLLER_GONE = 0x032;
301 const EXCEPTION_CLASS_NOT_FOUND = 0x033;
302 const EXCEPTION_REQUIRED_INTERFACE_MISSING = 0x034;
303 const EXCEPTION_FATAL_ERROR = 0x035;
304 const EXCEPTION_FILE_NOT_FOUND = 0x036;
305 const EXCEPTION_ASSERTION_FAILED = 0x037;
306 const EXCEPTION_FILE_CANNOT_BE_READ = 0x038;
307 const EXCEPTION_DATABASE_UPDATED_NOT_ALLOWED = 0x039;
308 const EXCEPTION_FILTER_CHAIN_INTERCEPTED = 0x03a;
311 * Hexadecimal->Decimal translation array
313 private static $hexdec = array(
333 * Decimal->hexadecimal translation array
335 private static $dechex = array(
355 * Startup time in miliseconds
357 private static $startupTime = 0;
360 * Protected super constructor
362 * @param $className Name of the class
365 protected function __construct ($className) {
367 $this->setRealClass($className);
369 // Set configuration instance if no registry ...
370 if (!$this instanceof Register) {
371 // ... because registries doesn't need to be configured
372 $this->setConfigInstance(FrameworkConfiguration::getSelfInstance());
375 // Is the startup time set? (0 cannot be TRUE anymore)
376 if (self::$startupTime == 0) {
378 self::$startupTime = microtime(TRUE);
383 * Destructor for all classes
387 public function __destruct () {
388 // Flush any updated entries to the database
389 $this->flushPendingUpdates();
391 // Is this object already destroyed?
392 if ($this->__toString() != 'DestructedObject') {
393 // Destroy all informations about this class but keep some text about it alive
394 $this->setRealClass('DestructedObject');
395 } elseif ((defined('DEBUG_DESTRUCTOR')) && (is_object($this->getDebugInstance()))) {
396 // Already destructed object
397 self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:] The object <span class="object_name">%s</span> is already destroyed.',
402 // Do not call this twice
403 trigger_error(__METHOD__ . ': Called twice.');
409 * The __call() method where all non-implemented methods end up
411 * @param $methodName Name of the missing method
412 * @args $args Arguments passed to the method
415 public final function __call ($methodName, $args) {
416 return self::__callStatic($methodName, $args);
420 * The __callStatic() method where all non-implemented static methods end up
422 * @param $methodName Name of the missing method
423 * @args $args Arguments passed to the method
426 public static final function __callStatic ($methodName, $args) {
427 // Init argument string
430 // Is it empty or an array?
433 $argsString = 'NULL';
434 } elseif (is_array($args)) {
435 // Some arguments are there
436 foreach ($args as $arg) {
437 // Add the value itself if not array. This prevents 'array to string conversion' message
438 if (is_array($arg)) {
439 $argsString .= 'Array';
444 // Add data about the argument
445 $argsString .= ' (' . gettype($arg);
447 if (is_string($arg)) {
448 // Add length for strings
449 $argsString .= ', ' . strlen($arg);
450 } elseif (is_array($arg)) {
451 // .. or size if array
452 $argsString .= ', ' . count($arg);
453 } elseif ($arg === TRUE) {
454 // ... is boolean 'TRUE'
455 $argsString .= ', TRUE';
456 } elseif ($arg === FALSE) {
457 // ... is boolean 'FALSE'
458 $argsString .= ', FALSE';
462 $argsString .= '), ';
466 if (substr($argsString, -2, 1) == ',') {
467 $argsString = substr($argsString, 0, -2);
470 // Invalid arguments!
471 $argsString = '!INVALID:' . gettype($args) . '!';
474 // Output stub message
475 // @TODO __CLASS__ does always return BaseFrameworkSystem but not the extending (=child) class
476 self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[unknown::%s:] Stub! Args: %s',
486 * Getter for $realClass
488 * @return $realClass The name of the real class (not BaseFrameworkSystem)
490 public function __toString () {
491 return $this->realClass;
495 * Magic function to catch setting of missing but set class fields/attributes
497 * @param $name Name of the field/attribute
498 * @param $value Value to store
501 public final function __set ($name, $value) {
502 $this->debugBackTrace(sprintf('Tried to set a missing field. name=%s, value[%s]=%s',
505 print_r($value, TRUE)
510 * Magic function to catch getting of missing fields/attributes
512 * @param $name Name of the field/attribute
515 public final function __get ($name) {
516 $this->debugBackTrace(sprintf('Tried to get a missing field. name=%s',
522 * Magic function to catch unsetting of missing fields/attributes
524 * @param $name Name of the field/attribute
527 public final function __unset ($name) {
528 $this->debugBackTrace(sprintf('Tried to unset a missing field. name=%s',
534 * Setter for the real class name
536 * @param $realClass Class name (string)
539 public final function setRealClass ($realClass) {
541 $this->realClass = (string) $realClass;
545 * Setter for database result instance
547 * @param $resultInstance An instance of a database result class
549 * @todo SearchableResult and UpdateableResult shall have a super interface to use here
551 protected final function setResultInstance (SearchableResult $resultInstance) {
552 $this->resultInstance = $resultInstance;
556 * Getter for database result instance
558 * @return $resultInstance An instance of a database result class
560 public final function getResultInstance () {
561 return $this->resultInstance;
565 * Setter for template engine instances
567 * @param $templateInstance An instance of a template engine class
570 protected final function setTemplateInstance (CompileableTemplate $templateInstance) {
571 $this->templateInstance = $templateInstance;
575 * Getter for template engine instances
577 * @return $templateInstance An instance of a template engine class
579 protected final function getTemplateInstance () {
580 return $this->templateInstance;
584 * Setter for search instance
586 * @param $searchInstance Searchable criteria instance
589 public final function setSearchInstance (LocalSearchCriteria $searchInstance) {
590 $this->searchInstance = $searchInstance;
594 * Getter for search instance
596 * @return $searchInstance Searchable criteria instance
598 public final function getSearchInstance () {
599 return $this->searchInstance;
603 * Setter for update instance
605 * @param $updateInstance Searchable criteria instance
608 public final function setUpdateInstance (LocalUpdateCriteria $updateInstance) {
609 $this->updateInstance = $updateInstance;
613 * Getter for update instance
615 * @return $updateInstance Updateable criteria instance
617 public final function getUpdateInstance () {
618 return $this->updateInstance;
622 * Setter for resolver instance
624 * @param $resolverInstance Instance of a command resolver class
627 public final function setResolverInstance (Resolver $resolverInstance) {
628 $this->resolverInstance = $resolverInstance;
632 * Getter for resolver instance
634 * @return $resolverInstance Instance of a command resolver class
636 public final function getResolverInstance () {
637 return $this->resolverInstance;
641 * Setter for language instance
643 * @param $configInstance The configuration instance which shall
644 * be FrameworkConfiguration
647 public final function setConfigInstance (FrameworkConfiguration $configInstance) {
648 Registry::getRegistry()->addInstance('config', $configInstance);
652 * Getter for configuration instance
654 * @return $configInstance Configuration instance
656 public final function getConfigInstance () {
657 $configInstance = Registry::getRegistry()->getInstance('config');
658 return $configInstance;
662 * Setter for debug instance
664 * @param $debugInstance The instance for debug output class
667 public final function setDebugInstance (DebugMiddleware $debugInstance) {
668 Registry::getRegistry()->addInstance('debug', $debugInstance);
672 * Getter for debug instance
674 * @return $debugInstance Instance to class DebugConsoleOutput or DebugWebOutput
676 public final function getDebugInstance () {
677 // Get debug instance
678 $debugInstance = Registry::getRegistry()->getInstance('debug');
681 return $debugInstance;
685 * Setter for web output instance
687 * @param $webInstance The instance for web output class
690 public final function setWebOutputInstance (OutputStreamer $webInstance) {
691 Registry::getRegistry()->addInstance('web_output', $webInstance);
695 * Getter for web output instance
697 * @return $webOutputInstance - Instance to class WebOutput
699 public final function getWebOutputInstance () {
700 $webOutputInstance = Registry::getRegistry()->getInstance('web_output');
701 return $webOutputInstance;
705 * Setter for database instance
707 * @param $databaseInstance The instance for the database connection (forced DatabaseConnection)
710 public final function setDatabaseInstance (DatabaseConnection $databaseInstance) {
711 Registry::getRegistry()->addInstance('db_instance', $databaseInstance);
715 * Getter for database layer
717 * @return $databaseInstance The database layer instance
719 public final function getDatabaseInstance () {
721 $databaseInstance = Registry::getRegistry()->getInstance('db_instance');
724 return $databaseInstance;
728 * Setter for compressor channel
730 * @param $compressorInstance An instance of CompressorChannel
733 public final function setCompressorChannel (CompressorChannel $compressorInstance) {
734 Registry::getRegistry()->addInstance('compressor', $compressorInstance);
738 * Getter for compressor channel
740 * @return $compressorInstance The compressor channel
742 public final function getCompressorChannel () {
743 $compressorInstance = Registry::getRegistry()->getInstance('compressor');
744 return $compressorInstance;
748 * Protected getter for a manageable application helper class
750 * @return $applicationInstance An instance of a manageable application helper class
752 protected final function getApplicationInstance () {
753 $applicationInstance = Registry::getRegistry()->getInstance('application');
754 return $applicationInstance;
758 * Setter for a manageable application helper class
760 * @param $applicationInstance An instance of a manageable application helper class
763 public final function setApplicationInstance (ManageableApplication $applicationInstance) {
764 Registry::getRegistry()->addInstance('application', $applicationInstance);
768 * Setter for request instance
770 * @param $requestInstance An instance of a Requestable class
773 public final function setRequestInstance (Requestable $requestInstance) {
774 $this->requestInstance = $requestInstance;
778 * Getter for request instance
780 * @return $requestInstance An instance of a Requestable class
782 public final function getRequestInstance () {
783 return $this->requestInstance;
787 * Setter for response instance
789 * @param $responseInstance An instance of a Responseable class
792 public final function setResponseInstance (Responseable $responseInstance) {
793 $this->responseInstance = $responseInstance;
797 * Getter for response instance
799 * @return $responseInstance An instance of a Responseable class
801 public final function getResponseInstance () {
802 return $this->responseInstance;
806 * Private getter for language instance
808 * @return $langInstance An instance to the language sub-system
810 protected final function getLanguageInstance () {
811 $langInstance = Registry::getRegistry()->getInstance('language');
812 return $langInstance;
816 * Setter for language instance
818 * @param $langInstance An instance to the language sub-system
820 * @see LanguageSystem
822 public final function setLanguageInstance (ManageableLanguage $langInstance) {
823 Registry::getRegistry()->addInstance('language', $langInstance);
827 * Private getter for file IO instance
829 * @return $fileIoInstance An instance to the file I/O sub-system
831 protected final function getFileIoInstance () {
832 return $this->fileIoInstance;
836 * Setter for file I/O instance
838 * @param $fileIoInstance An instance to the file I/O sub-system
841 public final function setFileIoInstance (IoHandler $fileIoInstance) {
842 $this->fileIoInstance = $fileIoInstance;
846 * Protected setter for user instance
848 * @param $userInstance An instance of a user class
851 protected final function setUserInstance (ManageableAccount $userInstance) {
852 $this->userInstance = $userInstance;
856 * Getter for user instance
858 * @return $userInstance An instance of a user class
860 public final function getUserInstance () {
861 return $this->userInstance;
865 * Setter for controller instance (this surely breaks a bit the MVC patterm)
867 * @param $controllerInstance An instance of the controller
870 public final function setControllerInstance (Controller $controllerInstance) {
871 $this->controllerInstance = $controllerInstance;
875 * Getter for controller instance (this surely breaks a bit the MVC patterm)
877 * @return $controllerInstance An instance of the controller
879 public final function getControllerInstance () {
880 return $this->controllerInstance;
884 * Setter for RNG instance
886 * @param $rngInstance An instance of a random number generator (RNG)
889 protected final function setRngInstance (RandomNumberGenerator $rngInstance) {
890 $this->rngInstance = $rngInstance;
894 * Getter for RNG instance
896 * @return $rngInstance An instance of a random number generator (RNG)
898 public final function getRngInstance () {
899 return $this->rngInstance;
903 * Setter for Cryptable instance
905 * @param $cryptoInstance An instance of a Cryptable class
908 protected final function setCryptoInstance (Cryptable $cryptoInstance) {
909 $this->cryptoInstance = $cryptoInstance;
913 * Getter for Cryptable instance
915 * @return $cryptoInstance An instance of a Cryptable class
917 public final function getCryptoInstance () {
918 return $this->cryptoInstance;
922 * Setter for the list instance
924 * @param $listInstance A list of Listable
927 protected final function setListInstance (Listable $listInstance) {
928 $this->listInstance = $listInstance;
932 * Getter for the list instance
934 * @return $listInstance A list of Listable
936 protected final function getListInstance () {
937 return $this->listInstance;
941 * Setter for the menu instance
943 * @param $menuInstance A RenderableMenu instance
946 protected final function setMenuInstance (RenderableMenu $menuInstance) {
947 $this->menuInstance = $menuInstance;
951 * Getter for the menu instance
953 * @return $menuInstance A RenderableMenu instance
955 protected final function getMenuInstance () {
956 return $this->menuInstance;
960 * Setter for image instance
962 * @param $imageInstance An instance of an image
965 public final function setImageInstance (BaseImage $imageInstance) {
966 $this->imageInstance = $imageInstance;
970 * Getter for image instance
972 * @return $imageInstance An instance of an image
974 public final function getImageInstance () {
975 return $this->imageInstance;
979 * Setter for stacker instance
981 * @param $stackInstance An instance of an stacker
984 public final function setStackInstance (Stackable $stackInstance) {
985 $this->stackInstance = $stackInstance;
989 * Getter for stacker instance
991 * @return $stackInstance An instance of an stacker
993 public final function getStackInstance () {
994 return $this->stackInstance;
998 * Setter for compressor instance
1000 * @param $compressorInstance An instance of an compressor
1003 public final function setCompressorInstance (Compressor $compressorInstance) {
1004 $this->compressorInstance = $compressorInstance;
1008 * Getter for compressor instance
1010 * @return $compressorInstance An instance of an compressor
1012 public final function getCompressorInstance () {
1013 return $this->compressorInstance;
1017 * Setter for Parseable instance
1019 * @param $parserInstance An instance of an Parseable
1022 public final function setParserInstance (Parseable $parserInstance) {
1023 $this->parserInstance = $parserInstance;
1027 * Getter for Parseable instance
1029 * @return $parserInstance An instance of an Parseable
1031 public final function getParserInstance () {
1032 return $this->parserInstance;
1036 * Setter for HandleableProtocol instance
1038 * @param $protocolInstance An instance of an HandleableProtocol
1041 public final function setProtocolInstance (HandleableProtocol $protocolInstance = NULL) {
1042 $this->protocolInstance = $protocolInstance;
1046 * Getter for HandleableProtocol instance
1048 * @return $protocolInstance An instance of an HandleableProtocol
1050 public final function getProtocolInstance () {
1051 return $this->protocolInstance;
1055 * Setter for DatabaseWrapper instance
1057 * @param $wrapperInstance An instance of an DatabaseWrapper
1060 public final function setWrapperInstance (DatabaseWrapper $wrapperInstance) {
1061 $this->wrapperInstance = $wrapperInstance;
1065 * Getter for DatabaseWrapper instance
1067 * @return $wrapperInstance An instance of an DatabaseWrapper
1069 public final function getWrapperInstance () {
1070 return $this->wrapperInstance;
1074 * Setter for socket resource
1076 * @param $socketResource A valid socket resource
1079 public final function setSocketResource ($socketResource) {
1080 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput($this->__toString() . '::' . __FUNCTION__ . ': socketResource=' . $socketResource . ',previous[' . gettype($this->socketResource) . ']=' . $this->socketResource);
1081 $this->socketResource = $socketResource;
1085 * Getter for socket resource
1087 * @return $socketResource A valid socket resource
1089 public final function getSocketResource () {
1090 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput($this->__toString() . '::' . __FUNCTION__ . ': socketResource[' . gettype($this->socketResource) . ']=' . $this->socketResource);
1091 return $this->socketResource;
1095 * Setter for regular expression
1097 * @param $regularExpression A valid regular expression
1100 public final function setRegularExpression ($regularExpression) {
1101 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput($this->__toString() . '::' . __FUNCTION__ . ': regularExpression=' . $regularExpression . ',previous[' . gettype($this->regularExpression) . ']=' . $this->regularExpression);
1102 $this->regularExpression = $regularExpression;
1106 * Getter for regular expression
1108 * @return $regularExpression A valid regular expression
1110 public final function getRegularExpression () {
1111 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput($this->__toString() . '::' . __FUNCTION__ . ': regularExpression[' . gettype($this->regularExpression) . ']=' . $this->regularExpression);
1112 return $this->regularExpression;
1116 * Setter for helper instance
1118 * @param $helperInstance An instance of a helper class
1121 protected final function setHelperInstance (Helper $helperInstance) {
1122 $this->helperInstance = $helperInstance;
1126 * Getter for helper instance
1128 * @return $helperInstance An instance of a helper class
1130 public final function getHelperInstance () {
1131 return $this->helperInstance;
1135 * Setter for a Sourceable instance
1137 * @param $sourceInstance An instance of a Sourceable class
1140 protected final function setSourceInstance (Sourceable $sourceInstance) {
1141 $this->sourceInstance = $sourceInstance;
1145 * Getter for a Sourceable instance
1147 * @return $sourceInstance An instance of a Sourceable class
1149 protected final function getSourceInstance () {
1150 return $this->sourceInstance;
1154 * Setter for a UrlSource instance
1156 * @param $sourceInstance An instance of a UrlSource class
1159 protected final function setUrlSourceInstance (UrlSource $urlSourceInstance) {
1160 $this->urlSourceInstance = $urlSourceInstance;
1164 * Getter for a UrlSource instance
1166 * @return $urlSourceInstance An instance of a UrlSource class
1168 protected final function getUrlSourceInstance () {
1169 return $this->urlSourceInstance;
1173 * Getter for a InputStream instance
1175 * @param $inputStreamInstance The InputStream instance
1177 protected final function getInputStreamInstance () {
1178 return $this->inputStreamInstance;
1182 * Setter for a InputStream instance
1184 * @param $inputStreamInstance The InputStream instance
1187 protected final function setInputStreamInstance (InputStream $inputStreamInstance) {
1188 $this->inputStreamInstance = $inputStreamInstance;
1192 * Getter for a OutputStream instance
1194 * @param $outputStreamInstance The OutputStream instance
1196 protected final function getOutputStreamInstance () {
1197 return $this->outputStreamInstance;
1201 * Setter for a OutputStream instance
1203 * @param $outputStreamInstance The OutputStream instance
1206 protected final function setOutputStreamInstance (OutputStream $outputStreamInstance) {
1207 $this->outputStreamInstance = $outputStreamInstance;
1211 * Setter for handler instance
1213 * @param $handlerInstance An instance of a Handleable class
1216 protected final function setHandlerInstance (Handleable $handlerInstance) {
1217 $this->handlerInstance = $handlerInstance;
1221 * Getter for handler instance
1223 * @return $handlerInstance A Networkable instance
1225 protected final function getHandlerInstance () {
1226 return $this->handlerInstance;
1230 * Setter for visitor instance
1232 * @param $visitorInstance A Visitor instance
1235 protected final function setVisitorInstance (Visitor $visitorInstance) {
1236 $this->visitorInstance = $visitorInstance;
1240 * Getter for visitor instance
1242 * @return $visitorInstance A Visitor instance
1244 protected final function getVisitorInstance () {
1245 return $this->visitorInstance;
1249 * Setter for DHT instance
1251 * @param $dhtInstance A Distributable instance
1254 protected final function setDhtInstance (Distributable $dhtInstance) {
1255 $this->dhtInstance = $dhtInstance;
1259 * Getter for DHT instance
1261 * @return $dhtInstance A Distributable instance
1263 protected final function getDhtInstance () {
1264 return $this->dhtInstance;
1268 * Setter for raw package Data
1270 * @param $packageData Raw package Data
1273 public final function setPackageData (array $packageData) {
1274 $this->packageData = $packageData;
1278 * Getter for raw package Data
1280 * @return $packageData Raw package Data
1282 public function getPackageData () {
1283 return $this->packageData;
1288 * Setter for Iterator instance
1290 * @param $iteratorInstance An instance of an Iterator
1293 protected final function setIteratorInstance (Iterator $iteratorInstance) {
1294 $this->iteratorInstance = $iteratorInstance;
1298 * Getter for Iterator instance
1300 * @return $iteratorInstance An instance of an Iterator
1302 public final function getIteratorInstance () {
1303 return $this->iteratorInstance;
1307 * Setter for FilePointer instance
1309 * @param $pointerInstance An instance of an FilePointer class
1312 protected final function setPointerInstance (FilePointer $pointerInstance) {
1313 $this->pointerInstance = $pointerInstance;
1317 * Getter for FilePointer instance
1319 * @return $pointerInstance An instance of an FilePointer class
1321 public final function getPointerInstance () {
1322 return $this->pointerInstance;
1326 * Setter for Indexable instance
1328 * @param $indexInstance An instance of an Indexable class
1331 protected final function setIndexInstance (Indexable $indexInstance) {
1332 $this->indexInstance = $indexInstance;
1336 * Getter for Indexable instance
1338 * @return $indexInstance An instance of an Indexable class
1340 public final function getIndexInstance () {
1341 return $this->indexInstance;
1345 * Setter for Block instance
1347 * @param $blockInstance An instance of an Block class
1350 protected final function setBlockInstance (Block $blockInstance) {
1351 $this->blockInstance = $blockInstance;
1355 * Getter for Block instance
1357 * @return $blockInstance An instance of an Block class
1359 public final function getBlockInstance () {
1360 return $this->blockInstance;
1364 * Setter for Minable instance
1366 * @param $minableInstance A Minable instance
1369 protected final function setMinableInstance (Minable $minableInstance) {
1370 $this->minableInstance = $minableInstance;
1374 * Getter for minable instance
1376 * @return $minableInstance A Minable instance
1378 protected final function getMinableInstance () {
1379 return $this->minableInstance;
1383 * Setter for FrameworkDirectory instance
1385 * @param $directoryInstance A FrameworkDirectoryPointer instance
1388 protected final function setDirectoryInstance (FrameworkDirectory $directoryInstance) {
1389 $this->directoryInstance = $directoryInstance;
1393 * Getter for FrameworkDirectory instance
1395 * @return $directoryInstance A FrameworkDirectory instance
1397 protected final function getDirectoryInstance () {
1398 return $this->directoryInstance;
1402 * Setter for listener instance
1404 * @param $listenerInstance A Listenable instance
1407 protected final function setListenerInstance (Listenable $listenerInstance) {
1408 $this->listenerInstance = $listenerInstance;
1412 * Getter for listener instance
1414 * @return $listenerInstance A Listenable instance
1416 protected final function getListenerInstance () {
1417 return $this->listenerInstance;
1421 * Checks whether an object equals this object. You should overwrite this
1422 * method to implement own equality checks
1424 * @param $objectInstance An instance of a FrameworkInterface object
1425 * @return $equals Whether both objects equals
1427 public function equals (FrameworkInterface $objectInstance) {
1430 $this->__toString() == $objectInstance->__toString()
1432 $this->hashCode() == $objectInstance->hashCode()
1435 // Return the result
1440 * Generates a generic hash code of this class. You should really overwrite
1441 * this method with your own hash code generator code. But keep KISS in mind.
1443 * @return $hashCode A generic hash code respresenting this whole class
1445 public function hashCode () {
1447 return crc32($this->__toString());
1451 * Formats computer generated price values into human-understandable formats
1452 * with thousand and decimal separators.
1454 * @param $value The in computer format value for a price
1455 * @param $currency The currency symbol (use HTML-valid characters!)
1456 * @param $decNum Number of decimals after commata
1457 * @return $price The for the current language formated price string
1458 * @throws MissingDecimalsThousandsSeparatorException If decimals or
1459 * thousands separator
1462 public function formatCurrency ($value, $currency = '€', $decNum = 2) {
1463 // Are all required attriutes set?
1464 if ((!isset($this->decimals)) || (!isset($this->thousands))) {
1465 // Throw an exception
1466 throw new MissingDecimalsThousandsSeparatorException($this, self::EXCEPTION_ATTRIBUTES_ARE_MISSING);
1470 $value = (float) $value;
1472 // Reformat the US number
1473 $price = number_format($value, $decNum, $this->decimals, $this->thousands) . $currency;
1475 // Return as string...
1480 * Appends a trailing slash to a string
1482 * @param $str A string (maybe) without trailing slash
1483 * @return $str A string with an auto-appended trailing slash
1485 public final function addMissingTrailingSlash ($str) {
1486 // Is there a trailing slash?
1487 if (substr($str, -1, 1) != '/') {
1491 // Return string with trailing slash
1496 * Prepare the template engine (WebTemplateEngine by default) for a given
1497 * application helper instance (ApplicationHelper by default).
1499 * @param $applicationInstance An application helper instance or
1500 * null if we shall use the default
1501 * @return $templateInstance The template engine instance
1502 * @throws NullPointerException If the discovered application
1503 * instance is still null
1505 protected function prepareTemplateInstance (ManageableApplication $applicationInstance = NULL) {
1506 // Is the application instance set?
1507 if (is_null($applicationInstance)) {
1508 // Get the current instance
1509 $applicationInstance = $this->getApplicationInstance();
1512 if (is_null($applicationInstance)) {
1513 // Thrown an exception
1514 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
1518 // Initialize the template engine
1519 $templateInstance = ObjectFactory::createObjectByConfiguredName('web_template_class');
1521 // Return the prepared instance
1522 return $templateInstance;
1526 * Debugs this instance by putting out it's full content
1528 * @param $message Optional message to show in debug output
1531 public final function debugInstance ($message = '') {
1532 // Restore the error handler to avoid trouble with missing array elements or undeclared variables
1533 restore_error_handler();
1538 // Is a message set?
1539 if (!empty($message)) {
1540 // Construct message
1541 $content = sprintf('<div class="debug_message">Message: %s</div>' . PHP_EOL, $message);
1544 // Generate the output
1545 $content .= sprintf('<pre>%s</pre>',
1548 print_r($this, TRUE)
1554 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>',
1555 $this->__toString(),
1557 ClassLoader::getSelfInstance()->getPrintableIncludeList()
1562 * Replaces control characters with printable output
1564 * @param $str String with control characters
1565 * @return $str Replaced string
1567 protected function replaceControlCharacters ($str) {
1570 chr(13), '[r]', str_replace(
1571 chr(10), '[n]', str_replace(
1581 * Output a partial stub message for the caller method
1583 * @param $message An optional message to display
1586 protected function partialStub ($message = '') {
1587 // Get the backtrace
1588 $backtrace = debug_backtrace();
1590 // Generate the class::method string
1591 $methodName = 'UnknownClass->unknownMethod';
1592 if ((isset($backtrace[1]['class'])) && (isset($backtrace[1]['function']))) {
1593 $methodName = $backtrace[1]['class'] . '->' . $backtrace[1]['function'];
1596 // Construct the full message
1597 $stubMessage = sprintf('[%s:] Partial stub!',
1601 // Is the extra message given?
1602 if (!empty($message)) {
1603 // Then add it as well
1604 $stubMessage .= ' Message: ' . $message;
1607 // Debug instance is there?
1608 if (!is_null($this->getDebugInstance())) {
1609 // Output stub message
1610 self::createDebugInstance(__CLASS__)->debugOutput($stubMessage);
1613 trigger_error($stubMessage);
1619 * Outputs a debug backtrace and stops further script execution
1621 * @param $message An optional message to output
1622 * @param $doExit Whether exit the program (TRUE is default)
1625 public function debugBackTrace ($message = '', $doExit = TRUE) {
1626 // Sorry, there is no other way getting this nice backtrace
1627 if (!empty($message)) {
1629 printf('Message: %s<br />' . chr(10), $message);
1633 debug_print_backtrace();
1637 if ($doExit === TRUE) {
1643 * Creates an instance of a debugger instance
1645 * @param $className Name of the class (currently unsupported)
1646 * @return $debugInstance An instance of a debugger class
1648 public final static function createDebugInstance ($className) {
1649 // Is the instance set?
1650 if (!Registry::getRegistry()->instanceExists('debug')) {
1651 // Init debug instance
1652 $debugInstance = NULL;
1656 // Get a debugger instance
1657 $debugInstance = DebugMiddleware::createDebugMiddleware(FrameworkConfiguration::getSelfInstance()->getConfigEntry('debug_class'));
1658 } catch (NullPointerException $e) {
1659 // Didn't work, no instance there
1660 exit('Cannot create debugInstance! Exception=' . $e->__toString() . ', message=' . $e->getMessage());
1663 // Empty string should be ignored and used for testing the middleware
1664 DebugMiddleware::getSelfInstance()->output('');
1666 // Set it in its own class. This will set it in the registry
1667 $debugInstance->setDebugInstance($debugInstance);
1669 // Get instance from registry
1670 $debugInstance = Registry::getRegistry()->getDebugInstance();
1674 return $debugInstance;
1678 * Simple output of a message with line-break
1680 * @param $message Message to output
1683 public function outputLine ($message) {
1685 print($message . PHP_EOL);
1689 * Outputs a debug message whether to debug instance (should be set!) or
1690 * dies with or ptints the message. Do NEVER EVER rewrite the exit() call to
1691 * ApplicationEntryPoint::app_exit(), this would cause an endless loop.
1693 * @param $message Message we shall send out...
1694 * @param $doPrint Whether print or die here (default: print)
1695 * @paran $stripTags Whether to strip tags (default: FALSE)
1698 public function debugOutput ($message, $doPrint = TRUE, $stripTags = FALSE) {
1699 // Set debug instance to NULL
1700 $debugInstance = NULL;
1704 // Get debug instance
1705 $debugInstance = $this->getDebugInstance();
1706 } catch (NullPointerException $e) {
1707 // The debug instance is not set (yet)
1710 // Is the debug instance there?
1711 if (is_object($debugInstance)) {
1712 // Use debug output handler
1713 $debugInstance->output($message, $stripTags);
1715 if ($doPrint === FALSE) {
1716 // Die here if not printed
1720 // Are debug times enabled?
1721 if ($this->getConfigInstance()->getConfigEntry('debug_output_timings') == 'Y') {
1723 $message = $this->getPrintableExecutionTime() . $message;
1727 if ($doPrint === TRUE) {
1729 $this->outputLine($message);
1738 * Converts e.g. a command from URL to a valid class by keeping out bad characters
1740 * @param $str The string, what ever it is needs to be converted
1741 * @return $className Generated class name
1743 public function convertToClassName ($str) {
1747 // Convert all dashes in underscores
1748 $str = $this->convertDashesToUnderscores($str);
1750 // Now use that underscores to get classname parts for hungarian style
1751 foreach (explode('_', $str) as $strPart) {
1752 // Make the class name part lower case and first upper case
1753 $className .= ucfirst(strtolower($strPart));
1756 // Return class name
1761 * Converts dashes to underscores, e.g. useable for configuration entries
1763 * @param $str The string with maybe dashes inside
1764 * @return $str The converted string with no dashed, but underscores
1766 public final function convertDashesToUnderscores ($str) {
1768 $str = str_replace('-', '_', $str);
1770 // Return converted string
1775 * Marks up the code by adding e.g. line numbers
1777 * @param $phpCode Unmarked PHP code
1778 * @return $markedCode Marked PHP code
1780 public function markupCode ($phpCode) {
1785 $errorArray = error_get_last();
1787 // Init the code with error message
1788 if (is_array($errorArray)) {
1790 $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>',
1791 basename($errorArray['file']),
1792 $errorArray['line'],
1793 $errorArray['message'],
1798 // Add line number to the code
1799 foreach (explode(chr(10), $phpCode) as $lineNo => $code) {
1801 $markedCode .= sprintf('<span id="code_line">%s</span>: %s' . chr(10),
1803 htmlentities($code, ENT_QUOTES)
1812 * Filter a given GMT timestamp (non Uni* stamp!) to make it look more
1813 * beatiful for web-based front-ends. If null is given a message id
1814 * null_timestamp will be resolved and returned.
1816 * @param $timestamp Timestamp to prepare (filter) for display
1817 * @return $readable A readable timestamp
1819 public function doFilterFormatTimestamp ($timestamp) {
1820 // Default value to return
1823 // Is the timestamp null?
1824 if (is_null($timestamp)) {
1825 // Get a message string
1826 $readable = $this->getLanguageInstance()->getMessage('null_timestamp');
1828 switch ($this->getLanguageInstance()->getLanguageCode()) {
1829 case 'de': // German format is a bit different to default
1830 // Split the GMT stamp up
1831 $dateTime = explode(' ', $timestamp );
1832 $dateArray = explode('-', $dateTime[0]);
1833 $timeArray = explode(':', $dateTime[1]);
1835 // Construct the timestamp
1836 $readable = sprintf($this->getConfigInstance()->getConfigEntry('german_date_time'),
1846 default: // Default is pass-through
1847 $readable = $timestamp;
1857 * Filter a given number into a localized number
1859 * @param $value The raw value from e.g. database
1860 * @return $localized Localized value
1862 public function doFilterFormatNumber ($value) {
1863 // Generate it from config and localize dependencies
1864 switch ($this->getLanguageInstance()->getLanguageCode()) {
1865 case 'de': // German format is a bit different to default
1866 $localized = number_format($value, $this->getConfigInstance()->getConfigEntry('decimals'), ',', '.');
1869 default: // US, etc.
1870 $localized = number_format($value, $this->getConfigInstance()->getConfigEntry('decimals'), '.', ',');
1879 * "Getter" for databse entry
1881 * @return $entry An array with database entries
1882 * @throws NullPointerException If the database result is not found
1883 * @throws InvalidDatabaseResultException If the database result is invalid
1885 protected final function getDatabaseEntry () {
1886 // Is there an instance?
1887 if (is_null($this->getResultInstance())) {
1888 // Throw an exception here
1889 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
1893 $this->getResultInstance()->rewind();
1895 // Do we have an entry?
1896 if ($this->getResultInstance()->valid() === FALSE) {
1897 // @TODO Move the constant to e.g. BaseDatabaseResult when there is a non-cached database result available
1898 throw new InvalidDatabaseResultException(array($this, $this->getResultInstance()), CachedDatabaseResult::EXCEPTION_INVALID_DATABASE_RESULT);
1902 $this->getResultInstance()->next();
1905 $entry = $this->getResultInstance()->current();
1912 * Getter for field name
1914 * @param $fieldName Field name which we shall get
1915 * @return $fieldValue Field value from the user
1916 * @throws NullPointerException If the result instance is null
1918 public final function getField ($fieldName) {
1919 // Default field value
1922 // Get result instance
1923 $resultInstance = $this->getResultInstance();
1925 // Is this instance null?
1926 if (is_null($resultInstance)) {
1927 // Then the user instance is no longer valid (expired cookies?)
1928 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
1931 // Get current array
1932 $fieldArray = $resultInstance->current();
1933 //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput($fieldName.':<pre>'.print_r($fieldArray, TRUE).'</pre>');
1935 // Convert dashes to underscore
1936 $fieldName = $this->convertDashesToUnderscores($fieldName);
1938 // Does the field exist?
1939 if (isset($fieldArray[$fieldName])) {
1941 $fieldValue = $fieldArray[$fieldName];
1943 // Missing field entry, may require debugging
1944 self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']:fieldName=' . $fieldName . ' not found!');
1952 * Flushs all pending updates to the database layer
1956 public function flushPendingUpdates () {
1957 // Get result instance
1958 $resultInstance = $this->getResultInstance();
1960 // Do we have data to update?
1961 if ((is_object($resultInstance)) && ($resultInstance->ifDataNeedsFlush())) {
1962 // Get wrapper class name config entry
1963 $configEntry = $resultInstance->getUpdateInstance()->getWrapperConfigEntry();
1965 // Create object instance
1966 $wrapperInstance = ObjectFactory::createObjectByConfiguredName($configEntry);
1968 // Yes, then send the whole result to the database layer
1969 $wrapperInstance->doUpdateByResult($this->getResultInstance());
1974 * Outputs a deprecation warning to the developer.
1976 * @param $message The message we shall output to the developer
1978 * @todo Write a logging mechanism for productive mode
1980 public function deprecationWarning ($message) {
1981 // Is developer mode active?
1982 if (defined('DEVELOPER')) {
1983 // Debug instance is there?
1984 if (!is_null($this->getDebugInstance())) {
1985 // Output stub message
1986 self::createDebugInstance(__CLASS__)->debugOutput($message);
1989 trigger_error($message . "<br />\n");
1993 // @TODO Finish this part!
1994 $this->partialStub('Developer mode inactive. Message:' . $message);
1999 * Checks whether the given PHP extension is loaded
2001 * @param $phpExtension The PHP extension we shall check
2002 * @return $isLoaded Whether the PHP extension is loaded
2004 public final function isPhpExtensionLoaded ($phpExtension) {
2006 $isLoaded = in_array($phpExtension, get_loaded_extensions());
2013 * "Getter" as a time() replacement but with milliseconds. You should use this
2014 * method instead of the encapsulated getimeofday() function.
2016 * @return $milliTime Timestamp with milliseconds
2018 public function getMilliTime () {
2019 // Get the time of day as float
2020 $milliTime = gettimeofday(TRUE);
2027 * Idles (sleeps) for given milliseconds
2029 * @return $hasSlept Whether it goes fine
2031 public function idle ($milliSeconds) {
2032 // Sleep is fine by default
2035 // Idle so long with found function
2036 if (function_exists('time_sleep_until')) {
2037 // Get current time and add idle time
2038 $sleepUntil = $this->getMilliTime() + abs($milliSeconds) / 1000;
2040 // New PHP 5.1.0 function found, ignore errors
2041 $hasSlept = @time_sleep_until($sleepUntil);
2044 * My Sun station doesn't have that function even with latest PHP
2047 usleep($milliSeconds * 1000);
2054 * Converts a hexadecimal string, even with negative sign as first string to
2055 * a decimal number using BC functions.
2057 * This work is based on comment #86673 on php.net documentation page at:
2058 * <http://de.php.net/manual/en/function.dechex.php#86673>
2060 * @param $hex Hexadecimal string
2061 * @return $dec Decimal number
2063 protected function hex2dec ($hex) {
2064 // Convert to all lower-case
2065 $hex = strtolower($hex);
2067 // Detect sign (negative/positive numbers)
2069 if (substr($hex, 0, 1) == '-') {
2071 $hex = substr($hex, 1);
2074 // Decode the hexadecimal string into a decimal number
2076 for ($i = strlen($hex) - 1, $e = 1; $i >= 0; $i--, $e = bcmul($e, 16)) {
2077 $factor = self::$hexdec[substr($hex, $i, 1)];
2078 $dec = bcadd($dec, bcmul($factor, $e));
2081 // Return the decimal number
2082 return $sign . $dec;
2086 * Converts even very large decimal numbers, also signed, to a hexadecimal
2089 * This work is based on comment #97756 on php.net documentation page at:
2090 * <http://de.php.net/manual/en/function.hexdec.php#97756>
2092 * @param $dec Decimal number, even with negative sign
2093 * @param $maxLength Optional maximum length of the string
2094 * @return $hex Hexadecimal string
2096 protected function dec2hex ($dec, $maxLength = 0) {
2097 // maxLength can be zero or devideable by 2
2098 assert(($maxLength == 0) || (($maxLength % 2) == 0));
2100 // Detect sign (negative/positive numbers)
2107 // Encode the decimal number into a hexadecimal string
2110 $hex = self::$dechex[($dec % (2 ^ 4))] . $hex;
2112 } while ($dec >= 1);
2115 * Leading zeros are required for hex-decimal "numbers". In some
2116 * situations more leading zeros are wanted, so check for both
2119 if ($maxLength > 0) {
2120 // Prepend more zeros
2121 $hex = str_pad($hex, $maxLength, '0', STR_PAD_LEFT);
2122 } elseif ((strlen($hex) % 2) != 0) {
2123 // Only make string's length dividable by 2
2127 // Return the hexadecimal string
2128 return $sign . $hex;
2132 * Converts a ASCII string (0 to 255) into a decimal number.
2134 * @param $asc The ASCII string to be converted
2135 * @return $dec Decimal number
2137 protected function asc2dec ($asc) {
2138 // Convert it into a hexadecimal number
2139 $hex = bin2hex($asc);
2141 // And back into a decimal number
2142 $dec = $this->hex2dec($hex);
2149 * Converts a decimal number into an ASCII string.
2151 * @param $dec Decimal number
2152 * @return $asc An ASCII string
2154 protected function dec2asc ($dec) {
2155 // First convert the number into a hexadecimal string
2156 $hex = $this->dec2hex($dec);
2158 // Then convert it into the ASCII string
2159 $asc = $this->hex2asc($hex);
2166 * Converts a hexadecimal number into an ASCII string. Negative numbers
2169 * @param $hex Hexadecimal string
2170 * @return $asc An ASCII string
2172 protected function hex2asc ($hex) {
2173 // Check for length, it must be devideable by 2
2174 //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('hex='.$hex);
2175 assert((strlen($hex) % 2) == 0);
2179 for ($idx = 0; $idx < strlen($hex); $idx+=2) {
2180 // Get the decimal number of the chunk
2181 $part = hexdec(substr($hex, $idx, 2));
2183 // Add it to the final string
2187 // Return the final string
2192 * Checks whether the given encoded data was encoded with Base64
2194 * @param $encodedData Encoded data we shall check
2195 * @return $isBase64 Whether the encoded data is Base64
2197 protected function isBase64Encoded ($encodedData) {
2199 $isBase64 = (@base64_decode($encodedData, TRUE) !== FALSE);
2206 * "Getter" to get response/request type from analysis of the system.
2208 * @return $responseType Analyzed response type
2210 protected function getResponseTypeFromSystem () {
2211 // Default is console
2212 $responseType = 'console';
2214 // Is 'HTTP_HOST' set?
2215 if (isset($_SERVER['HTTP_HOST'])) {
2216 // Then it is a HTTP response/request
2217 $responseType = 'http';
2221 return $responseType;
2225 * Gets a cache key from Criteria instance
2227 * @param $criteriaInstance An instance of a Criteria class
2228 * @param $onlyKeys Only use these keys for a cache key
2229 * @return $cacheKey A cache key suitable for lookup/storage purposes
2231 protected function getCacheKeyByCriteria (Criteria $criteriaInstance, array $onlyKeys = array()) {
2233 $cacheKey = sprintf('%s@%s',
2234 $this->__toString(),
2235 $criteriaInstance->getCacheKey($onlyKeys)
2239 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput($this->__toString() . ': cacheKey=' . $cacheKey);
2244 * Getter for startup time in miliseconds
2246 * @return $startupTime Startup time in miliseconds
2248 protected function getStartupTime () {
2249 return self::$startupTime;
2253 * "Getter" for a printable currently execution time in nice braces
2255 * @return $executionTime Current execution time in nice braces
2257 protected function getPrintableExecutionTime () {
2258 // Caculate the execution time
2259 $executionTime = microtime(TRUE) - $this->getStartupTime();
2261 // Pack it in nice braces
2262 $executionTime = sprintf('[ %01.5f ] ', $executionTime);
2265 return $executionTime;
2269 * Hashes a given string with a simple but stronger hash function (no salt)
2270 * and hex-encode it.
2272 * @param $str The string to be hashed
2273 * @return $hash The hash from string $str
2275 public static final function hash ($str) {
2276 // Hash given string with (better secure) hasher
2277 $hash = bin2hex(mhash(MHASH_SHA256, $str));
2284 * "Getter" for length of hash() output. This will be "cached" to speed up
2287 * @return $length Length of hash() output
2289 public static final function getHashLength () {
2291 if (is_null(self::$hashLength)) {
2292 // No, then hash a string and save its length.
2293 self::$hashLength = strlen(self::hash('abc123'));
2297 return self::$hashLength;
2301 * Checks whether the given number is really a number (only chars 0-9).
2303 * @param $num A string consisting only chars between 0 and 9
2304 * @param $castValue Whether to cast the value to double. Do only use this to secure numbers from Requestable classes.
2305 * @param $assertMismatch Whether to assert mismatches
2306 * @return $ret The (hopefully) secured numbered value
2308 public function bigintval ($num, $castValue = TRUE, $assertMismatch = FALSE) {
2309 // Filter all numbers out
2310 $ret = preg_replace('/[^0123456789]/', '', $num);
2313 if ($castValue === TRUE) {
2314 // Cast to biggest numeric type
2315 $ret = (double) $ret;
2318 // Assert only if requested
2319 if ($assertMismatch === TRUE) {
2320 // Has the whole value changed?
2321 assert(('' . $ret . '' != '' . $num . '') && (!is_null($num)));
2329 * Checks whether the given hexadecimal number is really a hex-number (only chars 0-9,a-f).
2331 * @param $num A string consisting only chars between 0 and 9
2332 * @param $assertMismatch Whether to assert mismatches
2333 * @return $ret The (hopefully) secured hext-numbered value
2335 public function hexval ($num, $assertMismatch = FALSE) {
2336 // Filter all numbers out
2337 $ret = preg_replace('/[^0123456789abcdefABCDEF]/', '', $num);
2339 // Assert only if requested
2340 if ($assertMismatch === TRUE) {
2341 // Has the whole value changed?
2342 assert(('' . $ret . '' != '' . $num . '') && (!is_null($num)));
2350 * Checks whether start/end marker are set
2352 * @param $data Data to be checked
2353 * @return $isset Whether start/end marker are set
2355 public final function ifStartEndMarkersSet ($data) {
2357 $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));
2359 // ... and return it
2364 * Determines if an element is set in the generic array
2366 * @param $keyGroup Main group for the key
2367 * @param $subGroup Sub group for the key
2368 * @param $key Key to check
2369 * @param $element Element to check
2370 * @return $isset Whether the given key is set
2372 protected final function isGenericArrayElementSet ($keyGroup, $subGroup, $key, $element) {
2374 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element);
2377 $isset = isset($this->genericArray[$keyGroup][$subGroup][$key][$element]);
2383 * Determines if a key is set in the generic array
2385 * @param $keyGroup Main group for the key
2386 * @param $subGroup Sub group for the key
2387 * @param $key Key to check
2388 * @return $isset Whether the given key is set
2390 protected final function isGenericArrayKeySet ($keyGroup, $subGroup, $key) {
2392 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
2395 $isset = isset($this->genericArray[$keyGroup][$subGroup][$key]);
2403 * Determines if a group is set in the generic array
2405 * @param $keyGroup Main group
2406 * @param $subGroup Sub group
2407 * @return $isset Whether the given group is set
2409 protected final function isGenericArrayGroupSet ($keyGroup, $subGroup) {
2411 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup);
2414 $isset = isset($this->genericArray[$keyGroup][$subGroup]);
2421 * Getter for sub key group
2423 * @param $keyGroup Main key group
2424 * @param $subGroup Sub key group
2425 * @return $array An array with all array elements
2427 protected final function getGenericSubArray ($keyGroup, $subGroup) {
2429 if (!$this->isGenericArrayGroupSet($keyGroup, $subGroup)) {
2430 // No, then abort here
2431 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' not found.');
2436 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',value=' . print_r($this->genericArray[$keyGroup][$subGroup], TRUE));
2439 return $this->genericArray[$keyGroup][$subGroup];
2443 * Unsets a given key in generic array
2445 * @param $keyGroup Main group for the key
2446 * @param $subGroup Sub group for the key
2447 * @param $key Key to unset
2450 protected final function unsetGenericArrayKey ($keyGroup, $subGroup, $key) {
2452 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
2455 unset($this->genericArray[$keyGroup][$subGroup][$key]);
2459 * Unsets a given element in generic array
2461 * @param $keyGroup Main group for the key
2462 * @param $subGroup Sub group for the key
2463 * @param $key Key to unset
2464 * @param $element Element to unset
2467 protected final function unsetGenericArrayElement ($keyGroup, $subGroup, $key, $element) {
2469 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element);
2472 unset($this->genericArray[$keyGroup][$subGroup][$key][$element]);
2476 * Append a string to a given generic array key
2478 * @param $keyGroup Main group for the key
2479 * @param $subGroup Sub group for the key
2480 * @param $key Key to unset
2481 * @param $value Value to add/append
2484 protected final function appendStringToGenericArrayKey ($keyGroup, $subGroup, $key, $value, $appendGlue = '') {
2486 //* 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);
2488 // Is it already there?
2489 if ($this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
2491 $this->genericArray[$keyGroup][$subGroup][$key] .= $appendGlue . (string) $value;
2494 $this->genericArray[$keyGroup][$subGroup][$key] = (string) $value;
2499 * Append a string to a given generic array element
2501 * @param $keyGroup Main group for the key
2502 * @param $subGroup Sub group for the key
2503 * @param $key Key to unset
2504 * @param $element Element to check
2505 * @param $value Value to add/append
2508 protected final function appendStringToGenericArrayElement ($keyGroup, $subGroup, $key, $element, $value, $appendGlue = '') {
2510 //* 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);
2512 // Is it already there?
2513 if ($this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element)) {
2515 $this->genericArray[$keyGroup][$subGroup][$key][$element] .= $appendGlue . (string) $value;
2518 $this->genericArray[$keyGroup][$subGroup][$key][$element] = (string) $value;
2523 * Initializes given generic array group
2525 * @param $keyGroup Main group for the key
2526 * @param $subGroup Sub group for the key
2527 * @param $key Key to use
2528 * @param $forceInit Optionally force initialization
2531 protected final function initGenericArrayGroup ($keyGroup, $subGroup, $forceInit = FALSE) {
2533 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',forceInit=' . intval($forceInit));
2535 // Is it already set?
2536 if (($forceInit === FALSE) && ($this->isGenericArrayGroupSet($keyGroup, $subGroup))) {
2537 // Already initialized
2538 trigger_error(__METHOD__ . ':keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' already initialized.');
2543 $this->genericArray[$keyGroup][$subGroup] = array();
2547 * Initializes given generic array key
2549 * @param $keyGroup Main group for the key
2550 * @param $subGroup Sub group for the key
2551 * @param $key Key to use
2552 * @param $forceInit Optionally force initialization
2555 protected final function initGenericArrayKey ($keyGroup, $subGroup, $key, $forceInit = FALSE) {
2557 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',forceInit=' . intval($forceInit));
2559 // Is it already set?
2560 if (($forceInit === FALSE) && ($this->isGenericArrayKeySet($keyGroup, $subGroup, $key))) {
2561 // Already initialized
2562 trigger_error(__METHOD__ . ':keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' already initialized.');
2567 $this->genericArray[$keyGroup][$subGroup][$key] = array();
2571 * Initializes given generic array element
2573 * @param $keyGroup Main group for the key
2574 * @param $subGroup Sub group for the key
2575 * @param $key Key to use
2576 * @param $element Element to use
2577 * @param $forceInit Optionally force initialization
2580 protected final function initGenericArrayElement ($keyGroup, $subGroup, $key, $element, $forceInit = FALSE) {
2582 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element . ',forceInit=' . intval($forceInit));
2584 // Is it already set?
2585 if (($forceInit === FALSE) && ($this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element))) {
2586 // Already initialized
2587 trigger_error(__METHOD__ . ':keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element . ' already initialized.');
2592 $this->genericArray[$keyGroup][$subGroup][$key][$element] = array();
2596 * Pushes an element to a generic key
2598 * @param $keyGroup Main group for the key
2599 * @param $subGroup Sub group for the key
2600 * @param $key Key to use
2601 * @param $value Value to add/append
2602 * @return $count Number of array elements
2604 protected final function pushValueToGenericArrayKey ($keyGroup, $subGroup, $key, $value) {
2606 //* NOISY-DEBUG: */ if (!is_object($value)) $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',value[' . gettype($value) . ']=' . print_r($value, TRUE));
2609 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
2611 $this->initGenericArrayKey($keyGroup, $subGroup, $key);
2615 $count = array_push($this->genericArray[$keyGroup][$subGroup][$key], $value);
2618 //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], TRUE));
2619 //* DEBUG: */ print(__METHOD__ . ': count=' . $count . PHP_EOL);
2624 * Pushes an element to a generic array element
2626 * @param $keyGroup Main group for the key
2627 * @param $subGroup Sub group for the key
2628 * @param $key Key to use
2629 * @param $element Element to check
2630 * @param $value Value to add/append
2631 * @return $count Number of array elements
2633 protected final function pushValueToGenericArrayElement ($keyGroup, $subGroup, $key, $element, $value) {
2635 //* 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));
2638 if (!$this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element)) {
2640 $this->initGenericArrayElement($keyGroup, $subGroup, $key, $element);
2644 $count = array_push($this->genericArray[$keyGroup][$subGroup][$key][$element], $value);
2647 //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], TRUE));
2648 //* DEBUG: */ print(__METHOD__ . ': count=' . $count . PHP_EOL);
2653 * Pops an element from a generic group
2655 * @param $keyGroup Main group for the key
2656 * @param $subGroup Sub group for the key
2657 * @param $key Key to unset
2658 * @return $value Last "popped" value
2660 protected final function popGenericArrayElement ($keyGroup, $subGroup, $key) {
2662 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
2665 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
2667 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' not found.');
2672 $value = array_pop($this->genericArray[$keyGroup][$subGroup][$key]);
2675 //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], TRUE));
2676 //* DEBUG: */ print(__METHOD__ . ': value[' . gettype($value) . ']=' . print_r($value, TRUE) . PHP_EOL);
2681 * Shifts an element from a generic group
2683 * @param $keyGroup Main group for the key
2684 * @param $subGroup Sub group for the key
2685 * @param $key Key to unset
2686 * @return $value Last "popped" value
2688 protected final function shiftGenericArrayElement ($keyGroup, $subGroup, $key) {
2690 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
2693 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
2695 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' not found.');
2700 $value = array_shift($this->genericArray[$keyGroup][$subGroup][$key]);
2703 //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], TRUE));
2704 //* DEBUG: */ print(__METHOD__ . ': value[' . gettype($value) . ']=' . print_r($value, TRUE) . PHP_EOL);
2709 * Count generic array group
2711 * @param $keyGroup Main group for the key
2712 * @return $count Count of given group
2714 protected final function countGenericArray ($keyGroup) {
2716 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup);
2719 if (!isset($this->genericArray[$keyGroup])) {
2721 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ' not found.');
2726 $count = count($this->genericArray[$keyGroup]);
2729 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',count=' . $count);
2736 * Count generic array sub group
2738 * @param $keyGroup Main group for the key
2739 * @param $subGroup Sub group for the key
2740 * @return $count Count of given group
2742 protected final function countGenericArrayGroup ($keyGroup, $subGroup) {
2744 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup);
2747 if (!$this->isGenericArrayGroupSet($keyGroup, $subGroup)) {
2749 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' not found.');
2754 $count = count($this->genericArray[$keyGroup][$subGroup]);
2757 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',count=' . $count);
2764 * Count generic array elements
2766 * @param $keyGroup Main group for the key
2767 * @param $subGroup Sub group for the key
2768 * @para $key Key to count
2769 * @return $count Count of given key
2771 protected final function countGenericArrayElements ($keyGroup, $subGroup, $key) {
2773 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
2776 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
2778 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' not found.');
2780 } elseif (!$this->isValidGenericArrayGroup($keyGroup, $subGroup)) {
2782 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' is not an array.');
2787 $count = count($this->genericArray[$keyGroup][$subGroup][$key]);
2790 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',count=' . $count);
2797 * Getter for whole generic group array
2799 * @param $keyGroup Key group to get
2800 * @return $array Whole generic array group
2802 protected final function getGenericArray ($keyGroup) {
2804 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup);
2807 if (!isset($this->genericArray[$keyGroup])) {
2809 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ' does not exist.');
2814 return $this->genericArray[$keyGroup];
2818 * Setter for generic array key
2820 * @param $keyGroup Key group to get
2821 * @param $subGroup Sub group for the key
2822 * @param $key Key to unset
2823 * @param $value Mixed value from generic array element
2826 protected final function setGenericArrayKey ($keyGroup, $subGroup, $key, $value) {
2828 //* NOISY-DEBUG: */ if (!is_object($value)) $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',value[' . gettype($value) . ']=' . print_r($value, TRUE));
2831 $this->genericArray[$keyGroup][$subGroup][$key] = $value;
2835 * Getter for generic array key
2837 * @param $keyGroup Key group to get
2838 * @param $subGroup Sub group for the key
2839 * @param $key Key to unset
2840 * @return $value Mixed value from generic array element
2842 protected final function getGenericArrayKey ($keyGroup, $subGroup, $key) {
2844 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
2847 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
2849 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' does not exist.');
2854 return $this->genericArray[$keyGroup][$subGroup][$key];
2858 * Sets a value in given generic array key/element
2860 * @param $keyGroup Main group for the key
2861 * @param $subGroup Sub group for the key
2862 * @param $key Key to set
2863 * @param $element Element to set
2864 * @param $value Value to set
2867 protected final function setGenericArrayElement ($keyGroup, $subGroup, $key, $element, $value) {
2869 //* 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));
2872 $this->genericArray[$keyGroup][$subGroup][$key][$element] = $value;
2876 * Getter for generic array element
2878 * @param $keyGroup Key group to get
2879 * @param $subGroup Sub group for the key
2880 * @param $key Key to look for
2881 * @param $element Element to look for
2882 * @return $value Mixed value from generic array element
2884 protected final function getGenericArrayElement ($keyGroup, $subGroup, $key, $element) {
2886 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element);
2889 if (!$this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element)) {
2891 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element . ' does not exist.');
2896 return $this->genericArray[$keyGroup][$subGroup][$key][$element];
2900 * Checks if a given sub group is valid (array)
2902 * @param $keyGroup Key group to get
2903 * @param $subGroup Sub group for the key
2904 * @return $isValid Whether given sub group is valid
2906 protected final function isValidGenericArrayGroup ($keyGroup, $subGroup) {
2908 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup);
2911 $isValid = (($this->isGenericArrayGroupSet($keyGroup, $subGroup)) && (is_array($this->getGenericSubArray($keyGroup, $subGroup))));
2918 * Checks if a given key is valid (array)
2920 * @param $keyGroup Key group to get
2921 * @param $subGroup Sub group for the key
2922 * @param $key Key to check
2923 * @return $isValid Whether given sub group is valid
2925 protected final function isValidGenericArrayKey ($keyGroup, $subGroup, $key) {
2927 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
2930 $isValid = (($this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) && (is_array($this->getGenericArrayKey($keyGroup, $subGroup, $key))));
2937 * Translates boolean TRUE to 'Y' and FALSE to 'N'
2939 * @param $boolean Boolean value
2940 * @return $translated Translated boolean value
2942 public static final function translateBooleanToYesNo ($boolean) {
2943 // Make sure it is really boolean
2944 assert(is_bool($boolean));
2947 $translated = ($boolean === TRUE) ? 'Y' : 'N';
2949 // ... and return it