3 namespace Org\Mxchange\CoreFramework\Object;
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
7 use Org\Mxchange\CoreFramework\Criteria\Criteria;
8 use Org\Mxchange\CoreFramework\EntryPoint\ApplicationEntryPoint;
9 use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory;
10 use Org\Mxchange\CoreFramework\Filesystem\PathWriteProtectedException;
11 use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
12 use Org\Mxchange\CoreFramework\Generic\NullPointerException;
13 use Org\Mxchange\CoreFramework\Generic\UnsupportedOperationException;
14 use Org\Mxchange\CoreFramework\Helper\Application\ApplicationHelper;
15 use Org\Mxchange\CoreFramework\Loader\ClassLoader;
16 use Org\Mxchange\CoreFramework\Manager\ManageableApplication;
17 use Org\Mxchange\CoreFramework\Middleware\Debug\DebugMiddleware;
18 use Org\Mxchange\CoreFramework\Registry\GenericRegistry;
19 use Org\Mxchange\CoreFramework\Result\Database\CachedDatabaseResult;
20 use Org\Mxchange\CoreFramework\State\Stateable;
21 use Org\Mxchange\CoreFramework\Stream\Output\OutputStreamer;
22 use Org\Mxchange\CoreFramework\Utils\String\StringUtils;
26 use \InvalidArgumentException;
31 * The simulator system class is the super class of all other classes. This
32 * class handles saving of games etc.
34 * @author Roland Haeder <webmaster@shipsimu.org>
36 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2020 Core Developer Team
37 * @license GNU GPL 3.0 or any newer version
38 * @link http://www.shipsimu.org
40 * This program is free software: you can redistribute it and/or modify
41 * it under the terms of the GNU General Public License as published by
42 * the Free Software Foundation, either version 3 of the License, or
43 * (at your option) any later version.
45 * This program is distributed in the hope that it will be useful,
46 * but WITHOUT ANY WARRANTY; without even the implied warranty of
47 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
48 * GNU General Public License for more details.
50 * You should have received a copy of the GNU General Public License
51 * along with this program. If not, see <http://www.gnu.org/licenses/>.
53 abstract class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
55 * Length of output from hash()
57 private static $hashLength = NULL;
60 * Self-referencing instance
62 private static $selfInstance = NULL;
67 private $realClass = __CLASS__;
72 private $callbackInstance = NULL;
77 private $genericArray = [];
79 /***********************
80 * Exception codes.... *
81 ***********************/
83 // @todo Try to clean these constants up
84 const EXCEPTION_IS_NULL_POINTER = 0x001;
85 const EXCEPTION_IS_NO_OBJECT = 0x002;
86 const EXCEPTION_IS_NO_ARRAY = 0x003;
87 const EXCEPTION_MISSING_METHOD = 0x004;
88 const EXCEPTION_CLASSES_NOT_MATCHING = 0x005;
89 const EXCEPTION_INDEX_OUT_OF_BOUNDS = 0x006;
90 const EXCEPTION_DIMENSION_ARRAY_INVALID = 0x007;
91 const EXCEPTION_ITEM_NOT_TRADEABLE = 0x008;
92 const EXCEPTION_ITEM_NOT_IN_PRICE_LIST = 0x009;
93 const EXCEPTION_GENDER_IS_WRONG = 0x00a;
94 const EXCEPTION_BIRTH_DATE_IS_INVALID = 0x00b;
95 const EXCEPTION_EMPTY_STRUCTURES_ARRAY = 0x00c;
96 const EXCEPTION_HAS_ALREADY_PERSONELL_LIST = 0x00d;
97 const EXCEPTION_NOT_ENOUGTH_UNEMPLOYEES = 0x00e;
98 const EXCEPTION_TOTAL_PRICE_NOT_CALCULATED = 0x00f;
99 const EXCEPTION_HARBOR_HAS_NO_SHIPYARDS = 0x010;
100 const EXCEPTION_CONTRACT_PARTNER_INVALID = 0x011;
101 const EXCEPTION_CONTRACT_PARTNER_MISMATCH = 0x012;
102 const EXCEPTION_CONTRACT_ALREADY_SIGNED = 0x013;
103 const EXCEPTION_UNEXPECTED_EMPTY_STRING = 0x014;
104 const EXCEPTION_PATH_NOT_FOUND = 0x015;
105 const EXCEPTION_INVALID_PATH_NAME = 0x016;
106 const EXCEPTION_READ_PROTECED_PATH = 0x017;
107 const EXCEPTION_WRITE_PROTECED_PATH = 0x018;
108 const EXCEPTION_DIR_POINTER_INVALID = 0x019;
109 const EXCEPTION_FILE_POINTER_INVALID = 0x01a;
110 const EXCEPTION_INVALID_RESOURCE = 0x01b;
111 const EXCEPTION_UNEXPECTED_OBJECT = 0x01c;
112 const EXCEPTION_LIMIT_ELEMENT_IS_UNSUPPORTED = 0x01d;
113 const EXCEPTION_GETTER_IS_MISSING = 0x01e;
114 const EXCEPTION_ARRAY_EXPECTED = 0x01f;
115 const EXCEPTION_ARRAY_HAS_INVALID_COUNT = 0x020;
116 const EXCEPTION_ID_IS_INVALID_FORMAT = 0x021;
117 const EXCEPTION_MD5_CHECKSUMS_MISMATCH = 0x022;
118 const EXCEPTION_UNEXPECTED_STRING_SIZE = 0x023;
119 const EXCEPTION_SIMULATOR_ID_INVALID = 0x024;
120 const EXCEPTION_MISMATCHING_COMPRESSORS = 0x025;
121 const EXCEPTION_CONTAINER_ITEM_IS_NULL = 0x026;
122 const EXCEPTION_ITEM_IS_NO_ARRAY = 0x027;
123 const EXCEPTION_CONTAINER_MAYBE_DAMAGED = 0x028;
124 const EXCEPTION_INVALID_STRING = 0x029;
125 const EXCEPTION_VARIABLE_NOT_SET = 0x02a;
126 const EXCEPTION_ATTRIBUTES_ARE_MISSING = 0x02b;
127 const EXCEPTION_ARRAY_ELEMENTS_MISSING = 0x02c;
128 const EXCEPTION_TEMPLATE_ENGINE_UNSUPPORTED = 0x02d;
129 const EXCEPTION_UNSPPORTED_OPERATION = 0x02e;
130 const EXCEPTION_FACTORY_REQUIRE_PARAMETER = 0x02f;
131 const EXCEPTION_MISSING_ELEMENT = 0x030;
132 const EXCEPTION_HEADERS_ALREADY_SENT = 0x031;
133 const EXCEPTION_DEFAULT_CONTROLLER_GONE = 0x032;
134 const EXCEPTION_CLASS_NOT_FOUND = 0x033;
135 const EXCEPTION_REQUIRED_INTERFACE_MISSING = 0x034;
136 const EXCEPTION_FATAL_ERROR = 0x035;
137 const EXCEPTION_FILE_NOT_FOUND = 0x036;
138 const EXCEPTION_ASSERTION_FAILED = 0x037;
139 const EXCEPTION_FILE_NOT_REACHABLE = 0x038;
140 const EXCEPTION_FILE_CANNOT_BE_READ = 0x039;
141 const EXCEPTION_FILE_CANNOT_BE_WRITTEN = 0x03a;
142 const EXCEPTION_PATH_CANNOT_BE_WRITTEN = 0x03b;
143 const EXCEPTION_DATABASE_UPDATED_NOT_ALLOWED = 0x03c;
144 const EXCEPTION_FILTER_CHAIN_INTERCEPTED = 0x03d;
145 const EXCEPTION_INVALID_SOCKET = 0x03e;
146 const EXCEPTION_SELF_INSTANCE = 0x03f;
149 * Startup time in miliseconds
151 private static $startupTime = 0;
154 * Protected super constructor
156 * @param $className Name of the class
159 protected function __construct (string $className) {
161 $this->setRealClass($className);
163 // Is the startup time set? (0 cannot be true anymore)
164 if (self::$startupTime == 0) {
166 self::$startupTime = microtime(true);
171 * Destructor for all classes. You should not call this method on your own.
175 public function __destruct () {
176 // Is this object already destroyed?
177 if ($this->__toString() != 'DestructedObject') {
178 // Destroy all informations about this class but keep some text about it alive
179 $this->setRealClass('DestructedObject');
180 } elseif ((defined('DEBUG_DESTRUCTOR')) && (is_object($this->getDebugInstance()))) {
181 // Already destructed object
182 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('The object <span class="object_name">%s</span> is already destroyed.',
186 // Do not call this twice
187 trigger_error(__METHOD__ . ': Called twice.');
193 * The __call() method where all non-implemented methods end up
195 * @param $methodName Name of the missing method
196 * @args $args Arguments passed to the method
199 public final function __call (string $methodName, array $args = NULL) {
201 self::$selfInstance = $this;
203 // Call static method
204 self::__callStatic($methodName, $args);
206 // Clear self-instance
207 self::$selfInstance = NULL;
211 * The __callStatic() method where all non-implemented static methods end up
213 * @param $methodName Name of the missing method
214 * @param $args Arguments passed to the method
216 * @throws InvalidArgumentException If self::$selfInstance is not a framework's own object
218 public static final function __callStatic (string $methodName, array $args = NULL) {
219 // Init argument string and class name
220 //* PRINT-DEBUG: */ printf('[%s:%d]: methodName=%s,args[]=%s - CALLED!' . PHP_EOL, __METHOD__, __LINE__, $methodName, gettype($args));
222 $className = 'unknown';
224 // Is self-instance set?
225 if (self::$selfInstance instanceof FrameworkInterface) {
226 // Framework's own instance
227 $className = self::$selfInstance->__toString();
228 } elseif (!is_null(self::$selfInstance)) {
230 throw new InvalidArgumentException(sprintf('self::instance[%s] is not expected.', gettype(self::$selfInstance)), self::EXCEPTION_SELF_INSTANCE);
233 // Is it NULL, empty or an array?
234 if (is_null($args)) {
236 $argsString = 'NULL';
237 } elseif (is_array($args)) {
241 // Some arguments are there
242 foreach ($args as $arg) {
243 // Add data about the argument
244 $argsString .= gettype($arg) . ':';
247 // Found a NULL argument
248 $argsString .= 'NULL';
249 } elseif (is_string($arg)) {
250 // Add length for strings
251 $argsString .= strlen($arg);
252 } elseif ((is_int($arg)) || (is_float($arg))) {
255 } elseif (is_array($arg)) {
256 // .. or size if array
257 $argsString .= count($arg);
258 } elseif (is_object($arg)) {
260 $reflection = new ReflectionClass($arg);
262 // Is an other object, maybe no __toString() available
263 $argsString .= $reflection->getName();
264 } elseif ($arg === true) {
265 // ... is boolean 'true'
266 $argsString .= 'true';
267 } elseif ($arg === false) {
268 // ... is boolean 'false'
269 $argsString .= 'false';
272 // Comma for next one
277 if (substr($argsString, -2, 1) == ',') {
279 $argsString = substr($argsString, 0, -2);
286 // Output stub message
287 // @TODO __CLASS__ does always return BaseFrameworkSystem but not the extending (=child) class
288 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s::%s]: Stub! Args: %s',
299 * Getter for $realClass
301 * @return $realClass The name of the real class (not BaseFrameworkSystem)
303 public function __toString () {
304 return $this->realClass;
308 * Magic method to catch setting of missing but set class fields/attributes
310 * @param $name Name of the field/attribute
311 * @param $value Value to store
314 public final function __set (string $name, $value) {
315 $this->debugBackTrace(sprintf('Tried to set a missing field. name=%s, value[%s]=%s',
318 print_r($value, true)
323 * Magic method to catch getting of missing fields/attributes
325 * @param $name Name of the field/attribute
328 public final function __get (string $name) {
329 $this->debugBackTrace(sprintf('Tried to get a missing field. name=%s',
335 * Magic method to catch unsetting of missing fields/attributes
337 * @param $name Name of the field/attribute
340 public final function __unset (string $name) {
341 $this->debugBackTrace(sprintf('Tried to unset a missing field. name=%s',
347 * Magic method to catch object serialization
349 * @return $unsupported Unsupported method
350 * @throws UnsupportedOperationException Objects of this framework cannot be serialized
352 public final function __sleep () {
353 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
357 * Magic method to catch object deserialization
359 * @return $unsupported Unsupported method
360 * @throws UnsupportedOperationException Objects of this framework cannot be serialized
362 public final function __wakeup () {
363 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
367 * Magic method to catch calls when an object instance is called
369 * @return $unsupported Unsupported method
370 * @throws UnsupportedOperationException Objects of this framework cannot be serialized
372 public final function __invoke () {
373 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
377 * Setter for the real class name
379 * @param $realClass Class name (string)
382 public final function setRealClass (string $realClass) {
384 $this->realClass = $realClass;
388 * Setter for debug instance
390 * @param $debugInstance The instance for debug output class
393 public final function setDebugInstance (DebugMiddleware $debugInstance) {
394 GenericRegistry::getRegistry()->addInstance('debug', $debugInstance);
398 * Getter for debug instance
400 * @return $debugInstance Instance to class DebugConsoleOutput or DebugWebOutput
402 public final function getDebugInstance () {
403 // Get debug instance
404 $debugInstance = GenericRegistry::getRegistry()->getInstance('debug');
407 return $debugInstance;
411 * Setter for web output instance
413 * @param $webInstance The instance for web output class
416 public final function setWebOutputInstance (OutputStreamer $webInstance) {
417 GenericRegistry::getRegistry()->addInstance('web_output', $webInstance);
421 * Getter for web output instance
423 * @return $webOutputInstance - Instance to class WebOutput
425 public final function getWebOutputInstance () {
426 $webOutputInstance = GenericRegistry::getRegistry()->getInstance('web_output');
427 return $webOutputInstance;
431 * Setter for call-back instance
433 * @param $callbackInstance An instance of a FrameworkInterface class
436 public final function setCallbackInstance (FrameworkInterface $callbackInstance) {
437 $this->callbackInstance = $callbackInstance;
441 * Getter for call-back instance
443 * @return $callbackInstance An instance of a FrameworkInterface class
445 protected final function getCallbackInstance () {
446 return $this->callbackInstance;
450 * Checks whether an object equals this object. You should overwrite this
451 * method to implement own equality checks
453 * @param $objectInstance An instance of a FrameworkInterface object
454 * @return $equals Whether both objects equals
456 public function equals (FrameworkInterface $objectInstance) {
459 $this->__toString() == $objectInstance->__toString()
461 $this->hashCode() == $objectInstance->hashCode()
469 * Generates a generic hash code of this class. You should really overwrite
470 * this method with your own hash code generator code. But keep KISS in mind.
472 * @return $hashCode A generic hash code respresenting this whole class
474 public function hashCode () {
476 return crc32($this->__toString());
480 * Appends a trailing slash to a string
482 * @param $str A string (maybe) without trailing slash
483 * @return $str A string with an auto-appended trailing slash
485 public final function addMissingTrailingSlash (string $str) {
486 // Is there a trailing slash?
487 if (substr($str, -1, 1) != '/') {
491 // Return string with trailing slash
496 * Debugs this instance by putting out it's full content
498 * @param $message Optional message to show in debug output
501 public final function debugInstance (string $message = '') {
502 // Restore the error handler to avoid trouble with missing array elements or undeclared variables
503 restore_error_handler();
509 if (!empty($message)) {
511 $content = sprintf('<div class="debug_message">
513 </div>' . PHP_EOL, $message);
516 // Generate the output
517 $content .= sprintf('<pre>%s</pre>',
526 ApplicationEntryPoint::exitApplication(sprintf('<div class="debug_header">
529 <div class="debug_content">
533 <div class="debug_include_list">
538 ClassLoader::getSelfInstance()->getPrintableIncludeList()
543 * Replaces control characters with printable output
545 * @param $str String with control characters
546 * @return $str Replaced string
548 protected function replaceControlCharacters (string $str) {
551 chr(13), '[r]', str_replace(
552 chr(10), '[n]', str_replace(
562 * Output a partial stub message for the caller method
564 * @param $message An optional message to display
567 protected function partialStub (string $message = '') {
569 $stubMessage = 'Partial stub!';
571 // Is an extra message given?
572 if (!empty($message)) {
573 // Then add it as well
574 $stubMessage .= ' Message: ' . $message;
577 // Debug instance is there?
578 if (!is_null($this->getDebugInstance())) {
579 // Output stub message
580 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput($stubMessage);
583 trigger_error($stubMessage);
589 * Outputs a debug backtrace and stops further script execution
591 * @param $message An optional message to output
592 * @param $doExit Whether exit the program (true is default)
595 public function debugBackTrace (string $message = '', bool $doExit = true) {
596 // Sorry, there is no other way getting this nice backtrace
597 if (!empty($message)) {
599 printf('Message: %s<br />' . PHP_EOL, $message);
603 debug_print_backtrace();
607 if ($doExit === true) {
613 * Creates an instance of a debugger instance
615 * @param $className Name of the class (currently unsupported)
616 * @param $lineNumber Line number where the call was made
617 * @return $debugInstance An instance of a debugger class
618 * @deprecated Not fully, as the new Logger facilities are not finished yet.
620 public final static function createDebugInstance (string $className, int $lineNumber = NULL) {
621 // Is the instance set?
622 if (!GenericRegistry::getRegistry()->instanceExists('debug')) {
623 // Init debug instance
624 $debugInstance = NULL;
628 // Get a debugger instance
629 $debugInstance = DebugMiddleware::createDebugMiddleware(FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('debug_' . FrameworkBootstrap::getRequestTypeFromSystem() . '_class'), $className);
630 } catch (NullPointerException $e) {
631 // Didn't work, no instance there
632 exit(sprintf('[%s:%d]: Cannot create debugInstance! Exception=%s,message=%s,className=%s,lineNumber=%d' . PHP_EOL, __METHOD__, __LINE__, $e->__toString(), $e->getMessage(), $className, $lineNumber));
635 // Empty string should be ignored and used for testing the middleware
636 DebugMiddleware::getSelfInstance()->output('');
638 // Set it in registry
639 GenericRegistry::getRegistry()->addInstance('debug', $debugInstance);
641 // Get instance from registry
642 $debugInstance = GenericRegistry::getRegistry()->getDebugInstance();
646 return $debugInstance;
650 * Simple output of a message with line-break
652 * @param $message Message to output
655 public function outputLine (string $message) {
657 print($message . PHP_EOL);
661 * Outputs a debug message whether to debug instance (should be set!) or
662 * dies with or ptints the message. Do NEVER EVER rewrite the exit() call to
663 * ApplicationEntryPoint::app_exit(), this would cause an endless loop.
665 * @param $message Message we shall send out...
666 * @param $doPrint Whether print or die here (default: print)
667 * @paran $stripTags Whether to strip tags (default: false)
670 public function debugOutput (string $message, bool $doPrint = true, bool $stripTags = false) {
671 // Set debug instance to NULL
672 $debugInstance = NULL;
675 $backtrace = debug_backtrace(!DEBUG_BACKTRACE_PROVIDE_OBJECT);
677 // Is function partialStub/__callStatic ?
678 if (in_array($backtrace[1]['function'], array('partialStub', '__call', '__callStatic'))) {
679 // Prepend class::function:line from 3rd element
680 $message = sprintf('[%s::%s:%d]: %s',
681 $backtrace[2]['class'],
682 $backtrace[2]['function'],
683 (isset($backtrace[2]['line']) ? $backtrace[2]['line'] : '0'),
687 // Prepend class::function:line from 2nd element
688 $message = sprintf('[%s::%s:%d]: %s',
689 $backtrace[1]['class'],
690 $backtrace[1]['function'],
691 (isset($backtrace[1]['line']) ? $backtrace[1]['line'] : '0'),
698 // Get debug instance
699 $debugInstance = $this->getDebugInstance();
700 } catch (NullPointerException $e) {
701 // The debug instance is not set (yet)
704 // Is the debug instance there?
705 if (is_object($debugInstance)) {
706 // Use debug output handler
707 $debugInstance->output($message, $stripTags);
709 if ($doPrint === false) {
710 // Die here if not printed
714 // Are debug times enabled?
715 if (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('debug_' . FrameworkBootstrap::getRequestTypeFromSystem() . '_output_timings') == 'Y') {
717 $message = $this->getPrintableExecutionTime() . $message;
721 if ($doPrint === true) {
723 $this->outputLine($message);
732 * Marks up the code by adding e.g. line numbers
734 * @param $phpCode Unmarked PHP code
735 * @return $markedCode Marked PHP code
737 public function markupCode (string $phpCode) {
742 $errorArray = error_get_last();
744 // Init the code with error message
745 if (is_array($errorArray)) {
747 $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>',
748 basename($errorArray['file']),
750 $errorArray['message'],
755 // Add line number to the code
756 foreach (explode(chr(10), $phpCode) as $lineNo => $code) {
758 $markedCode .= sprintf('<span id="code_line">%s</span>: %s' . PHP_EOL,
760 htmlentities($code, ENT_QUOTES)
769 * "Getter" for databse entry
771 * @return $entry An array with database entries
772 * @throws NullPointerException If the database result is not found
773 * @throws InvalidDatabaseResultException If the database result is invalid
774 * @todo Monolithic method, should be moved to proper classes
776 protected final function getDatabaseEntry () {
777 // Is there an instance?
778 if (!$this->getResultInstance() instanceof SearchableResult) {
779 // Throw an exception here
780 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
784 $this->getResultInstance()->rewind();
786 // Do we have an entry?
787 if ($this->getResultInstance()->valid() === false) {
788 // @TODO Move the constant to e.g. BaseDatabaseResult when there is a non-cached database result available
789 throw new InvalidDatabaseResultException(array($this, $this->getResultInstance()), CachedDatabaseResult::EXCEPTION_INVALID_DATABASE_RESULT);
793 $this->getResultInstance()->next();
796 $entry = $this->getResultInstance()->current();
803 * Getter for field name
805 * @param $fieldName Field name which we shall get
806 * @return $fieldValue Field value from the user
807 * @throws NullPointerException If the result instance is null
809 public final function getField (string $fieldName) {
810 // Default field value
813 // Get result instance
814 $resultInstance = $this->getResultInstance();
816 // Is this instance null?
817 if (is_null($resultInstance)) {
818 // Then the user instance is no longer valid (expired cookies?)
819 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
823 $fieldArray = $resultInstance->current();
824 //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput($fieldName.':<pre>'.print_r($fieldArray, true).'</pre>');
826 // Convert dashes to underscore
827 $fieldName2 = StringUtils::convertDashesToUnderscores($fieldName);
829 // Does the field exist?
830 if ($this->isFieldSet($fieldName)) {
832 $fieldValue = $fieldArray[$fieldName2];
833 } elseif (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('developer_mode_enabled')) {
834 // Missing field entry, may require debugging
835 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FRAMEWORK-SYSTEM: fieldArray<pre>=' . print_r($fieldArray, true) . '</pre>,fieldName=' . $fieldName . ' not found!');
837 // Missing field entry, may require debugging
838 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FRAMEWORK-SYSTEM: fieldName=' . $fieldName . ' not found!');
846 * Checks if given field is set
848 * @param $fieldName Field name to check
849 * @return $isSet Whether the given field name is set
850 * @throws NullPointerException If the result instance is null
852 public function isFieldSet (string $fieldName) {
853 // Get result instance
854 $resultInstance = $this->getResultInstance();
856 // Is this instance null?
857 if (is_null($resultInstance)) {
858 // Then the user instance is no longer valid (expired cookies?)
859 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
863 $fieldArray = $resultInstance->current();
864 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('[' . $this->__toString() . ':' . __LINE__ . '] fieldName=' . $fieldName . ',fieldArray=<pre>'.print_r($fieldArray, true).'</pre>');
866 // Convert dashes to underscore
867 $fieldName = StringUtils::convertDashesToUnderscores($fieldName);
870 $isSet = isset($fieldArray[$fieldName]);
877 * Outputs a deprecation warning to the developer.
879 * @param $message The message we shall output to the developer
881 * @todo Write a logging mechanism for productive mode
883 public function deprecationWarning (string $message) {
884 // Is developer mode active?
885 if (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('developer_mode_enabled')) {
886 // Debug instance is there?
887 if (!is_null($this->getDebugInstance())) {
888 // Output stub message
889 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput($message);
892 trigger_error($message . "<br />\n");
896 // @TODO Finish this part!
897 $this->partialStub('Developer mode inactive. Message:' . $message);
902 * Checks whether the given PHP extension is loaded
904 * @param $phpExtension The PHP extension we shall check
905 * @return $isLoaded Whether the PHP extension is loaded
907 public final function isPhpExtensionLoaded (string $phpExtension) {
909 $isLoaded = in_array($phpExtension, get_loaded_extensions());
916 * "Getter" as a time() replacement but with milliseconds. You should use this
917 * method instead of the encapsulated getimeofday() function.
919 * @return $milliTime Timestamp with milliseconds
921 public function getMilliTime () {
922 // Get the time of day as float
923 $milliTime = gettimeofday(true);
930 * Idles (sleeps) for given milliseconds
932 * @return $hasSlept Whether it goes fine
934 public function idle (int $milliSeconds) {
935 // Sleep is fine by default
938 // Idle so long with found function
939 if (function_exists('time_sleep_until')) {
940 // Get current time and add idle time
941 $sleepUntil = $this->getMilliTime() + abs($milliSeconds) / 1000;
943 // New PHP 5.1.0 function found, ignore errors
944 $hasSlept = @time_sleep_until($sleepUntil);
947 * My Sun station doesn't have that function even with latest PHP
950 usleep($milliSeconds * 1000);
958 * Checks whether the given encoded data was encoded with Base64
960 * @param $encodedData Encoded data we shall check
961 * @return $isBase64 Whether the encoded data is Base64
963 protected function isBase64Encoded (string $encodedData) {
965 $isBase64 = (@base64_decode($encodedData, true) !== false);
972 * Gets a cache key from Criteria instance
974 * @param $criteriaInstance An instance of a Criteria class
975 * @param $onlyKeys Only use these keys for a cache key
976 * @return $cacheKey A cache key suitable for lookup/storage purposes
978 protected function getCacheKeyByCriteria (Criteria $criteriaInstance, array $onlyKeys = []) {
980 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FRAMEWORK-SYSTEM: criteriaInstance=' . $criteriaInstance->__toString() . ',onlyKeys()=' . count($onlyKeys) . ' - CALLED!');
981 $cacheKey = sprintf('%s@%s',
983 $criteriaInstance->getCacheKey($onlyKeys)
987 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FRAMEWORK-SYSTEM: cacheKey=' . $cacheKey . ' - EXIT!');
992 * Getter for startup time in miliseconds
994 * @return $startupTime Startup time in miliseconds
996 protected function getStartupTime () {
997 return self::$startupTime;
1001 * "Getter" for a printable currently execution time in nice braces
1003 * @return $executionTime Current execution time in nice braces
1005 protected function getPrintableExecutionTime () {
1006 // Calculate execution time and pack it in nice braces
1007 $executionTime = sprintf('[ %01.5f ] ', (microtime(true) - $this->getStartupTime()));
1010 return $executionTime;
1014 * Hashes a given string with a simple but stronger hash function (no salt)
1015 * and hex-encode it.
1017 * @param $str The string to be hashed
1018 * @return $hash The hash from string $str
1020 public static final function hash (string $str) {
1021 // Hash given string with (better secure) hasher
1022 $hash = bin2hex(mhash(MHASH_SHA256, $str));
1029 * "Getter" for length of hash() output. This will be "cached" to speed up
1032 * @return $length Length of hash() output
1034 public static final function getHashLength () {
1036 if (is_null(self::$hashLength)) {
1037 // No, then hash a string and save its length.
1038 self::$hashLength = strlen(self::hash('abc123'));
1042 return self::$hashLength;
1046 * Determines if an element is set in the generic array
1048 * @param $keyGroup Main group for the key
1049 * @param $subGroup Sub group for the key
1050 * @param $key Key to check
1051 * @param $element Element to check
1052 * @return $isset Whether the given key is set
1054 protected final function isGenericArrayElementSet (string $keyGroup, string $subGroup, $key, $element) {
1056 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element);
1059 $isset = isset($this->genericArray[$keyGroup][$subGroup][$key][$element]);
1065 * Determines if a key is set in the generic array
1067 * @param $keyGroup Main group for the key
1068 * @param $subGroup Sub group for the key
1069 * @param $key Key to check
1070 * @return $isset Whether the given key is set
1072 protected final function isGenericArrayKeySet (string $keyGroup, string $subGroup, $key) {
1074 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1077 $isset = isset($this->genericArray[$keyGroup][$subGroup][$key]);
1085 * Determines if a group is set in the generic array
1087 * @param $keyGroup Main group
1088 * @param $subGroup Sub group
1089 * @return $isset Whether the given group is set
1091 protected final function isGenericArrayGroupSet (string $keyGroup, string $subGroup) {
1093 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup);
1096 $isset = isset($this->genericArray[$keyGroup][$subGroup]);
1103 * Getter for sub key group
1105 * @param $keyGroup Main key group
1106 * @param $subGroup Sub key group
1107 * @return $array An array with all array elements
1109 protected final function getGenericSubArray (string $keyGroup, string $subGroup) {
1111 if (!$this->isGenericArrayGroupSet($keyGroup, $subGroup)) {
1112 // No, then abort here
1113 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' not found.');
1118 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',value=' . print_r($this->genericArray[$keyGroup][$subGroup], true));
1121 return $this->genericArray[$keyGroup][$subGroup];
1125 * Unsets a given key in generic array
1127 * @param $keyGroup Main group for the key
1128 * @param $subGroup Sub group for the key
1129 * @param $key Key to unset
1132 protected final function unsetGenericArrayKey (string $keyGroup, string $subGroup, $key) {
1134 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1137 unset($this->genericArray[$keyGroup][$subGroup][$key]);
1141 * Unsets a given element in generic array
1143 * @param $keyGroup Main group for the key
1144 * @param $subGroup Sub group for the key
1145 * @param $key Key to unset
1146 * @param $element Element to unset
1149 protected final function unsetGenericArrayElement (string $keyGroup, string $subGroup, $key, $element) {
1151 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element);
1154 unset($this->genericArray[$keyGroup][$subGroup][$key][$element]);
1158 * Append a string to a given generic array key
1160 * @param $keyGroup Main group for the key
1161 * @param $subGroup Sub group for the key
1162 * @param $key Key to unset
1163 * @param $value Value to add/append
1166 protected final function appendStringToGenericArrayKey (string $keyGroup, string $subGroup, $key, string $value, $appendGlue = '') {
1168 //* 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);
1170 // Is it already there?
1171 if ($this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
1173 $this->genericArray[$keyGroup][$subGroup][$key] .= $appendGlue . (string) $value;
1176 $this->genericArray[$keyGroup][$subGroup][$key] = (string) $value;
1181 * Append a string to a given generic array element
1183 * @param $keyGroup Main group for the key
1184 * @param $subGroup Sub group for the key
1185 * @param $key Key to unset
1186 * @param $element Element to check
1187 * @param $value Value to add/append
1190 protected final function appendStringToGenericArrayElement (string $keyGroup, string $subGroup, $key, $element, $value, $appendGlue = '') {
1192 //* 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);
1194 // Is it already there?
1195 if ($this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element)) {
1197 $this->genericArray[$keyGroup][$subGroup][$key][$element] .= $appendGlue . (string) $value;
1200 $this->setStringGenericArrayElement($keyGroup, $subGroup, $key, $element, $value);
1205 * Sets a string in a given generic array element
1207 * @param $keyGroup Main group for the key
1208 * @param $subGroup Sub group for the key
1209 * @param $key Key to unset
1210 * @param $element Element to check
1211 * @param $value Value to add/append
1214 protected final function setStringGenericArrayElement (string $keyGroup, string $subGroup, $key, $element, $value, $appendGlue = '') {
1216 //* 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);
1219 $this->genericArray[$keyGroup][$subGroup][$key][$element] = (string) $value;
1223 * Initializes given generic array group
1225 * @param $keyGroup Main group for the key
1226 * @param $subGroup Sub group for the key
1227 * @param $key Key to use
1228 * @param $forceInit Optionally force initialization
1231 protected final function initGenericArrayGroup (string $keyGroup, string $subGroup, bool $forceInit = false) {
1233 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',forceInit=' . intval($forceInit));
1235 // Is it already set?
1236 if (($forceInit === false) && ($this->isGenericArrayGroupSet($keyGroup, $subGroup))) {
1237 // Already initialized
1238 trigger_error(__METHOD__ . ':keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' already initialized.');
1243 $this->genericArray[$keyGroup][$subGroup] = [];
1247 * Initializes given generic array key
1249 * @param $keyGroup Main group for the key
1250 * @param $subGroup Sub group for the key
1251 * @param $key Key to use
1252 * @param $forceInit Optionally force initialization
1255 protected final function initGenericArrayKey (string $keyGroup, string $subGroup, $key, bool $forceInit = false) {
1257 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',forceInit=' . intval($forceInit));
1259 // Is it already set?
1260 if (($forceInit === false) && ($this->isGenericArrayKeySet($keyGroup, $subGroup, $key))) {
1261 // Already initialized
1262 trigger_error(__METHOD__ . ':keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' already initialized.');
1267 $this->genericArray[$keyGroup][$subGroup][$key] = [];
1271 * Initializes given generic array element
1273 * @param $keyGroup Main group for the key
1274 * @param $subGroup Sub group for the key
1275 * @param $key Key to use
1276 * @param $element Element to use
1277 * @param $forceInit Optionally force initialization
1280 protected final function initGenericArrayElement (string $keyGroup, string $subGroup, $key, $element, bool $forceInit = false) {
1282 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element . ',forceInit=' . intval($forceInit));
1284 // Is it already set?
1285 if (($forceInit === false) && ($this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element))) {
1286 // Already initialized
1287 trigger_error(__METHOD__ . ':keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element . ' already initialized.');
1292 $this->genericArray[$keyGroup][$subGroup][$key][$element] = [];
1296 * Pushes an element to a generic key
1298 * @param $keyGroup Main group for the key
1299 * @param $subGroup Sub group for the key
1300 * @param $key Key to use
1301 * @param $value Value to add/append
1302 * @return $count Number of array elements
1304 protected final function pushValueToGenericArrayKey (string $keyGroup, string $subGroup, $key, $value) {
1306 //* NOISY-DEBUG: */ if (!is_object($value)) $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',value[' . gettype($value) . ']=' . print_r($value, true));
1309 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
1311 $this->initGenericArrayKey($keyGroup, $subGroup, $key);
1315 $count = array_push($this->genericArray[$keyGroup][$subGroup][$key], $value);
1318 //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], true));
1319 //* DEBUG: */ print(__METHOD__ . ': count=' . $count . PHP_EOL);
1324 * Pushes an element to a generic array element
1326 * @param $keyGroup Main group for the key
1327 * @param $subGroup Sub group for the key
1328 * @param $key Key to use
1329 * @param $element Element to check
1330 * @param $value Value to add/append
1331 * @return $count Number of array elements
1333 protected final function pushValueToGenericArrayElement (string $keyGroup, string $subGroup, $key, $element, $value) {
1335 //* 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));
1338 if (!$this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element)) {
1340 $this->initGenericArrayElement($keyGroup, $subGroup, $key, $element);
1344 $count = array_push($this->genericArray[$keyGroup][$subGroup][$key][$element], $value);
1347 //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], true));
1348 //* DEBUG: */ print(__METHOD__ . ': count=' . $count . PHP_EOL);
1353 * Pops an element from a generic group
1355 * @param $keyGroup Main group for the key
1356 * @param $subGroup Sub group for the key
1357 * @param $key Key to unset
1358 * @return $value Last "popped" value
1360 protected final function popGenericArrayElement (string $keyGroup, string $subGroup, $key) {
1362 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1365 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
1367 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' not found.');
1372 $value = array_pop($this->genericArray[$keyGroup][$subGroup][$key]);
1375 //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], true));
1376 //* DEBUG: */ print(__METHOD__ . ': value[' . gettype($value) . ']=' . print_r($value, true) . PHP_EOL);
1381 * Shifts an element from a generic group
1383 * @param $keyGroup Main group for the key
1384 * @param $subGroup Sub group for the key
1385 * @param $key Key to unset
1386 * @return $value Last "popped" value
1388 protected final function shiftGenericArrayElement (string $keyGroup, string $subGroup, $key) {
1390 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1393 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
1395 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' not found.');
1400 $value = array_shift($this->genericArray[$keyGroup][$subGroup][$key]);
1403 //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], true));
1404 //* DEBUG: */ print(__METHOD__ . ': value[' . gettype($value) . ']=' . print_r($value, true) . PHP_EOL);
1409 * Count generic array group
1411 * @param $keyGroup Main group for the key
1412 * @return $count Count of given group
1414 protected final function countGenericArray ($keyGroup) {
1416 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup);
1419 if (!isset($this->genericArray[$keyGroup])) {
1421 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ' not found.');
1426 $count = count($this->genericArray[$keyGroup]);
1429 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',count=' . $count);
1436 * Count generic array sub group
1438 * @param $keyGroup Main group for the key
1439 * @param $subGroup Sub group for the key
1440 * @return $count Count of given group
1442 protected final function countGenericArrayGroup (string $keyGroup, string $subGroup) {
1444 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup);
1447 if (!$this->isGenericArrayGroupSet($keyGroup, $subGroup)) {
1449 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' not found.');
1454 $count = count($this->genericArray[$keyGroup][$subGroup]);
1457 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',count=' . $count);
1464 * Count generic array elements
1466 * @param $keyGroup Main group for the key
1467 * @param $subGroup Sub group for the key
1468 * @para $key Key to count
1469 * @return $count Count of given key
1471 protected final function countGenericArrayElements (string $keyGroup, string $subGroup, $key) {
1473 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1476 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
1478 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' not found.');
1480 } elseif (!$this->isValidGenericArrayGroup($keyGroup, $subGroup)) {
1482 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' is not an array.');
1487 $count = count($this->genericArray[$keyGroup][$subGroup][$key]);
1490 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',count=' . $count);
1497 * Getter for whole generic group array
1499 * @param $keyGroup Key group to get
1500 * @return $array Whole generic array group
1502 protected final function getGenericArray ($keyGroup) {
1504 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup);
1507 if (!isset($this->genericArray[$keyGroup])) {
1509 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ' does not exist.');
1514 return $this->genericArray[$keyGroup];
1518 * Setter for generic array key
1520 * @param $keyGroup Key group to get
1521 * @param $subGroup Sub group for the key
1522 * @param $key Key to unset
1523 * @param $value Mixed value from generic array element
1526 protected final function setGenericArrayKey (string $keyGroup, string $subGroup, $key, $value) {
1528 //* NOISY-DEBUG: */ if (!is_object($value)) $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',value[' . gettype($value) . ']=' . print_r($value, true));
1531 $this->genericArray[$keyGroup][$subGroup][$key] = $value;
1535 * Getter for generic array key
1537 * @param $keyGroup Key group to get
1538 * @param $subGroup Sub group for the key
1539 * @param $key Key to unset
1540 * @return $value Mixed value from generic array element
1542 protected final function getGenericArrayKey (string $keyGroup, string $subGroup, $key) {
1544 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1547 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
1549 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' does not exist.');
1554 return $this->genericArray[$keyGroup][$subGroup][$key];
1558 * Sets a value in given generic array key/element
1560 * @param $keyGroup Main group for the key
1561 * @param $subGroup Sub group for the key
1562 * @param $key Key to set
1563 * @param $element Element to set
1564 * @param $value Value to set
1567 protected final function setGenericArrayElement (string $keyGroup, string $subGroup, $key, $element, $value) {
1569 //* 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));
1572 $this->genericArray[$keyGroup][$subGroup][$key][$element] = $value;
1576 * Getter for generic array element
1578 * @param $keyGroup Key group to get
1579 * @param $subGroup Sub group for the key
1580 * @param $key Key to look for
1581 * @param $element Element to look for
1582 * @return $value Mixed value from generic array element
1584 protected final function getGenericArrayElement (string $keyGroup, string $subGroup, $key, $element) {
1586 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element);
1589 if (!$this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element)) {
1591 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element . ' does not exist.');
1596 return $this->genericArray[$keyGroup][$subGroup][$key][$element];
1600 * Checks if a given sub group is valid (array)
1602 * @param $keyGroup Key group to get
1603 * @param $subGroup Sub group for the key
1604 * @return $isValid Whether given sub group is valid
1606 protected final function isValidGenericArrayGroup (string $keyGroup, string $subGroup) {
1608 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup);
1611 $isValid = (($this->isGenericArrayGroupSet($keyGroup, $subGroup)) && (is_array($this->getGenericSubArray($keyGroup, $subGroup))));
1618 * Checks if a given key is valid (array)
1620 * @param $keyGroup Key group to get
1621 * @param $subGroup Sub group for the key
1622 * @param $key Key to check
1623 * @return $isValid Whether given sub group is valid
1625 protected final function isValidGenericArrayKey (string $keyGroup, string $subGroup, $key) {
1627 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1630 $isValid = (($this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) && (is_array($this->getGenericArrayKey($keyGroup, $subGroup, $key))));
1637 * Initializes the web output instance
1641 protected function initWebOutputInstance () {
1642 // Get application instance
1643 $applicationInstance = ApplicationHelper::getSelfInstance();
1645 // Init web output instance
1646 $outputInstance = ObjectFactory::createObjectByConfiguredName('output_class', array($applicationInstance));
1649 $this->setWebOutputInstance($outputInstance);
1653 * Translates boolean true to 'Y' and false to 'N'
1655 * @param $boolean Boolean value
1656 * @return $translated Translated boolean value
1658 public static final function translateBooleanToYesNo (bool $boolean) {
1659 // Make sure it is really boolean
1660 assert(is_bool($boolean));
1663 $translated = ($boolean === true) ? 'Y' : 'N';
1665 // ... and return it
1670 * Creates a full-qualified file name (FQFN) for given file name by adding
1671 * a configured temporary file path to it.
1673 * @param $infoInstance An instance of a SplFileInfo class
1674 * @return $tempInstance An instance of a SplFileInfo class (temporary file)
1675 * @throw PathWriteProtectedException If the path in 'temp_file_path' is write-protected
1676 * @throws FileIoException If the file cannot be written
1678 protected static function createTempPathForFile (SplFileInfo $infoInstance) {
1680 $basePath = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('temp_file_path');
1682 // Is the path writeable?
1683 if (!is_writable($basePath)) {
1684 // Path is write-protected
1685 throw new PathWriteProtectedException($infoInstance, self::EXCEPTION_PATH_CANNOT_BE_WRITTEN);
1689 $tempInstance = new SplFileInfo($basePath . DIRECTORY_SEPARATOR . $infoInstance->getBasename());
1692 if (!FrameworkBootstrap::isReachableFilePath($tempInstance)) {
1694 throw new FileIoException($tempInstance, self::EXCEPTION_FILE_NOT_REACHABLE);
1698 return $tempInstance;
1702 * "Getter" for a printable state name
1704 * @return $stateName Name of the node's state in a printable format
1705 * @todo Move this class away from this monolithic place (not whole class is monolithic)
1707 public final function getPrintableState () {
1708 // Default is 'null'
1709 $stateName = 'null';
1711 // Get the state instance
1712 $stateInstance = $this->getStateInstance();
1714 // Is it an instance of Stateable?
1715 if ($stateInstance instanceof Stateable) {
1716 // Then use that state name
1717 $stateName = $stateInstance->getStateName();