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();
249 private $commandName = '';
254 private $controllerName = '';
256 /***********************
257 * Exception codes.... *
258 ***********************/
260 // @todo Try to clean these constants up
261 const EXCEPTION_IS_NULL_POINTER = 0x001;
262 const EXCEPTION_IS_NO_OBJECT = 0x002;
263 const EXCEPTION_IS_NO_ARRAY = 0x003;
264 const EXCEPTION_MISSING_METHOD = 0x004;
265 const EXCEPTION_CLASSES_NOT_MATCHING = 0x005;
266 const EXCEPTION_INDEX_OUT_OF_BOUNDS = 0x006;
267 const EXCEPTION_DIMENSION_ARRAY_INVALID = 0x007;
268 const EXCEPTION_ITEM_NOT_TRADEABLE = 0x008;
269 const EXCEPTION_ITEM_NOT_IN_PRICE_LIST = 0x009;
270 const EXCEPTION_GENDER_IS_WRONG = 0x00a;
271 const EXCEPTION_BIRTH_DATE_IS_INVALID = 0x00b;
272 const EXCEPTION_EMPTY_STRUCTURES_ARRAY = 0x00c;
273 const EXCEPTION_HAS_ALREADY_PERSONELL_LIST = 0x00d;
274 const EXCEPTION_NOT_ENOUGTH_UNEMPLOYEES = 0x00e;
275 const EXCEPTION_TOTAL_PRICE_NOT_CALCULATED = 0x00f;
276 const EXCEPTION_HARBOR_HAS_NO_SHIPYARDS = 0x010;
277 const EXCEPTION_CONTRACT_PARTNER_INVALID = 0x011;
278 const EXCEPTION_CONTRACT_PARTNER_MISMATCH = 0x012;
279 const EXCEPTION_CONTRACT_ALREADY_SIGNED = 0x013;
280 const EXCEPTION_UNEXPECTED_EMPTY_STRING = 0x014;
281 const EXCEPTION_PATH_NOT_FOUND = 0x015;
282 const EXCEPTION_INVALID_PATH_NAME = 0x016;
283 const EXCEPTION_READ_PROTECED_PATH = 0x017;
284 const EXCEPTION_WRITE_PROTECED_PATH = 0x018;
285 const EXCEPTION_DIR_POINTER_INVALID = 0x019;
286 const EXCEPTION_FILE_POINTER_INVALID = 0x01a;
287 const EXCEPTION_INVALID_RESOURCE = 0x01b;
288 const EXCEPTION_UNEXPECTED_OBJECT = 0x01c;
289 const EXCEPTION_LIMIT_ELEMENT_IS_UNSUPPORTED = 0x01d;
290 const EXCEPTION_GETTER_IS_MISSING = 0x01e;
291 const EXCEPTION_ARRAY_EXPECTED = 0x01f;
292 const EXCEPTION_ARRAY_HAS_INVALID_COUNT = 0x020;
293 const EXCEPTION_ID_IS_INVALID_FORMAT = 0x021;
294 const EXCEPTION_MD5_CHECKSUMS_MISMATCH = 0x022;
295 const EXCEPTION_UNEXPECTED_STRING_SIZE = 0x023;
296 const EXCEPTION_SIMULATOR_ID_INVALID = 0x024;
297 const EXCEPTION_MISMATCHING_COMPRESSORS = 0x025;
298 const EXCEPTION_CONTAINER_ITEM_IS_NULL = 0x026;
299 const EXCEPTION_ITEM_IS_NO_ARRAY = 0x027;
300 const EXCEPTION_CONTAINER_MAYBE_DAMAGED = 0x028;
301 const EXCEPTION_INVALID_STRING = 0x029;
302 const EXCEPTION_VARIABLE_NOT_SET = 0x02a;
303 const EXCEPTION_ATTRIBUTES_ARE_MISSING = 0x02b;
304 const EXCEPTION_ARRAY_ELEMENTS_MISSING = 0x02c;
305 const EXCEPTION_TEMPLATE_ENGINE_UNSUPPORTED = 0x02d;
306 const EXCEPTION_UNSPPORTED_OPERATION = 0x02e;
307 const EXCEPTION_FACTORY_REQUIRE_PARAMETER = 0x02f;
308 const EXCEPTION_MISSING_ELEMENT = 0x030;
309 const EXCEPTION_HEADERS_ALREADY_SENT = 0x031;
310 const EXCEPTION_DEFAULT_CONTROLLER_GONE = 0x032;
311 const EXCEPTION_CLASS_NOT_FOUND = 0x033;
312 const EXCEPTION_REQUIRED_INTERFACE_MISSING = 0x034;
313 const EXCEPTION_FATAL_ERROR = 0x035;
314 const EXCEPTION_FILE_NOT_FOUND = 0x036;
315 const EXCEPTION_ASSERTION_FAILED = 0x037;
316 const EXCEPTION_FILE_CANNOT_BE_READ = 0x038;
317 const EXCEPTION_DATABASE_UPDATED_NOT_ALLOWED = 0x039;
318 const EXCEPTION_FILTER_CHAIN_INTERCEPTED = 0x03a;
321 * Hexadecimal->Decimal translation array
323 private static $hexdec = array(
343 * Decimal->hexadecimal translation array
345 private static $dechex = array(
365 * Startup time in miliseconds
367 private static $startupTime = 0;
370 * Protected super constructor
372 * @param $className Name of the class
375 protected function __construct ($className) {
377 $this->setRealClass($className);
379 // Set configuration instance if no registry ...
380 if (!$this instanceof Register) {
381 // ... because registries doesn't need to be configured
382 $this->setConfigInstance(FrameworkConfiguration::getSelfInstance());
385 // Is the startup time set? (0 cannot be TRUE anymore)
386 if (self::$startupTime == 0) {
388 self::$startupTime = microtime(TRUE);
393 * Destructor for all classes
397 public function __destruct () {
398 // Flush any updated entries to the database
399 $this->flushPendingUpdates();
401 // Is this object already destroyed?
402 if ($this->__toString() != 'DestructedObject') {
403 // Destroy all informations about this class but keep some text about it alive
404 $this->setRealClass('DestructedObject');
405 } elseif ((defined('DEBUG_DESTRUCTOR')) && (is_object($this->getDebugInstance()))) {
406 // Already destructed object
407 self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:] The object <span class="object_name">%s</span> is already destroyed.',
412 // Do not call this twice
413 trigger_error(__METHOD__ . ': Called twice.');
419 * The __call() method where all non-implemented methods end up
421 * @param $methodName Name of the missing method
422 * @args $args Arguments passed to the method
425 public final function __call ($methodName, $args) {
426 return self::__callStatic($methodName, $args);
430 * The __callStatic() method where all non-implemented static methods end up
432 * @param $methodName Name of the missing method
433 * @args $args Arguments passed to the method
436 public static final function __callStatic ($methodName, $args) {
437 // Init argument string
440 // Is it empty or an array?
443 $argsString = 'NULL';
444 } elseif (is_array($args)) {
445 // Some arguments are there
446 foreach ($args as $arg) {
447 // Add the value itself if not array. This prevents 'array to string conversion' message
448 if (is_array($arg)) {
449 $argsString .= 'Array';
454 // Add data about the argument
455 $argsString .= ' (' . gettype($arg);
457 if (is_string($arg)) {
458 // Add length for strings
459 $argsString .= ', ' . strlen($arg);
460 } elseif (is_array($arg)) {
461 // .. or size if array
462 $argsString .= ', ' . count($arg);
463 } elseif ($arg === TRUE) {
464 // ... is boolean 'TRUE'
465 $argsString .= ', TRUE';
466 } elseif ($arg === FALSE) {
467 // ... is boolean 'FALSE'
468 $argsString .= ', FALSE';
472 $argsString .= '), ';
476 if (substr($argsString, -2, 1) == ',') {
477 $argsString = substr($argsString, 0, -2);
480 // Invalid arguments!
481 $argsString = '!INVALID:' . gettype($args) . '!';
484 // Output stub message
485 // @TODO __CLASS__ does always return BaseFrameworkSystem but not the extending (=child) class
486 self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[unknown::%s:] Stub! Args: %s',
496 * Getter for $realClass
498 * @return $realClass The name of the real class (not BaseFrameworkSystem)
500 public function __toString () {
501 return $this->realClass;
505 * Magic function to catch setting of missing but set class fields/attributes
507 * @param $name Name of the field/attribute
508 * @param $value Value to store
511 public final function __set ($name, $value) {
512 $this->debugBackTrace(sprintf('Tried to set a missing field. name=%s, value[%s]=%s',
515 print_r($value, TRUE)
520 * Magic function to catch getting of missing fields/attributes
522 * @param $name Name of the field/attribute
525 public final function __get ($name) {
526 $this->debugBackTrace(sprintf('Tried to get a missing field. name=%s',
532 * Magic function to catch unsetting of missing fields/attributes
534 * @param $name Name of the field/attribute
537 public final function __unset ($name) {
538 $this->debugBackTrace(sprintf('Tried to unset a missing field. name=%s',
544 * Setter for the real class name
546 * @param $realClass Class name (string)
549 public final function setRealClass ($realClass) {
551 $this->realClass = (string) $realClass;
555 * Setter for database result instance
557 * @param $resultInstance An instance of a database result class
559 * @todo SearchableResult and UpdateableResult shall have a super interface to use here
561 protected final function setResultInstance (SearchableResult $resultInstance) {
562 $this->resultInstance = $resultInstance;
566 * Getter for database result instance
568 * @return $resultInstance An instance of a database result class
570 public final function getResultInstance () {
571 return $this->resultInstance;
575 * Setter for template engine instances
577 * @param $templateInstance An instance of a template engine class
580 protected final function setTemplateInstance (CompileableTemplate $templateInstance) {
581 $this->templateInstance = $templateInstance;
585 * Getter for template engine instances
587 * @return $templateInstance An instance of a template engine class
589 protected final function getTemplateInstance () {
590 return $this->templateInstance;
594 * Setter for search instance
596 * @param $searchInstance Searchable criteria instance
599 public final function setSearchInstance (LocalSearchCriteria $searchInstance) {
600 $this->searchInstance = $searchInstance;
604 * Getter for search instance
606 * @return $searchInstance Searchable criteria instance
608 public final function getSearchInstance () {
609 return $this->searchInstance;
613 * Setter for update instance
615 * @param $updateInstance Searchable criteria instance
618 public final function setUpdateInstance (LocalUpdateCriteria $updateInstance) {
619 $this->updateInstance = $updateInstance;
623 * Getter for update instance
625 * @return $updateInstance Updateable criteria instance
627 public final function getUpdateInstance () {
628 return $this->updateInstance;
632 * Setter for resolver instance
634 * @param $resolverInstance Instance of a command resolver class
637 public final function setResolverInstance (Resolver $resolverInstance) {
638 $this->resolverInstance = $resolverInstance;
642 * Getter for resolver instance
644 * @return $resolverInstance Instance of a command resolver class
646 public final function getResolverInstance () {
647 return $this->resolverInstance;
651 * Setter for language instance
653 * @param $configInstance The configuration instance which shall
654 * be FrameworkConfiguration
657 public final function setConfigInstance (FrameworkConfiguration $configInstance) {
658 Registry::getRegistry()->addInstance('config', $configInstance);
662 * Getter for configuration instance
664 * @return $configInstance Configuration instance
666 public final function getConfigInstance () {
667 $configInstance = Registry::getRegistry()->getInstance('config');
668 return $configInstance;
672 * Setter for debug instance
674 * @param $debugInstance The instance for debug output class
677 public final function setDebugInstance (DebugMiddleware $debugInstance) {
678 Registry::getRegistry()->addInstance('debug', $debugInstance);
682 * Getter for debug instance
684 * @return $debugInstance Instance to class DebugConsoleOutput or DebugWebOutput
686 public final function getDebugInstance () {
687 // Get debug instance
688 $debugInstance = Registry::getRegistry()->getInstance('debug');
691 return $debugInstance;
695 * Setter for web output instance
697 * @param $webInstance The instance for web output class
700 public final function setWebOutputInstance (OutputStreamer $webInstance) {
701 Registry::getRegistry()->addInstance('web_output', $webInstance);
705 * Getter for web output instance
707 * @return $webOutputInstance - Instance to class WebOutput
709 public final function getWebOutputInstance () {
710 $webOutputInstance = Registry::getRegistry()->getInstance('web_output');
711 return $webOutputInstance;
715 * Setter for database instance
717 * @param $databaseInstance The instance for the database connection (forced DatabaseConnection)
720 public final function setDatabaseInstance (DatabaseConnection $databaseInstance) {
721 Registry::getRegistry()->addInstance('db_instance', $databaseInstance);
725 * Getter for database layer
727 * @return $databaseInstance The database layer instance
729 public final function getDatabaseInstance () {
731 $databaseInstance = Registry::getRegistry()->getInstance('db_instance');
734 return $databaseInstance;
738 * Setter for compressor channel
740 * @param $compressorInstance An instance of CompressorChannel
743 public final function setCompressorChannel (CompressorChannel $compressorInstance) {
744 Registry::getRegistry()->addInstance('compressor', $compressorInstance);
748 * Getter for compressor channel
750 * @return $compressorInstance The compressor channel
752 public final function getCompressorChannel () {
753 $compressorInstance = Registry::getRegistry()->getInstance('compressor');
754 return $compressorInstance;
758 * Protected getter for a manageable application helper class
760 * @return $applicationInstance An instance of a manageable application helper class
762 protected final function getApplicationInstance () {
763 $applicationInstance = Registry::getRegistry()->getInstance('application');
764 return $applicationInstance;
768 * Setter for a manageable application helper class
770 * @param $applicationInstance An instance of a manageable application helper class
773 public final function setApplicationInstance (ManageableApplication $applicationInstance) {
774 Registry::getRegistry()->addInstance('application', $applicationInstance);
778 * Setter for request instance
780 * @param $requestInstance An instance of a Requestable class
783 public final function setRequestInstance (Requestable $requestInstance) {
784 $this->requestInstance = $requestInstance;
788 * Getter for request instance
790 * @return $requestInstance An instance of a Requestable class
792 public final function getRequestInstance () {
793 return $this->requestInstance;
797 * Setter for response instance
799 * @param $responseInstance An instance of a Responseable class
802 public final function setResponseInstance (Responseable $responseInstance) {
803 $this->responseInstance = $responseInstance;
807 * Getter for response instance
809 * @return $responseInstance An instance of a Responseable class
811 public final function getResponseInstance () {
812 return $this->responseInstance;
816 * Private getter for language instance
818 * @return $langInstance An instance to the language sub-system
820 protected final function getLanguageInstance () {
821 $langInstance = Registry::getRegistry()->getInstance('language');
822 return $langInstance;
826 * Setter for language instance
828 * @param $langInstance An instance to the language sub-system
830 * @see LanguageSystem
832 public final function setLanguageInstance (ManageableLanguage $langInstance) {
833 Registry::getRegistry()->addInstance('language', $langInstance);
837 * Private getter for file IO instance
839 * @return $fileIoInstance An instance to the file I/O sub-system
841 protected final function getFileIoInstance () {
842 return $this->fileIoInstance;
846 * Setter for file I/O instance
848 * @param $fileIoInstance An instance to the file I/O sub-system
851 public final function setFileIoInstance (IoHandler $fileIoInstance) {
852 $this->fileIoInstance = $fileIoInstance;
856 * Protected setter for user instance
858 * @param $userInstance An instance of a user class
861 protected final function setUserInstance (ManageableAccount $userInstance) {
862 $this->userInstance = $userInstance;
866 * Getter for user instance
868 * @return $userInstance An instance of a user class
870 public final function getUserInstance () {
871 return $this->userInstance;
875 * Setter for controller instance (this surely breaks a bit the MVC patterm)
877 * @param $controllerInstance An instance of the controller
880 public final function setControllerInstance (Controller $controllerInstance) {
881 $this->controllerInstance = $controllerInstance;
885 * Getter for controller instance (this surely breaks a bit the MVC patterm)
887 * @return $controllerInstance An instance of the controller
889 public final function getControllerInstance () {
890 return $this->controllerInstance;
894 * Setter for RNG instance
896 * @param $rngInstance An instance of a random number generator (RNG)
899 protected final function setRngInstance (RandomNumberGenerator $rngInstance) {
900 $this->rngInstance = $rngInstance;
904 * Getter for RNG instance
906 * @return $rngInstance An instance of a random number generator (RNG)
908 public final function getRngInstance () {
909 return $this->rngInstance;
913 * Setter for Cryptable instance
915 * @param $cryptoInstance An instance of a Cryptable class
918 protected final function setCryptoInstance (Cryptable $cryptoInstance) {
919 $this->cryptoInstance = $cryptoInstance;
923 * Getter for Cryptable instance
925 * @return $cryptoInstance An instance of a Cryptable class
927 public final function getCryptoInstance () {
928 return $this->cryptoInstance;
932 * Setter for the list instance
934 * @param $listInstance A list of Listable
937 protected final function setListInstance (Listable $listInstance) {
938 $this->listInstance = $listInstance;
942 * Getter for the list instance
944 * @return $listInstance A list of Listable
946 protected final function getListInstance () {
947 return $this->listInstance;
951 * Setter for the menu instance
953 * @param $menuInstance A RenderableMenu instance
956 protected final function setMenuInstance (RenderableMenu $menuInstance) {
957 $this->menuInstance = $menuInstance;
961 * Getter for the menu instance
963 * @return $menuInstance A RenderableMenu instance
965 protected final function getMenuInstance () {
966 return $this->menuInstance;
970 * Setter for image instance
972 * @param $imageInstance An instance of an image
975 public final function setImageInstance (BaseImage $imageInstance) {
976 $this->imageInstance = $imageInstance;
980 * Getter for image instance
982 * @return $imageInstance An instance of an image
984 public final function getImageInstance () {
985 return $this->imageInstance;
989 * Setter for stacker instance
991 * @param $stackInstance An instance of an stacker
994 public final function setStackInstance (Stackable $stackInstance) {
995 $this->stackInstance = $stackInstance;
999 * Getter for stacker instance
1001 * @return $stackInstance An instance of an stacker
1003 public final function getStackInstance () {
1004 return $this->stackInstance;
1008 * Setter for compressor instance
1010 * @param $compressorInstance An instance of an compressor
1013 public final function setCompressorInstance (Compressor $compressorInstance) {
1014 $this->compressorInstance = $compressorInstance;
1018 * Getter for compressor instance
1020 * @return $compressorInstance An instance of an compressor
1022 public final function getCompressorInstance () {
1023 return $this->compressorInstance;
1027 * Setter for Parseable instance
1029 * @param $parserInstance An instance of an Parseable
1032 public final function setParserInstance (Parseable $parserInstance) {
1033 $this->parserInstance = $parserInstance;
1037 * Getter for Parseable instance
1039 * @return $parserInstance An instance of an Parseable
1041 public final function getParserInstance () {
1042 return $this->parserInstance;
1046 * Setter for HandleableProtocol instance
1048 * @param $protocolInstance An instance of an HandleableProtocol
1051 public final function setProtocolInstance (HandleableProtocol $protocolInstance) {
1052 $this->protocolInstance = $protocolInstance;
1056 * Getter for HandleableProtocol instance
1058 * @return $protocolInstance An instance of an HandleableProtocol
1060 public final function getProtocolInstance () {
1061 return $this->protocolInstance;
1065 * Setter for DatabaseWrapper instance
1067 * @param $wrapperInstance An instance of an DatabaseWrapper
1070 public final function setWrapperInstance (DatabaseWrapper $wrapperInstance) {
1071 $this->wrapperInstance = $wrapperInstance;
1075 * Getter for DatabaseWrapper instance
1077 * @return $wrapperInstance An instance of an DatabaseWrapper
1079 public final function getWrapperInstance () {
1080 return $this->wrapperInstance;
1084 * Setter for socket resource
1086 * @param $socketResource A valid socket resource
1089 public final function setSocketResource ($socketResource) {
1090 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput($this->__toString() . '::' . __FUNCTION__ . ': socketResource=' . $socketResource . ',previous[' . gettype($this->socketResource) . ']=' . $this->socketResource);
1091 $this->socketResource = $socketResource;
1095 * Getter for socket resource
1097 * @return $socketResource A valid socket resource
1099 public final function getSocketResource () {
1100 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput($this->__toString() . '::' . __FUNCTION__ . ': socketResource[' . gettype($this->socketResource) . ']=' . $this->socketResource);
1101 return $this->socketResource;
1105 * Setter for regular expression
1107 * @param $regularExpression A valid regular expression
1110 public final function setRegularExpression ($regularExpression) {
1111 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput($this->__toString() . '::' . __FUNCTION__ . ': regularExpression=' . $regularExpression . ',previous[' . gettype($this->regularExpression) . ']=' . $this->regularExpression);
1112 $this->regularExpression = $regularExpression;
1116 * Getter for regular expression
1118 * @return $regularExpression A valid regular expression
1120 public final function getRegularExpression () {
1121 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput($this->__toString() . '::' . __FUNCTION__ . ': regularExpression[' . gettype($this->regularExpression) . ']=' . $this->regularExpression);
1122 return $this->regularExpression;
1126 * Setter for helper instance
1128 * @param $helperInstance An instance of a helper class
1131 protected final function setHelperInstance (Helper $helperInstance) {
1132 $this->helperInstance = $helperInstance;
1136 * Getter for helper instance
1138 * @return $helperInstance An instance of a helper class
1140 public final function getHelperInstance () {
1141 return $this->helperInstance;
1145 * Setter for a Sourceable instance
1147 * @param $sourceInstance An instance of a Sourceable class
1150 protected final function setSourceInstance (Sourceable $sourceInstance) {
1151 $this->sourceInstance = $sourceInstance;
1155 * Getter for a Sourceable instance
1157 * @return $sourceInstance An instance of a Sourceable class
1159 protected final function getSourceInstance () {
1160 return $this->sourceInstance;
1164 * Setter for a UrlSource instance
1166 * @param $sourceInstance An instance of a UrlSource class
1169 protected final function setUrlSourceInstance (UrlSource $urlSourceInstance) {
1170 $this->urlSourceInstance = $urlSourceInstance;
1174 * Getter for a UrlSource instance
1176 * @return $urlSourceInstance An instance of a UrlSource class
1178 protected final function getUrlSourceInstance () {
1179 return $this->urlSourceInstance;
1183 * Getter for a InputStream instance
1185 * @param $inputStreamInstance The InputStream instance
1187 protected final function getInputStreamInstance () {
1188 return $this->inputStreamInstance;
1192 * Setter for a InputStream instance
1194 * @param $inputStreamInstance The InputStream instance
1197 protected final function setInputStreamInstance (InputStream $inputStreamInstance) {
1198 $this->inputStreamInstance = $inputStreamInstance;
1202 * Getter for a OutputStream instance
1204 * @param $outputStreamInstance The OutputStream instance
1206 protected final function getOutputStreamInstance () {
1207 return $this->outputStreamInstance;
1211 * Setter for a OutputStream instance
1213 * @param $outputStreamInstance The OutputStream instance
1216 protected final function setOutputStreamInstance (OutputStream $outputStreamInstance) {
1217 $this->outputStreamInstance = $outputStreamInstance;
1221 * Setter for handler instance
1223 * @param $handlerInstance An instance of a Handleable class
1226 protected final function setHandlerInstance (Handleable $handlerInstance) {
1227 $this->handlerInstance = $handlerInstance;
1231 * Getter for handler instance
1233 * @return $handlerInstance A Networkable instance
1235 protected final function getHandlerInstance () {
1236 return $this->handlerInstance;
1240 * Setter for visitor instance
1242 * @param $visitorInstance A Visitor instance
1245 protected final function setVisitorInstance (Visitor $visitorInstance) {
1246 $this->visitorInstance = $visitorInstance;
1250 * Getter for visitor instance
1252 * @return $visitorInstance A Visitor instance
1254 protected final function getVisitorInstance () {
1255 return $this->visitorInstance;
1259 * Setter for DHT instance
1261 * @param $dhtInstance A Distributable instance
1264 protected final function setDhtInstance (Distributable $dhtInstance) {
1265 $this->dhtInstance = $dhtInstance;
1269 * Getter for DHT instance
1271 * @return $dhtInstance A Distributable instance
1273 protected final function getDhtInstance () {
1274 return $this->dhtInstance;
1278 * Setter for raw package Data
1280 * @param $packageData Raw package Data
1283 public final function setPackageData (array $packageData) {
1284 $this->packageData = $packageData;
1288 * Getter for raw package Data
1290 * @return $packageData Raw package Data
1292 public function getPackageData () {
1293 return $this->packageData;
1298 * Setter for Iterator instance
1300 * @param $iteratorInstance An instance of an Iterator
1303 protected final function setIteratorInstance (Iterator $iteratorInstance) {
1304 $this->iteratorInstance = $iteratorInstance;
1308 * Getter for Iterator instance
1310 * @return $iteratorInstance An instance of an Iterator
1312 public final function getIteratorInstance () {
1313 return $this->iteratorInstance;
1317 * Setter for FilePointer instance
1319 * @param $pointerInstance An instance of an FilePointer class
1322 protected final function setPointerInstance (FilePointer $pointerInstance) {
1323 $this->pointerInstance = $pointerInstance;
1327 * Getter for FilePointer instance
1329 * @return $pointerInstance An instance of an FilePointer class
1331 public final function getPointerInstance () {
1332 return $this->pointerInstance;
1336 * Unsets pointer instance which triggers a call of __destruct() if the
1337 * instance is still there. This is surely not fatal on already "closed"
1338 * file pointer instances.
1340 * I don't want to mess around with above setter by giving it a default
1341 * value NULL as setter should always explicitly only set (existing) object
1342 * instances and NULL is NULL.
1346 protected final function unsetPointerInstance () {
1347 // Simply it to NULL
1348 $this->pointerInstance = NULL;
1352 * Setter for Indexable instance
1354 * @param $indexInstance An instance of an Indexable class
1357 protected final function setIndexInstance (Indexable $indexInstance) {
1358 $this->indexInstance = $indexInstance;
1362 * Getter for Indexable instance
1364 * @return $indexInstance An instance of an Indexable class
1366 public final function getIndexInstance () {
1367 return $this->indexInstance;
1371 * Setter for Block instance
1373 * @param $blockInstance An instance of an Block class
1376 protected final function setBlockInstance (Block $blockInstance) {
1377 $this->blockInstance = $blockInstance;
1381 * Getter for Block instance
1383 * @return $blockInstance An instance of an Block class
1385 public final function getBlockInstance () {
1386 return $this->blockInstance;
1390 * Setter for Minable instance
1392 * @param $minableInstance A Minable instance
1395 protected final function setMinableInstance (Minable $minableInstance) {
1396 $this->minableInstance = $minableInstance;
1400 * Getter for minable instance
1402 * @return $minableInstance A Minable instance
1404 protected final function getMinableInstance () {
1405 return $this->minableInstance;
1409 * Setter for FrameworkDirectory instance
1411 * @param $directoryInstance A FrameworkDirectoryPointer instance
1414 protected final function setDirectoryInstance (FrameworkDirectory $directoryInstance) {
1415 $this->directoryInstance = $directoryInstance;
1419 * Getter for FrameworkDirectory instance
1421 * @return $directoryInstance A FrameworkDirectory instance
1423 protected final function getDirectoryInstance () {
1424 return $this->directoryInstance;
1428 * Setter for listener instance
1430 * @param $listenerInstance A Listenable instance
1433 protected final function setListenerInstance (Listenable $listenerInstance) {
1434 $this->listenerInstance = $listenerInstance;
1438 * Getter for listener instance
1440 * @return $listenerInstance A Listenable instance
1442 protected final function getListenerInstance () {
1443 return $this->listenerInstance;
1447 * Setter for command name
1449 * @param $commandName Last validated command name
1452 protected final function setCommandName ($commandName) {
1453 $this->commandName = $commandName;
1457 * Getter for command name
1459 * @return $commandName Last validated command name
1461 protected final function getCommandName () {
1462 return $this->commandName;
1466 * Setter for controller name
1468 * @param $controllerName Last validated controller name
1471 protected final function setControllerName ($controllerName) {
1472 $this->controllerName = $controllerName;
1476 * Getter for controller name
1478 * @return $controllerName Last validated controller name
1480 protected final function getControllerName () {
1481 return $this->controllerName;
1485 * Checks whether an object equals this object. You should overwrite this
1486 * method to implement own equality checks
1488 * @param $objectInstance An instance of a FrameworkInterface object
1489 * @return $equals Whether both objects equals
1491 public function equals (FrameworkInterface $objectInstance) {
1494 $this->__toString() == $objectInstance->__toString()
1496 $this->hashCode() == $objectInstance->hashCode()
1499 // Return the result
1504 * Generates a generic hash code of this class. You should really overwrite
1505 * this method with your own hash code generator code. But keep KISS in mind.
1507 * @return $hashCode A generic hash code respresenting this whole class
1509 public function hashCode () {
1511 return crc32($this->__toString());
1515 * Formats computer generated price values into human-understandable formats
1516 * with thousand and decimal separators.
1518 * @param $value The in computer format value for a price
1519 * @param $currency The currency symbol (use HTML-valid characters!)
1520 * @param $decNum Number of decimals after commata
1521 * @return $price The for the current language formated price string
1522 * @throws MissingDecimalsThousandsSeparatorException If decimals or
1523 * thousands separator
1526 public function formatCurrency ($value, $currency = '€', $decNum = 2) {
1527 // Are all required attriutes set?
1528 if ((!isset($this->decimals)) || (!isset($this->thousands))) {
1529 // Throw an exception
1530 throw new MissingDecimalsThousandsSeparatorException($this, self::EXCEPTION_ATTRIBUTES_ARE_MISSING);
1534 $value = (float) $value;
1536 // Reformat the US number
1537 $price = number_format($value, $decNum, $this->decimals, $this->thousands) . $currency;
1539 // Return as string...
1544 * Appends a trailing slash to a string
1546 * @param $str A string (maybe) without trailing slash
1547 * @return $str A string with an auto-appended trailing slash
1549 public final function addMissingTrailingSlash ($str) {
1550 // Is there a trailing slash?
1551 if (substr($str, -1, 1) != '/') {
1555 // Return string with trailing slash
1560 * Prepare the template engine (HtmlTemplateEngine by default) for a given
1561 * application helper instance (ApplicationHelper by default).
1563 * @param $applicationInstance An application helper instance or
1564 * null if we shall use the default
1565 * @return $templateInstance The template engine instance
1566 * @throws NullPointerException If the discovered application
1567 * instance is still null
1569 protected function prepareTemplateInstance (ManageableApplication $applicationInstance = NULL) {
1570 // Is the application instance set?
1571 if (is_null($applicationInstance)) {
1572 // Get the current instance
1573 $applicationInstance = $this->getApplicationInstance();
1576 if (is_null($applicationInstance)) {
1577 // Thrown an exception
1578 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
1582 // Initialize the template engine
1583 $templateInstance = ObjectFactory::createObjectByConfiguredName('html_template_class');
1585 // Return the prepared instance
1586 return $templateInstance;
1590 * Debugs this instance by putting out it's full content
1592 * @param $message Optional message to show in debug output
1595 public final function debugInstance ($message = '') {
1596 // Restore the error handler to avoid trouble with missing array elements or undeclared variables
1597 restore_error_handler();
1602 // Is a message set?
1603 if (!empty($message)) {
1604 // Construct message
1605 $content = sprintf('<div class="debug_message">Message: %s</div>' . PHP_EOL, $message);
1608 // Generate the output
1609 $content .= sprintf('<pre>%s</pre>',
1612 print_r($this, TRUE)
1618 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>',
1619 $this->__toString(),
1621 ClassLoader::getSelfInstance()->getPrintableIncludeList()
1626 * Replaces control characters with printable output
1628 * @param $str String with control characters
1629 * @return $str Replaced string
1631 protected function replaceControlCharacters ($str) {
1634 chr(13), '[r]', str_replace(
1635 chr(10), '[n]', str_replace(
1645 * Output a partial stub message for the caller method
1647 * @param $message An optional message to display
1650 protected function partialStub ($message = '') {
1651 // Get the backtrace
1652 $backtrace = debug_backtrace();
1654 // Generate the class::method string
1655 $methodName = 'UnknownClass->unknownMethod';
1656 if ((isset($backtrace[1]['class'])) && (isset($backtrace[1]['function']))) {
1657 $methodName = $backtrace[1]['class'] . '->' . $backtrace[1]['function'];
1660 // Construct the full message
1661 $stubMessage = sprintf('[%s:] Partial stub!',
1665 // Is the extra message given?
1666 if (!empty($message)) {
1667 // Then add it as well
1668 $stubMessage .= ' Message: ' . $message;
1671 // Debug instance is there?
1672 if (!is_null($this->getDebugInstance())) {
1673 // Output stub message
1674 self::createDebugInstance(__CLASS__)->debugOutput($stubMessage);
1677 trigger_error($stubMessage);
1683 * Outputs a debug backtrace and stops further script execution
1685 * @param $message An optional message to output
1686 * @param $doExit Whether exit the program (TRUE is default)
1689 public function debugBackTrace ($message = '', $doExit = TRUE) {
1690 // Sorry, there is no other way getting this nice backtrace
1691 if (!empty($message)) {
1693 printf('Message: %s<br />' . chr(10), $message);
1697 debug_print_backtrace();
1701 if ($doExit === TRUE) {
1707 * Creates an instance of a debugger instance
1709 * @param $className Name of the class (currently unsupported)
1710 * @return $debugInstance An instance of a debugger class
1712 public final static function createDebugInstance ($className) {
1713 // Is the instance set?
1714 if (!Registry::getRegistry()->instanceExists('debug')) {
1715 // Init debug instance
1716 $debugInstance = NULL;
1720 // Get a debugger instance
1721 $debugInstance = DebugMiddleware::createDebugMiddleware(FrameworkConfiguration::getSelfInstance()->getConfigEntry('debug_' . self::getResponseTypeFromSystem() . '_class'));
1722 } catch (NullPointerException $e) {
1723 // Didn't work, no instance there
1724 exit('Cannot create debugInstance! Exception=' . $e->__toString() . ', message=' . $e->getMessage());
1727 // Empty string should be ignored and used for testing the middleware
1728 DebugMiddleware::getSelfInstance()->output('');
1730 // Set it in its own class. This will set it in the registry
1731 $debugInstance->setDebugInstance($debugInstance);
1733 // Get instance from registry
1734 $debugInstance = Registry::getRegistry()->getDebugInstance();
1738 return $debugInstance;
1742 * Simple output of a message with line-break
1744 * @param $message Message to output
1747 public function outputLine ($message) {
1749 print($message . PHP_EOL);
1753 * Outputs a debug message whether to debug instance (should be set!) or
1754 * dies with or ptints the message. Do NEVER EVER rewrite the exit() call to
1755 * ApplicationEntryPoint::app_exit(), this would cause an endless loop.
1757 * @param $message Message we shall send out...
1758 * @param $doPrint Whether print or die here (default: print)
1759 * @paran $stripTags Whether to strip tags (default: FALSE)
1762 public function debugOutput ($message, $doPrint = TRUE, $stripTags = FALSE) {
1763 // Set debug instance to NULL
1764 $debugInstance = NULL;
1768 // Get debug instance
1769 $debugInstance = $this->getDebugInstance();
1770 } catch (NullPointerException $e) {
1771 // The debug instance is not set (yet)
1774 // Is the debug instance there?
1775 if (is_object($debugInstance)) {
1776 // Use debug output handler
1777 $debugInstance->output($message, $stripTags);
1779 if ($doPrint === FALSE) {
1780 // Die here if not printed
1784 // Are debug times enabled?
1785 if ($this->getConfigInstance()->getConfigEntry('debug_output_timings') == 'Y') {
1787 $message = $this->getPrintableExecutionTime() . $message;
1791 if ($doPrint === TRUE) {
1793 $this->outputLine($message);
1802 * Converts e.g. a command from URL to a valid class by keeping out bad characters
1804 * @param $str The string, what ever it is needs to be converted
1805 * @return $className Generated class name
1807 public function convertToClassName ($str) {
1811 // Convert all dashes in underscores
1812 $str = $this->convertDashesToUnderscores($str);
1814 // Now use that underscores to get classname parts for hungarian style
1815 foreach (explode('_', $str) as $strPart) {
1816 // Make the class name part lower case and first upper case
1817 $className .= ucfirst(strtolower($strPart));
1820 // Return class name
1825 * Converts dashes to underscores, e.g. useable for configuration entries
1827 * @param $str The string with maybe dashes inside
1828 * @return $str The converted string with no dashed, but underscores
1830 public final function convertDashesToUnderscores ($str) {
1832 $str = str_replace('-', '_', $str);
1834 // Return converted string
1839 * Marks up the code by adding e.g. line numbers
1841 * @param $phpCode Unmarked PHP code
1842 * @return $markedCode Marked PHP code
1844 public function markupCode ($phpCode) {
1849 $errorArray = error_get_last();
1851 // Init the code with error message
1852 if (is_array($errorArray)) {
1854 $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>',
1855 basename($errorArray['file']),
1856 $errorArray['line'],
1857 $errorArray['message'],
1862 // Add line number to the code
1863 foreach (explode(chr(10), $phpCode) as $lineNo => $code) {
1865 $markedCode .= sprintf('<span id="code_line">%s</span>: %s' . chr(10),
1867 htmlentities($code, ENT_QUOTES)
1876 * Filter a given GMT timestamp (non Uni* stamp!) to make it look more
1877 * beatiful for web-based front-ends. If null is given a message id
1878 * null_timestamp will be resolved and returned.
1880 * @param $timestamp Timestamp to prepare (filter) for display
1881 * @return $readable A readable timestamp
1883 public function doFilterFormatTimestamp ($timestamp) {
1884 // Default value to return
1887 // Is the timestamp null?
1888 if (is_null($timestamp)) {
1889 // Get a message string
1890 $readable = $this->getLanguageInstance()->getMessage('null_timestamp');
1892 switch ($this->getLanguageInstance()->getLanguageCode()) {
1893 case 'de': // German format is a bit different to default
1894 // Split the GMT stamp up
1895 $dateTime = explode(' ', $timestamp );
1896 $dateArray = explode('-', $dateTime[0]);
1897 $timeArray = explode(':', $dateTime[1]);
1899 // Construct the timestamp
1900 $readable = sprintf($this->getConfigInstance()->getConfigEntry('german_date_time'),
1910 default: // Default is pass-through
1911 $readable = $timestamp;
1921 * Filter a given number into a localized number
1923 * @param $value The raw value from e.g. database
1924 * @return $localized Localized value
1926 public function doFilterFormatNumber ($value) {
1927 // Generate it from config and localize dependencies
1928 switch ($this->getLanguageInstance()->getLanguageCode()) {
1929 case 'de': // German format is a bit different to default
1930 $localized = number_format($value, $this->getConfigInstance()->getConfigEntry('decimals'), ',', '.');
1933 default: // US, etc.
1934 $localized = number_format($value, $this->getConfigInstance()->getConfigEntry('decimals'), '.', ',');
1943 * "Getter" for databse entry
1945 * @return $entry An array with database entries
1946 * @throws NullPointerException If the database result is not found
1947 * @throws InvalidDatabaseResultException If the database result is invalid
1949 protected final function getDatabaseEntry () {
1950 // Is there an instance?
1951 if (is_null($this->getResultInstance())) {
1952 // Throw an exception here
1953 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
1957 $this->getResultInstance()->rewind();
1959 // Do we have an entry?
1960 if ($this->getResultInstance()->valid() === FALSE) {
1961 // @TODO Move the constant to e.g. BaseDatabaseResult when there is a non-cached database result available
1962 throw new InvalidDatabaseResultException(array($this, $this->getResultInstance()), CachedDatabaseResult::EXCEPTION_INVALID_DATABASE_RESULT);
1966 $this->getResultInstance()->next();
1969 $entry = $this->getResultInstance()->current();
1976 * Getter for field name
1978 * @param $fieldName Field name which we shall get
1979 * @return $fieldValue Field value from the user
1980 * @throws NullPointerException If the result instance is null
1982 public final function getField ($fieldName) {
1983 // Default field value
1986 // Get result instance
1987 $resultInstance = $this->getResultInstance();
1989 // Is this instance null?
1990 if (is_null($resultInstance)) {
1991 // Then the user instance is no longer valid (expired cookies?)
1992 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
1995 // Get current array
1996 $fieldArray = $resultInstance->current();
1997 //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput($fieldName.':<pre>'.print_r($fieldArray, TRUE).'</pre>');
1999 // Convert dashes to underscore
2000 $fieldName = $this->convertDashesToUnderscores($fieldName);
2002 // Does the field exist?
2003 if (isset($fieldArray[$fieldName])) {
2005 $fieldValue = $fieldArray[$fieldName];
2007 // Missing field entry, may require debugging
2008 self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']:fieldName=' . $fieldName . ' not found!');
2016 * Flushs all pending updates to the database layer
2020 public function flushPendingUpdates () {
2021 // Get result instance
2022 $resultInstance = $this->getResultInstance();
2024 // Do we have data to update?
2025 if ((is_object($resultInstance)) && ($resultInstance->ifDataNeedsFlush())) {
2026 // Get wrapper class name config entry
2027 $configEntry = $resultInstance->getUpdateInstance()->getWrapperConfigEntry();
2029 // Create object instance
2030 $wrapperInstance = ObjectFactory::createObjectByConfiguredName($configEntry);
2032 // Yes, then send the whole result to the database layer
2033 $wrapperInstance->doUpdateByResult($this->getResultInstance());
2038 * Outputs a deprecation warning to the developer.
2040 * @param $message The message we shall output to the developer
2042 * @todo Write a logging mechanism for productive mode
2044 public function deprecationWarning ($message) {
2045 // Is developer mode active?
2046 if (defined('DEVELOPER')) {
2047 // Debug instance is there?
2048 if (!is_null($this->getDebugInstance())) {
2049 // Output stub message
2050 self::createDebugInstance(__CLASS__)->debugOutput($message);
2053 trigger_error($message . "<br />\n");
2057 // @TODO Finish this part!
2058 $this->partialStub('Developer mode inactive. Message:' . $message);
2063 * Checks whether the given PHP extension is loaded
2065 * @param $phpExtension The PHP extension we shall check
2066 * @return $isLoaded Whether the PHP extension is loaded
2068 public final function isPhpExtensionLoaded ($phpExtension) {
2070 $isLoaded = in_array($phpExtension, get_loaded_extensions());
2077 * "Getter" as a time() replacement but with milliseconds. You should use this
2078 * method instead of the encapsulated getimeofday() function.
2080 * @return $milliTime Timestamp with milliseconds
2082 public function getMilliTime () {
2083 // Get the time of day as float
2084 $milliTime = gettimeofday(TRUE);
2091 * Idles (sleeps) for given milliseconds
2093 * @return $hasSlept Whether it goes fine
2095 public function idle ($milliSeconds) {
2096 // Sleep is fine by default
2099 // Idle so long with found function
2100 if (function_exists('time_sleep_until')) {
2101 // Get current time and add idle time
2102 $sleepUntil = $this->getMilliTime() + abs($milliSeconds) / 1000;
2104 // New PHP 5.1.0 function found, ignore errors
2105 $hasSlept = @time_sleep_until($sleepUntil);
2108 * My Sun station doesn't have that function even with latest PHP
2111 usleep($milliSeconds * 1000);
2118 * Converts a hexadecimal string, even with negative sign as first string to
2119 * a decimal number using BC functions.
2121 * This work is based on comment #86673 on php.net documentation page at:
2122 * <http://de.php.net/manual/en/function.dechex.php#86673>
2124 * @param $hex Hexadecimal string
2125 * @return $dec Decimal number
2127 protected function hex2dec ($hex) {
2128 // Convert to all lower-case
2129 $hex = strtolower($hex);
2131 // Detect sign (negative/positive numbers)
2133 if (substr($hex, 0, 1) == '-') {
2135 $hex = substr($hex, 1);
2138 // Decode the hexadecimal string into a decimal number
2140 for ($i = strlen($hex) - 1, $e = 1; $i >= 0; $i--, $e = bcmul($e, 16)) {
2141 $factor = self::$hexdec[substr($hex, $i, 1)];
2142 $dec = bcadd($dec, bcmul($factor, $e));
2145 // Return the decimal number
2146 return $sign . $dec;
2150 * Converts even very large decimal numbers, also signed, to a hexadecimal
2153 * This work is based on comment #97756 on php.net documentation page at:
2154 * <http://de.php.net/manual/en/function.hexdec.php#97756>
2156 * @param $dec Decimal number, even with negative sign
2157 * @param $maxLength Optional maximum length of the string
2158 * @return $hex Hexadecimal string
2160 protected function dec2hex ($dec, $maxLength = 0) {
2161 // maxLength can be zero or devideable by 2
2162 assert(($maxLength == 0) || (($maxLength % 2) == 0));
2164 // Detect sign (negative/positive numbers)
2171 // Encode the decimal number into a hexadecimal string
2174 $hex = self::$dechex[($dec % (2 ^ 4))] . $hex;
2176 } while ($dec >= 1);
2179 * Leading zeros are required for hex-decimal "numbers". In some
2180 * situations more leading zeros are wanted, so check for both
2183 if ($maxLength > 0) {
2184 // Prepend more zeros
2185 $hex = str_pad($hex, $maxLength, '0', STR_PAD_LEFT);
2186 } elseif ((strlen($hex) % 2) != 0) {
2187 // Only make string's length dividable by 2
2191 // Return the hexadecimal string
2192 return $sign . $hex;
2196 * Converts a ASCII string (0 to 255) into a decimal number.
2198 * @param $asc The ASCII string to be converted
2199 * @return $dec Decimal number
2201 protected function asc2dec ($asc) {
2202 // Convert it into a hexadecimal number
2203 $hex = bin2hex($asc);
2205 // And back into a decimal number
2206 $dec = $this->hex2dec($hex);
2213 * Converts a decimal number into an ASCII string.
2215 * @param $dec Decimal number
2216 * @return $asc An ASCII string
2218 protected function dec2asc ($dec) {
2219 // First convert the number into a hexadecimal string
2220 $hex = $this->dec2hex($dec);
2222 // Then convert it into the ASCII string
2223 $asc = $this->hex2asc($hex);
2230 * Converts a hexadecimal number into an ASCII string. Negative numbers
2233 * @param $hex Hexadecimal string
2234 * @return $asc An ASCII string
2236 protected function hex2asc ($hex) {
2237 // Check for length, it must be devideable by 2
2238 //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('hex='.$hex);
2239 assert((strlen($hex) % 2) == 0);
2243 for ($idx = 0; $idx < strlen($hex); $idx+=2) {
2244 // Get the decimal number of the chunk
2245 $part = hexdec(substr($hex, $idx, 2));
2247 // Add it to the final string
2251 // Return the final string
2256 * Checks whether the given encoded data was encoded with Base64
2258 * @param $encodedData Encoded data we shall check
2259 * @return $isBase64 Whether the encoded data is Base64
2261 protected function isBase64Encoded ($encodedData) {
2263 $isBase64 = (@base64_decode($encodedData, TRUE) !== FALSE);
2270 * "Getter" to get response/request type from analysis of the system.
2272 * @return $responseType Analyzed response type
2274 protected static function getResponseTypeFromSystem () {
2275 // Default is console
2276 $responseType = 'console';
2278 // Is 'HTTP_HOST' set?
2279 if (isset($_SERVER['HTTP_HOST'])) {
2281 * Then it is a HTML response/request as RSS and so on may be
2282 * transfered over HTTP as well.
2284 $responseType = 'html';
2288 return $responseType;
2292 * Gets a cache key from Criteria instance
2294 * @param $criteriaInstance An instance of a Criteria class
2295 * @param $onlyKeys Only use these keys for a cache key
2296 * @return $cacheKey A cache key suitable for lookup/storage purposes
2298 protected function getCacheKeyByCriteria (Criteria $criteriaInstance, array $onlyKeys = array()) {
2300 $cacheKey = sprintf('%s@%s',
2301 $this->__toString(),
2302 $criteriaInstance->getCacheKey($onlyKeys)
2306 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput($this->__toString() . ': cacheKey=' . $cacheKey);
2311 * Getter for startup time in miliseconds
2313 * @return $startupTime Startup time in miliseconds
2315 protected function getStartupTime () {
2316 return self::$startupTime;
2320 * "Getter" for a printable currently execution time in nice braces
2322 * @return $executionTime Current execution time in nice braces
2324 protected function getPrintableExecutionTime () {
2325 // Caculate the execution time
2326 $executionTime = microtime(TRUE) - $this->getStartupTime();
2328 // Pack it in nice braces
2329 $executionTime = sprintf('[ %01.5f ] ', $executionTime);
2332 return $executionTime;
2336 * Hashes a given string with a simple but stronger hash function (no salt)
2337 * and hex-encode it.
2339 * @param $str The string to be hashed
2340 * @return $hash The hash from string $str
2342 public static final function hash ($str) {
2343 // Hash given string with (better secure) hasher
2344 $hash = bin2hex(mhash(MHASH_SHA256, $str));
2351 * "Getter" for length of hash() output. This will be "cached" to speed up
2354 * @return $length Length of hash() output
2356 public static final function getHashLength () {
2358 if (is_null(self::$hashLength)) {
2359 // No, then hash a string and save its length.
2360 self::$hashLength = strlen(self::hash('abc123'));
2364 return self::$hashLength;
2368 * Checks whether the given number is really a number (only chars 0-9).
2370 * @param $num A string consisting only chars between 0 and 9
2371 * @param $castValue Whether to cast the value to double. Do only use this to secure numbers from Requestable classes.
2372 * @param $assertMismatch Whether to assert mismatches
2373 * @return $ret The (hopefully) secured numbered value
2375 public function bigintval ($num, $castValue = TRUE, $assertMismatch = FALSE) {
2376 // Filter all numbers out
2377 $ret = preg_replace('/[^0123456789]/', '', $num);
2380 if ($castValue === TRUE) {
2381 // Cast to biggest numeric type
2382 $ret = (double) $ret;
2385 // Assert only if requested
2386 if ($assertMismatch === TRUE) {
2387 // Has the whole value changed?
2388 assert(('' . $ret . '' != '' . $num . '') && (!is_null($num)));
2396 * Checks whether the given hexadecimal number is really a hex-number (only chars 0-9,a-f).
2398 * @param $num A string consisting only chars between 0 and 9
2399 * @param $assertMismatch Whether to assert mismatches
2400 * @return $ret The (hopefully) secured hext-numbered value
2402 public function hexval ($num, $assertMismatch = FALSE) {
2403 // Filter all numbers out
2404 $ret = preg_replace('/[^0123456789abcdefABCDEF]/', '', $num);
2406 // Assert only if requested
2407 if ($assertMismatch === TRUE) {
2408 // Has the whole value changed?
2409 assert(('' . $ret . '' != '' . $num . '') && (!is_null($num)));
2417 * Checks whether start/end marker are set
2419 * @param $data Data to be checked
2420 * @return $isset Whether start/end marker are set
2422 public final function ifStartEndMarkersSet ($data) {
2424 $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));
2426 // ... and return it
2431 * Determines if an element is set in the generic array
2433 * @param $keyGroup Main group for the key
2434 * @param $subGroup Sub group for the key
2435 * @param $key Key to check
2436 * @param $element Element to check
2437 * @return $isset Whether the given key is set
2439 protected final function isGenericArrayElementSet ($keyGroup, $subGroup, $key, $element) {
2441 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element);
2444 $isset = isset($this->genericArray[$keyGroup][$subGroup][$key][$element]);
2450 * Determines if a key is set in the generic array
2452 * @param $keyGroup Main group for the key
2453 * @param $subGroup Sub group for the key
2454 * @param $key Key to check
2455 * @return $isset Whether the given key is set
2457 protected final function isGenericArrayKeySet ($keyGroup, $subGroup, $key) {
2459 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
2462 $isset = isset($this->genericArray[$keyGroup][$subGroup][$key]);
2470 * Determines if a group is set in the generic array
2472 * @param $keyGroup Main group
2473 * @param $subGroup Sub group
2474 * @return $isset Whether the given group is set
2476 protected final function isGenericArrayGroupSet ($keyGroup, $subGroup) {
2478 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup);
2481 $isset = isset($this->genericArray[$keyGroup][$subGroup]);
2488 * Getter for sub key group
2490 * @param $keyGroup Main key group
2491 * @param $subGroup Sub key group
2492 * @return $array An array with all array elements
2494 protected final function getGenericSubArray ($keyGroup, $subGroup) {
2496 if (!$this->isGenericArrayGroupSet($keyGroup, $subGroup)) {
2497 // No, then abort here
2498 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' not found.');
2503 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',value=' . print_r($this->genericArray[$keyGroup][$subGroup], TRUE));
2506 return $this->genericArray[$keyGroup][$subGroup];
2510 * Unsets a given key in generic array
2512 * @param $keyGroup Main group for the key
2513 * @param $subGroup Sub group for the key
2514 * @param $key Key to unset
2517 protected final function unsetGenericArrayKey ($keyGroup, $subGroup, $key) {
2519 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
2522 unset($this->genericArray[$keyGroup][$subGroup][$key]);
2526 * Unsets a given element in generic array
2528 * @param $keyGroup Main group for the key
2529 * @param $subGroup Sub group for the key
2530 * @param $key Key to unset
2531 * @param $element Element to unset
2534 protected final function unsetGenericArrayElement ($keyGroup, $subGroup, $key, $element) {
2536 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element);
2539 unset($this->genericArray[$keyGroup][$subGroup][$key][$element]);
2543 * Append a string to a given generic array key
2545 * @param $keyGroup Main group for the key
2546 * @param $subGroup Sub group for the key
2547 * @param $key Key to unset
2548 * @param $value Value to add/append
2551 protected final function appendStringToGenericArrayKey ($keyGroup, $subGroup, $key, $value, $appendGlue = '') {
2553 //* 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);
2555 // Is it already there?
2556 if ($this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
2558 $this->genericArray[$keyGroup][$subGroup][$key] .= $appendGlue . (string) $value;
2561 $this->genericArray[$keyGroup][$subGroup][$key] = (string) $value;
2566 * Append a string to a given generic array element
2568 * @param $keyGroup Main group for the key
2569 * @param $subGroup Sub group for the key
2570 * @param $key Key to unset
2571 * @param $element Element to check
2572 * @param $value Value to add/append
2575 protected final function appendStringToGenericArrayElement ($keyGroup, $subGroup, $key, $element, $value, $appendGlue = '') {
2577 //* 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);
2579 // Is it already there?
2580 if ($this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element)) {
2582 $this->genericArray[$keyGroup][$subGroup][$key][$element] .= $appendGlue . (string) $value;
2585 $this->genericArray[$keyGroup][$subGroup][$key][$element] = (string) $value;
2590 * Initializes given generic array group
2592 * @param $keyGroup Main group for the key
2593 * @param $subGroup Sub group for the key
2594 * @param $key Key to use
2595 * @param $forceInit Optionally force initialization
2598 protected final function initGenericArrayGroup ($keyGroup, $subGroup, $forceInit = FALSE) {
2600 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',forceInit=' . intval($forceInit));
2602 // Is it already set?
2603 if (($forceInit === FALSE) && ($this->isGenericArrayGroupSet($keyGroup, $subGroup))) {
2604 // Already initialized
2605 trigger_error(__METHOD__ . ':keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' already initialized.');
2610 $this->genericArray[$keyGroup][$subGroup] = array();
2614 * Initializes given generic array key
2616 * @param $keyGroup Main group for the key
2617 * @param $subGroup Sub group for the key
2618 * @param $key Key to use
2619 * @param $forceInit Optionally force initialization
2622 protected final function initGenericArrayKey ($keyGroup, $subGroup, $key, $forceInit = FALSE) {
2624 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',forceInit=' . intval($forceInit));
2626 // Is it already set?
2627 if (($forceInit === FALSE) && ($this->isGenericArrayKeySet($keyGroup, $subGroup, $key))) {
2628 // Already initialized
2629 trigger_error(__METHOD__ . ':keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' already initialized.');
2634 $this->genericArray[$keyGroup][$subGroup][$key] = array();
2638 * Initializes given generic array element
2640 * @param $keyGroup Main group for the key
2641 * @param $subGroup Sub group for the key
2642 * @param $key Key to use
2643 * @param $element Element to use
2644 * @param $forceInit Optionally force initialization
2647 protected final function initGenericArrayElement ($keyGroup, $subGroup, $key, $element, $forceInit = FALSE) {
2649 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element . ',forceInit=' . intval($forceInit));
2651 // Is it already set?
2652 if (($forceInit === FALSE) && ($this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element))) {
2653 // Already initialized
2654 trigger_error(__METHOD__ . ':keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element . ' already initialized.');
2659 $this->genericArray[$keyGroup][$subGroup][$key][$element] = array();
2663 * Pushes an element to a generic key
2665 * @param $keyGroup Main group for the key
2666 * @param $subGroup Sub group for the key
2667 * @param $key Key to use
2668 * @param $value Value to add/append
2669 * @return $count Number of array elements
2671 protected final function pushValueToGenericArrayKey ($keyGroup, $subGroup, $key, $value) {
2673 //* NOISY-DEBUG: */ if (!is_object($value)) $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',value[' . gettype($value) . ']=' . print_r($value, TRUE));
2676 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
2678 $this->initGenericArrayKey($keyGroup, $subGroup, $key);
2682 $count = array_push($this->genericArray[$keyGroup][$subGroup][$key], $value);
2685 //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], TRUE));
2686 //* DEBUG: */ print(__METHOD__ . ': count=' . $count . PHP_EOL);
2691 * Pushes an element to a generic array element
2693 * @param $keyGroup Main group for the key
2694 * @param $subGroup Sub group for the key
2695 * @param $key Key to use
2696 * @param $element Element to check
2697 * @param $value Value to add/append
2698 * @return $count Number of array elements
2700 protected final function pushValueToGenericArrayElement ($keyGroup, $subGroup, $key, $element, $value) {
2702 //* 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));
2705 if (!$this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element)) {
2707 $this->initGenericArrayElement($keyGroup, $subGroup, $key, $element);
2711 $count = array_push($this->genericArray[$keyGroup][$subGroup][$key][$element], $value);
2714 //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], TRUE));
2715 //* DEBUG: */ print(__METHOD__ . ': count=' . $count . PHP_EOL);
2720 * Pops an element from a generic group
2722 * @param $keyGroup Main group for the key
2723 * @param $subGroup Sub group for the key
2724 * @param $key Key to unset
2725 * @return $value Last "popped" value
2727 protected final function popGenericArrayElement ($keyGroup, $subGroup, $key) {
2729 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
2732 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
2734 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' not found.');
2739 $value = array_pop($this->genericArray[$keyGroup][$subGroup][$key]);
2742 //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], TRUE));
2743 //* DEBUG: */ print(__METHOD__ . ': value[' . gettype($value) . ']=' . print_r($value, TRUE) . PHP_EOL);
2748 * Shifts an element from a generic group
2750 * @param $keyGroup Main group for the key
2751 * @param $subGroup Sub group for the key
2752 * @param $key Key to unset
2753 * @return $value Last "popped" value
2755 protected final function shiftGenericArrayElement ($keyGroup, $subGroup, $key) {
2757 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
2760 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
2762 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' not found.');
2767 $value = array_shift($this->genericArray[$keyGroup][$subGroup][$key]);
2770 //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], TRUE));
2771 //* DEBUG: */ print(__METHOD__ . ': value[' . gettype($value) . ']=' . print_r($value, TRUE) . PHP_EOL);
2776 * Count generic array group
2778 * @param $keyGroup Main group for the key
2779 * @return $count Count of given group
2781 protected final function countGenericArray ($keyGroup) {
2783 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup);
2786 if (!isset($this->genericArray[$keyGroup])) {
2788 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ' not found.');
2793 $count = count($this->genericArray[$keyGroup]);
2796 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',count=' . $count);
2803 * Count generic array sub group
2805 * @param $keyGroup Main group for the key
2806 * @param $subGroup Sub group for the key
2807 * @return $count Count of given group
2809 protected final function countGenericArrayGroup ($keyGroup, $subGroup) {
2811 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup);
2814 if (!$this->isGenericArrayGroupSet($keyGroup, $subGroup)) {
2816 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' not found.');
2821 $count = count($this->genericArray[$keyGroup][$subGroup]);
2824 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',count=' . $count);
2831 * Count generic array elements
2833 * @param $keyGroup Main group for the key
2834 * @param $subGroup Sub group for the key
2835 * @para $key Key to count
2836 * @return $count Count of given key
2838 protected final function countGenericArrayElements ($keyGroup, $subGroup, $key) {
2840 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
2843 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
2845 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' not found.');
2847 } elseif (!$this->isValidGenericArrayGroup($keyGroup, $subGroup)) {
2849 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' is not an array.');
2854 $count = count($this->genericArray[$keyGroup][$subGroup][$key]);
2857 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',count=' . $count);
2864 * Getter for whole generic group array
2866 * @param $keyGroup Key group to get
2867 * @return $array Whole generic array group
2869 protected final function getGenericArray ($keyGroup) {
2871 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup);
2874 if (!isset($this->genericArray[$keyGroup])) {
2876 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ' does not exist.');
2881 return $this->genericArray[$keyGroup];
2885 * Setter for generic array key
2887 * @param $keyGroup Key group to get
2888 * @param $subGroup Sub group for the key
2889 * @param $key Key to unset
2890 * @param $value Mixed value from generic array element
2893 protected final function setGenericArrayKey ($keyGroup, $subGroup, $key, $value) {
2895 //* NOISY-DEBUG: */ if (!is_object($value)) $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',value[' . gettype($value) . ']=' . print_r($value, TRUE));
2898 $this->genericArray[$keyGroup][$subGroup][$key] = $value;
2902 * Getter for generic array key
2904 * @param $keyGroup Key group to get
2905 * @param $subGroup Sub group for the key
2906 * @param $key Key to unset
2907 * @return $value Mixed value from generic array element
2909 protected final function getGenericArrayKey ($keyGroup, $subGroup, $key) {
2911 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
2914 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
2916 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' does not exist.');
2921 return $this->genericArray[$keyGroup][$subGroup][$key];
2925 * Sets a value in given generic array key/element
2927 * @param $keyGroup Main group for the key
2928 * @param $subGroup Sub group for the key
2929 * @param $key Key to set
2930 * @param $element Element to set
2931 * @param $value Value to set
2934 protected final function setGenericArrayElement ($keyGroup, $subGroup, $key, $element, $value) {
2936 //* 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));
2939 $this->genericArray[$keyGroup][$subGroup][$key][$element] = $value;
2943 * Getter for generic array element
2945 * @param $keyGroup Key group to get
2946 * @param $subGroup Sub group for the key
2947 * @param $key Key to look for
2948 * @param $element Element to look for
2949 * @return $value Mixed value from generic array element
2951 protected final function getGenericArrayElement ($keyGroup, $subGroup, $key, $element) {
2953 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element);
2956 if (!$this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element)) {
2958 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element . ' does not exist.');
2963 return $this->genericArray[$keyGroup][$subGroup][$key][$element];
2967 * Checks if a given sub group is valid (array)
2969 * @param $keyGroup Key group to get
2970 * @param $subGroup Sub group for the key
2971 * @return $isValid Whether given sub group is valid
2973 protected final function isValidGenericArrayGroup ($keyGroup, $subGroup) {
2975 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup);
2978 $isValid = (($this->isGenericArrayGroupSet($keyGroup, $subGroup)) && (is_array($this->getGenericSubArray($keyGroup, $subGroup))));
2985 * Checks if a given key is valid (array)
2987 * @param $keyGroup Key group to get
2988 * @param $subGroup Sub group for the key
2989 * @param $key Key to check
2990 * @return $isValid Whether given sub group is valid
2992 protected final function isValidGenericArrayKey ($keyGroup, $subGroup, $key) {
2994 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
2997 $isValid = (($this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) && (is_array($this->getGenericArrayKey($keyGroup, $subGroup, $key))));
3004 * Initializes the web output instance
3008 protected function initWebOutputInstance () {
3009 // Get application instance
3010 $applicationInstance = Registry::getRegistry()->getInstance('app');
3012 // Is this a response instance?
3013 if ($this instanceof Responseable) {
3014 // Then set it in application instance
3015 $applicationInstance->setResponseInstance($this);
3018 // Init web output instance
3019 $outputInstance = ObjectFactory::createObjectByConfiguredName('output_class', array($applicationInstance));
3022 $this->setWebOutputInstance($outputInstance);
3026 * Translates boolean TRUE to 'Y' and FALSE to 'N'
3028 * @param $boolean Boolean value
3029 * @return $translated Translated boolean value
3031 public static final function translateBooleanToYesNo ($boolean) {
3032 // Make sure it is really boolean
3033 assert(is_bool($boolean));
3036 $translated = ($boolean === TRUE) ? 'Y' : 'N';
3038 // ... and return it