3 namespace Org\Mxchange\CoreFramework\Object;
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
7 use Org\Mxchange\CoreFramework\EntryPoint\ApplicationEntryPoint;
8 use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory;
9 use Org\Mxchange\CoreFramework\Filesystem\FileIoException;
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\Strings\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 - 2021 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 * Self-referencing instance
57 private static $selfInstance = NULL;
62 private static $stubMethods = [
63 'partialStub' => true,
65 '__callStatic' => true,
71 private $realClass = __CLASS__;
76 private $callbackInstance = NULL;
81 private $genericArray = [];
83 /***********************
84 * Exception codes.... *
85 ***********************/
87 // @todo Try to clean these constants up
88 const EXCEPTION_IS_NULL_POINTER = 0x001;
89 const EXCEPTION_IS_NO_OBJECT = 0x002;
90 const EXCEPTION_IS_NO_ARRAY = 0x003;
91 const EXCEPTION_MISSING_METHOD = 0x004;
92 const EXCEPTION_CLASSES_NOT_MATCHING = 0x005;
93 const EXCEPTION_INDEX_OUT_OF_BOUNDS = 0x006;
94 const EXCEPTION_DIMENSION_ARRAY_INVALID = 0x007;
95 const EXCEPTION_ITEM_NOT_TRADEABLE = 0x008;
96 const EXCEPTION_ITEM_NOT_IN_PRICE_LIST = 0x009;
97 const EXCEPTION_GENDER_IS_WRONG = 0x00a;
98 const EXCEPTION_BIRTH_DATE_IS_INVALID = 0x00b;
99 const EXCEPTION_EMPTY_STRUCTURES_ARRAY = 0x00c;
100 const EXCEPTION_HAS_ALREADY_PERSONELL_LIST = 0x00d;
101 const EXCEPTION_NOT_ENOUGTH_UNEMPLOYEES = 0x00e;
102 const EXCEPTION_TOTAL_PRICE_NOT_CALCULATED = 0x00f;
103 const EXCEPTION_HARBOR_HAS_NO_SHIPYARDS = 0x010;
104 const EXCEPTION_CONTRACT_PARTNER_INVALID = 0x011;
105 const EXCEPTION_CONTRACT_PARTNER_MISMATCH = 0x012;
106 const EXCEPTION_CONTRACT_ALREADY_SIGNED = 0x013;
107 const EXCEPTION_UNEXPECTED_EMPTY_STRING = 0x014;
108 const EXCEPTION_PATH_NOT_FOUND = 0x015;
109 const EXCEPTION_INVALID_PATH_NAME = 0x016;
110 const EXCEPTION_READ_PROTECED_PATH = 0x017;
111 const EXCEPTION_WRITE_PROTECED_PATH = 0x018;
112 const EXCEPTION_DIR_POINTER_INVALID = 0x019;
113 const EXCEPTION_FILE_POINTER_INVALID = 0x01a;
114 const EXCEPTION_INVALID_RESOURCE = 0x01b;
115 const EXCEPTION_UNEXPECTED_OBJECT = 0x01c;
116 const EXCEPTION_LIMIT_ELEMENT_IS_UNSUPPORTED = 0x01d;
117 const EXCEPTION_GETTER_IS_MISSING = 0x01e;
118 const EXCEPTION_ARRAY_EXPECTED = 0x01f;
119 const EXCEPTION_ARRAY_HAS_INVALID_COUNT = 0x020;
120 const EXCEPTION_ID_IS_INVALID_FORMAT = 0x021;
121 const EXCEPTION_MD5_CHECKSUMS_MISMATCH = 0x022;
122 const EXCEPTION_UNEXPECTED_STRING_SIZE = 0x023;
123 const EXCEPTION_SIMULATOR_ID_INVALID = 0x024;
124 const EXCEPTION_MISMATCHING_COMPRESSORS = 0x025;
125 const EXCEPTION_CONTAINER_ITEM_IS_NULL = 0x026;
126 const EXCEPTION_ITEM_IS_NO_ARRAY = 0x027;
127 const EXCEPTION_CONTAINER_MAYBE_DAMAGED = 0x028;
128 const EXCEPTION_INVALID_STRING = 0x029;
129 const EXCEPTION_VARIABLE_NOT_SET = 0x02a;
130 const EXCEPTION_ATTRIBUTES_ARE_MISSING = 0x02b;
131 const EXCEPTION_ARRAY_ELEMENTS_MISSING = 0x02c;
132 const EXCEPTION_TEMPLATE_ENGINE_UNSUPPORTED = 0x02d;
133 const EXCEPTION_UNSPPORTED_OPERATION = 0x02e;
134 const EXCEPTION_FACTORY_REQUIRE_PARAMETER = 0x02f;
135 const EXCEPTION_MISSING_ELEMENT = 0x030;
136 const EXCEPTION_HEADERS_ALREADY_SENT = 0x031;
137 const EXCEPTION_DEFAULT_CONTROLLER_GONE = 0x032;
138 const EXCEPTION_CLASS_NOT_FOUND = 0x033;
139 const EXCEPTION_REQUIRED_INTERFACE_MISSING = 0x034;
140 const EXCEPTION_FATAL_ERROR = 0x035;
141 const EXCEPTION_FILE_NOT_FOUND = 0x036;
142 const EXCEPTION_ASSERTION_FAILED = 0x037;
143 const EXCEPTION_FILE_NOT_REACHABLE = 0x038;
144 const EXCEPTION_FILE_CANNOT_BE_READ = 0x039;
145 const EXCEPTION_FILE_CANNOT_BE_WRITTEN = 0x03a;
146 const EXCEPTION_PATH_CANNOT_BE_WRITTEN = 0x03b;
147 const EXCEPTION_DATABASE_UPDATED_NOT_ALLOWED = 0x03c;
148 const EXCEPTION_FILTER_CHAIN_INTERCEPTED = 0x03d;
149 const EXCEPTION_INVALID_SOCKET = 0x03e;
150 const EXCEPTION_SELF_INSTANCE = 0x03f;
153 * Startup time in miliseconds
155 private static $startupTime = 0;
158 * Protected super constructor
160 * @param $className Name of the class
163 protected function __construct (string $className) {
165 $this->setRealClass($className);
167 // Is the startup time set? (0 cannot be true anymore)
168 if (self::$startupTime == 0) {
170 self::$startupTime = microtime(true);
175 * Destructor for all classes. You should not call this method on your own.
179 public function __destruct () {
180 // Is this object already destroyed?
181 if ($this->__toString() != 'DestructedObject') {
182 // Destroy all informations about this class but keep some text about it alive
183 $this->setRealClass('DestructedObject');
184 } elseif ((defined('DEBUG_DESTRUCTOR')) && (is_object($this->getDebugInstance()))) {
185 // Already destructed object
186 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('The object <span class="object_name">%s</span> is already destroyed.',
190 // Do not call this twice
191 trigger_error(__METHOD__ . ': Called twice.');
197 * The __call() method where all non-implemented methods end up
199 * @param $methodName Name of the missing method
200 * @args $args Arguments passed to the method
203 public final function __call (string $methodName, array $args = NULL) {
205 self::$selfInstance = $this;
207 // Call static method
208 self::__callStatic($methodName, $args);
210 // Clear self-instance
211 self::$selfInstance = NULL;
215 * The __callStatic() method where all non-implemented static methods end up
217 * @param $methodName Name of the missing method
218 * @param $args Arguments passed to the method
220 * @throws InvalidArgumentException If self::$selfInstance is not a framework's own object
222 public static final function __callStatic (string $methodName, array $args = NULL) {
223 // Init argument string and class name
224 //* PRINT-DEBUG: */ printf('[%s:%d]: methodName=%s,args[]=%s - CALLED!' . PHP_EOL, __METHOD__, __LINE__, $methodName, gettype($args));
226 $className = 'unknown';
228 // Is self-instance set?
229 if (self::$selfInstance instanceof FrameworkInterface) {
230 // Framework's own instance
231 $className = self::$selfInstance->__toString();
232 } elseif (!is_null(self::$selfInstance)) {
234 throw new InvalidArgumentException(sprintf('self::instance[%s] is not expected.', gettype(self::$selfInstance)), self::EXCEPTION_SELF_INSTANCE);
237 // Is it NULL, empty or an array?
238 if (is_null($args)) {
240 $argsString = 'NULL';
241 } elseif (is_array($args)) {
245 // Some arguments are there
246 foreach ($args as $arg) {
247 // Add data about the argument
248 $argsString .= gettype($arg) . ':';
251 // Found a NULL argument
252 $argsString .= 'NULL';
253 } elseif (is_string($arg)) {
254 // Add length for strings
255 $argsString .= strlen($arg);
256 } elseif ((is_int($arg)) || (is_float($arg))) {
259 } elseif (is_array($arg)) {
260 // .. or size if array
261 $argsString .= count($arg);
262 } elseif (is_object($arg)) {
264 $reflection = new ReflectionClass($arg);
266 // Is an other object, maybe no __toString() available
267 $argsString .= $reflection->getName();
268 } elseif ($arg === true) {
269 // ... is boolean 'true'
270 $argsString .= 'true';
271 } elseif ($arg === false) {
272 // ... is boolean 'false'
273 $argsString .= 'false';
276 // Comma for next one
281 if (substr($argsString, -2, 1) == ',') {
283 $argsString = substr($argsString, 0, -2);
290 // Output stub message
291 // @TODO __CLASS__ does always return BaseFrameworkSystem but not the extending (=child) class
292 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s::%s]: Stub! Args: %s',
303 * Getter for $realClass
305 * @return $realClass The name of the real class (not BaseFrameworkSystem)
307 public function __toString () {
308 return $this->realClass;
312 * Magic method to catch setting of missing but set class fields/attributes
314 * @param $name Name of the field/attribute
315 * @param $value Value to store
318 public final function __set (string $name, $value) {
319 $this->debugBackTrace(sprintf('Tried to set a missing field. name=%s, value[%s]=%s',
322 print_r($value, true)
327 * Magic method to catch getting of missing fields/attributes
329 * @param $name Name of the field/attribute
332 public final function __get (string $name) {
333 $this->debugBackTrace(sprintf('Tried to get a missing field. name=%s',
339 * Magic method to catch unsetting of missing fields/attributes
341 * @param $name Name of the field/attribute
344 public final function __unset (string $name) {
345 $this->debugBackTrace(sprintf('Tried to unset a missing field. name=%s',
351 * Magic method to catch object serialization
353 * @return $unsupported Unsupported method
354 * @throws UnsupportedOperationException Objects of this framework cannot be serialized
356 public final function __sleep () {
357 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
361 * Magic method to catch object deserialization
363 * @return $unsupported Unsupported method
364 * @throws UnsupportedOperationException Objects of this framework cannot be serialized
366 public final function __wakeup () {
367 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
371 * Magic method to catch calls when an object instance is called
373 * @return $unsupported Unsupported method
374 * @throws UnsupportedOperationException Objects of this framework cannot be serialized
376 public final function __invoke () {
377 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
381 * Setter for the real class name
383 * @param $realClass Class name (string)
386 public final function setRealClass (string $realClass) {
388 $this->realClass = $realClass;
392 * Setter for debug instance
394 * @param $debugInstance The instance for debug output class
397 public final function setDebugInstance (DebugMiddleware $debugInstance) {
398 GenericRegistry::getRegistry()->addInstance('debug', $debugInstance);
402 * Getter for debug instance
404 * @return $debugInstance Instance to class DebugConsoleOutput or DebugWebOutput
406 public final function getDebugInstance () {
407 // Get debug instance
408 $debugInstance = GenericRegistry::getRegistry()->getInstance('debug');
411 return $debugInstance;
415 * Setter for web output instance
417 * @param $webInstance The instance for web output class
420 public final function setWebOutputInstance (OutputStreamer $webInstance) {
421 GenericRegistry::getRegistry()->addInstance('web_output', $webInstance);
425 * Getter for web output instance
427 * @return $webOutputInstance - Instance to class WebOutput
429 public final function getWebOutputInstance () {
430 $webOutputInstance = GenericRegistry::getRegistry()->getInstance('web_output');
431 return $webOutputInstance;
435 * Setter for call-back instance
437 * @param $callbackInstance An instance of a FrameworkInterface class
440 public final function setCallbackInstance (FrameworkInterface $callbackInstance) {
441 $this->callbackInstance = $callbackInstance;
445 * Getter for call-back instance
447 * @return $callbackInstance An instance of a FrameworkInterface class
449 protected final function getCallbackInstance () {
450 return $this->callbackInstance;
454 * Checks whether an object equals this object. You should overwrite this
455 * method to implement own equality checks
457 * @param $objectInstance An instance of a FrameworkInterface object
458 * @return $equals Whether both objects equals
460 public function equals (FrameworkInterface $objectInstance) {
463 $this->__toString() == $objectInstance->__toString()
465 $this->hashCode() == $objectInstance->hashCode()
473 * Generates a generic hash code of this class. You should really overwrite
474 * this method with your own hash code generator code. But keep KISS in mind.
476 * @return $hashCode A generic hash code respresenting this whole class
478 public function hashCode () {
480 return crc32($this->__toString());
484 * Appends a trailing slash to a string
486 * @param $str A string (maybe) without trailing slash
487 * @return $str A string with an auto-appended trailing slash
489 public final function addMissingTrailingSlash (string $str) {
490 // Is there a trailing slash?
491 if (substr($str, -1, 1) != '/') {
495 // Return string with trailing slash
500 * Debugs this instance by putting out it's full content
502 * @param $message Optional message to show in debug output
505 public final function debugInstance (string $message = '') {
506 // Restore the error handler to avoid trouble with missing array elements or undeclared variables
507 restore_error_handler();
513 if (!empty($message)) {
515 $content = sprintf('<div class="debug_message">
517 </div>' . PHP_EOL, $message);
520 // Generate the output
521 $content .= sprintf('<pre>%s</pre>',
530 ApplicationEntryPoint::exitApplication(sprintf('<div class="debug_header">
533 <div class="debug_content">
537 <div class="debug_include_list">
542 ClassLoader::getSelfInstance()->getPrintableIncludeList()
547 * Replaces control characters with printable output
549 * @param $str String with control characters
550 * @return $str Replaced string
552 protected function replaceControlCharacters (string $str) {
555 chr(13), '[r]', str_replace(
556 chr(10), '[n]', str_replace(
566 * Output a partial stub message for the caller method
568 * @param $message An optional message to display
571 protected function partialStub (string $message = '') {
573 $stubMessage = 'Partial stub!';
575 // Is an extra message given?
576 if (!empty($message)) {
577 // Then add it as well
578 $stubMessage .= ' Message: ' . $message;
581 // Debug instance is there?
582 if (!is_null($this->getDebugInstance())) {
583 // Output stub message
584 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput($stubMessage);
587 trigger_error($stubMessage);
593 * Outputs a debug backtrace and stops further script execution
595 * @param $message An optional message to output
596 * @param $doExit Whether exit the program (true is default)
599 public function debugBackTrace (string $message = '', bool $doExit = true) {
600 // Sorry, there is no other way getting this nice backtrace
601 if (!empty($message)) {
603 printf('Message: %s<br />' . PHP_EOL, $message);
607 debug_print_backtrace();
611 if ($doExit === true) {
617 * Creates an instance of a debugger instance
619 * @param $className Name of the class (currently unsupported)
620 * @param $lineNumber Line number where the call was made
621 * @return $debugInstance An instance of a debugger class
622 * @deprecated Not fully, as the new Logger facilities are not finished yet.
624 public final static function createDebugInstance (string $className, int $lineNumber = NULL) {
625 // Validate parameter
626 if (empty($className)) {
628 throw new InvalidArgumentException('Parameter "className" is empty');
629 } elseif (!GenericRegistry::getRegistry()->instanceExists('debug')) {
630 // Init debug instance
631 $debugInstance = NULL;
635 // Get a debugger instance
636 $debugInstance = DebugMiddleware::createDebugMiddleware(FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('debug_' . FrameworkBootstrap::getRequestTypeFromSystem() . '_class'), $className);
637 } catch (NullPointerException $e) {
638 // Didn't work, no instance there
639 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));
642 // Empty string should be ignored and used for testing the middleware
643 DebugMiddleware::getSelfInstance()->output('');
645 // Set it in registry
646 GenericRegistry::getRegistry()->addInstance('debug', $debugInstance);
648 // Get instance from registry
649 $debugInstance = GenericRegistry::getRegistry()->getDebugInstance();
653 return $debugInstance;
657 * Simple output of a message with line-break
659 * @param $message Message to output
662 public function outputLine (string $message) {
664 print($message . PHP_EOL);
668 * Outputs a debug message whether to debug instance (should be set!) or
669 * dies with or ptints the message. Do NEVER EVER rewrite the exit() call to
670 * ApplicationEntryPoint::app_exit(), this would cause an endless loop.
672 * @param $message Message we shall send out...
673 * @param $doPrint Whether print or die here (default: print)
674 * @paran $stripTags Whether to strip tags (default: false)
677 public function debugOutput (string $message, bool $doPrint = true, bool $stripTags = false) {
678 // Set debug instance to NULL
679 $debugInstance = NULL;
682 $backtrace = debug_backtrace(!DEBUG_BACKTRACE_PROVIDE_OBJECT);
684 // Is function partialStub/__callStatic ?
685 if (isset(self::$stubMethods[$backtrace[1]['function']])) {
686 // Prepend class::function:line from 3rd element
687 $message = sprintf('[%s::%s:%d]: %s',
688 $backtrace[2]['class'],
689 $backtrace[2]['function'],
690 (isset($backtrace[2]['line']) ? $backtrace[2]['line'] : '0'),
694 // Prepend class::function:line from 2nd element
695 $message = sprintf('[%s::%s:%d]: %s',
696 $backtrace[1]['class'],
697 $backtrace[1]['function'],
698 (isset($backtrace[1]['line']) ? $backtrace[1]['line'] : '0'),
705 // Get debug instance
706 $debugInstance = $this->getDebugInstance();
707 } catch (NullPointerException $e) {
708 // The debug instance is not set (yet)
711 // Is the debug instance there?
712 if (is_object($debugInstance)) {
713 // Use debug output handler
714 $debugInstance->output($message, $stripTags);
716 if ($doPrint === false) {
717 // Die here if not printed
721 // Are debug times enabled?
722 if (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('debug_' . FrameworkBootstrap::getRequestTypeFromSystem() . '_output_timings') == 'Y') {
724 $message = $this->getPrintableExecutionTime() . $message;
728 if ($doPrint === true) {
730 $this->outputLine($message);
739 * Marks up the code by adding e.g. line numbers
741 * @param $phpCode Unmarked PHP code
742 * @return $markedCode Marked PHP code
744 public function markupCode (string $phpCode) {
749 $errorArray = error_get_last();
751 // Init the code with error message
752 if (is_array($errorArray)) {
754 $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>',
755 basename($errorArray['file']),
757 $errorArray['message'],
762 // Add line number to the code
763 foreach (explode(chr(10), $phpCode) as $lineNo => $code) {
765 $markedCode .= sprintf('<span id="code_line">%s</span>: %s' . PHP_EOL,
767 htmlentities($code, ENT_QUOTES)
776 * "Getter" for databse entry
778 * @return $entry An array with database entries
779 * @throws NullPointerException If the database result is not found
780 * @throws InvalidDatabaseResultException If the database result is invalid
781 * @todo Monolithic method, should be moved to proper classes
783 protected final function getDatabaseEntry () {
784 // Is there an instance?
785 if (!$this->getResultInstance() instanceof SearchableResult) {
786 // Throw an exception here
787 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
791 $this->getResultInstance()->rewind();
793 // Do we have an entry?
794 if ($this->getResultInstance()->valid() === false) {
795 // @TODO Move the constant to e.g. BaseDatabaseResult when there is a non-cached database result available
796 throw new InvalidDatabaseResultException(array($this, $this->getResultInstance()), CachedDatabaseResult::EXCEPTION_INVALID_DATABASE_RESULT);
800 $this->getResultInstance()->next();
803 $entry = $this->getResultInstance()->current();
810 * Getter for field name
812 * @param $fieldName Field name which we shall get
813 * @return $fieldValue Field value from the user
814 * @throws NullPointerException If the result instance is null
816 public final function getField (string $fieldName) {
817 // Default field value
820 // Get result instance
821 $resultInstance = $this->getResultInstance();
823 // Is this instance null?
824 if (is_null($resultInstance)) {
825 // Then the user instance is no longer valid (expired cookies?)
826 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
830 $fieldArray = $resultInstance->current();
831 //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput($fieldName.':<pre>'.print_r($fieldArray, true).'</pre>');
833 // Convert dashes to underscore
834 $fieldName2 = StringUtils::convertDashesToUnderscores($fieldName);
836 // Does the field exist?
837 if ($this->isFieldSet($fieldName)) {
839 $fieldValue = $fieldArray[$fieldName2];
840 } elseif (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('developer_mode_enabled')) {
841 // Missing field entry, may require debugging
842 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FRAMEWORK-SYSTEM: fieldArray<pre>=' . print_r($fieldArray, true) . '</pre>,fieldName=' . $fieldName . ' not found!');
844 // Missing field entry, may require debugging
845 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FRAMEWORK-SYSTEM: fieldName=' . $fieldName . ' not found!');
853 * Checks if given field is set
855 * @param $fieldName Field name to check
856 * @return $isSet Whether the given field name is set
857 * @throws NullPointerException If the result instance is null
859 public function isFieldSet (string $fieldName) {
860 // Get result instance
861 $resultInstance = $this->getResultInstance();
863 // Is this instance null?
864 if (is_null($resultInstance)) {
865 // Then the user instance is no longer valid (expired cookies?)
866 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
870 $fieldArray = $resultInstance->current();
871 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('[' . $this->__toString() . ':' . __LINE__ . '] fieldName=' . $fieldName . ',fieldArray=<pre>'.print_r($fieldArray, true).'</pre>');
873 // Convert dashes to underscore
874 $fieldName = StringUtils::convertDashesToUnderscores($fieldName);
877 $isSet = isset($fieldArray[$fieldName]);
884 * Outputs a deprecation warning to the developer.
886 * @param $message The message we shall output to the developer
888 * @todo Write a logging mechanism for productive mode
890 public function deprecationWarning (string $message) {
891 // Is developer mode active?
892 if (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('developer_mode_enabled')) {
893 // Debug instance is there?
894 if (!is_null($this->getDebugInstance())) {
895 // Output stub message
896 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput($message);
899 trigger_error($message . "<br />\n");
903 // @TODO Finish this part!
904 $this->partialStub('Developer mode inactive. Message:' . $message);
909 * Checks whether the given PHP extension is loaded
911 * @param $phpExtension The PHP extension we shall check
912 * @return $isLoaded Whether the PHP extension is loaded
914 public final function isPhpExtensionLoaded (string $phpExtension) {
916 $isLoaded = in_array($phpExtension, get_loaded_extensions());
923 * "Getter" as a time() replacement but with milliseconds. You should use this
924 * method instead of the encapsulated getimeofday() function.
926 * @return $milliTime Timestamp with milliseconds
928 public function getMilliTime () {
929 // Get the time of day as float
930 $milliTime = gettimeofday(true);
937 * Idles (sleeps) for given milliseconds
939 * @return $hasSlept Whether it goes fine
941 public function idle (int $milliSeconds) {
942 // Sleep is fine by default
945 // Idle so long with found function
946 if (function_exists('time_sleep_until')) {
947 // Get current time and add idle time
948 $sleepUntil = $this->getMilliTime() + abs($milliSeconds) / 1000;
950 // New PHP 5.1.0 function found, ignore errors
951 $hasSlept = @time_sleep_until($sleepUntil);
954 * My Sun station doesn't have that function even with latest PHP
957 usleep($milliSeconds * 1000);
965 * Checks whether the given encoded data was encoded with Base64
967 * @param $encodedData Encoded data we shall check
968 * @return $isBase64 Whether the encoded data is Base64
970 protected function isBase64Encoded (string $encodedData) {
972 $isBase64 = (@base64_decode($encodedData, true) !== false);
979 * Getter for startup time in miliseconds
981 * @return $startupTime Startup time in miliseconds
983 protected function getStartupTime () {
984 return self::$startupTime;
988 * "Getter" for a printable currently execution time in nice braces
990 * @return $executionTime Current execution time in nice braces
992 protected function getPrintableExecutionTime () {
993 // Calculate execution time and pack it in nice braces
994 $executionTime = sprintf('[ %01.5f ] ', (microtime(true) - $this->getStartupTime()));
997 return $executionTime;
1001 * Determines if an element is set in the generic array
1003 * @param $keyGroup Main group for the key
1004 * @param $subGroup Sub group for the key
1005 * @param $key Key to check
1006 * @param $element Element to check
1007 * @return $isset Whether the given key is set
1009 protected final function isGenericArrayElementSet (string $keyGroup, string $subGroup, $key, $element) {
1011 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element);
1012 $isset = isset($this->genericArray[$keyGroup][$subGroup][$key][$element]);
1018 * Determines if a key is set in the generic array
1020 * @param $keyGroup Main group for the key
1021 * @param $subGroup Sub group for the key
1022 * @param $key Key to check
1023 * @return $isset Whether the given key is set
1025 protected final function isGenericArrayKeySet (string $keyGroup, string $subGroup, $key) {
1027 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1028 $isset = isset($this->genericArray[$keyGroup][$subGroup][$key]);
1036 * Determines if a group is set in the generic array
1038 * @param $keyGroup Main group
1039 * @param $subGroup Sub group
1040 * @return $isset Whether the given group is set
1042 protected final function isGenericArrayGroupSet (string $keyGroup, string $subGroup) {
1044 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup);
1045 $isset = isset($this->genericArray[$keyGroup][$subGroup]);
1052 * Getter for sub key group
1054 * @param $keyGroup Main key group
1055 * @param $subGroup Sub key group
1056 * @return $array An array with all array elements
1058 protected final function getGenericSubArray (string $keyGroup, string $subGroup) {
1060 if (!$this->isGenericArrayGroupSet($keyGroup, $subGroup)) {
1061 // No, then abort here
1062 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' not found.');
1067 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',value=' . print_r($this->genericArray[$keyGroup][$subGroup], true));
1068 return $this->genericArray[$keyGroup][$subGroup];
1072 * Unsets a given key in generic array
1074 * @param $keyGroup Main group for the key
1075 * @param $subGroup Sub group for the key
1076 * @param $key Key to unset
1079 protected final function unsetGenericArrayKey (string $keyGroup, string $subGroup, $key) {
1081 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1082 unset($this->genericArray[$keyGroup][$subGroup][$key]);
1086 * Unsets a given element in generic array
1088 * @param $keyGroup Main group for the key
1089 * @param $subGroup Sub group for the key
1090 * @param $key Key to unset
1091 * @param $element Element to unset
1094 protected final function unsetGenericArrayElement (string $keyGroup, string $subGroup, $key, $element) {
1096 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element);
1099 unset($this->genericArray[$keyGroup][$subGroup][$key][$element]);
1103 * Append a string to a given generic array key
1105 * @param $keyGroup Main group for the key
1106 * @param $subGroup Sub group for the key
1107 * @param $key Key to unset
1108 * @param $value Value to add/append
1111 protected final function appendStringToGenericArrayKey (string $keyGroup, string $subGroup, $key, string $value, $appendGlue = '') {
1113 //* 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);
1115 // Is it already there?
1116 if ($this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
1118 $this->genericArray[$keyGroup][$subGroup][$key] .= $appendGlue . (string) $value;
1121 $this->genericArray[$keyGroup][$subGroup][$key] = (string) $value;
1126 * Append a string to a given generic array element
1128 * @param $keyGroup Main group for the key
1129 * @param $subGroup Sub group for the key
1130 * @param $key Key to unset
1131 * @param $element Element to check
1132 * @param $value Value to add/append
1135 protected final function appendStringToGenericArrayElement (string $keyGroup, string $subGroup, $key, $element, $value, $appendGlue = '') {
1137 //* 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);
1139 // Is it already there?
1140 if ($this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element)) {
1142 $this->genericArray[$keyGroup][$subGroup][$key][$element] .= $appendGlue . (string) $value;
1145 $this->setStringGenericArrayElement($keyGroup, $subGroup, $key, $element, $value);
1150 * Sets a string in a given generic array element
1152 * @param $keyGroup Main group for the key
1153 * @param $subGroup Sub group for the key
1154 * @param $key Key to unset
1155 * @param $element Element to check
1156 * @param $value Value to add/append
1159 protected final function setStringGenericArrayElement (string $keyGroup, string $subGroup, $key, $element, $value, $appendGlue = '') {
1161 //* 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);
1164 $this->genericArray[$keyGroup][$subGroup][$key][$element] = (string) $value;
1168 * Initializes given generic array group
1170 * @param $keyGroup Main group for the key
1171 * @param $subGroup Sub group for the key
1172 * @param $key Key to use
1173 * @param $forceInit Optionally force initialization
1176 protected final function initGenericArrayGroup (string $keyGroup, string $subGroup, bool $forceInit = false) {
1178 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',forceInit=' . intval($forceInit));
1180 // Is it already set?
1181 if (($forceInit === false) && ($this->isGenericArrayGroupSet($keyGroup, $subGroup))) {
1182 // Already initialized
1183 trigger_error(__METHOD__ . ':keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' already initialized.');
1188 $this->genericArray[$keyGroup][$subGroup] = [];
1192 * Initializes given generic array key
1194 * @param $keyGroup Main group for the key
1195 * @param $subGroup Sub group for the key
1196 * @param $key Key to use
1197 * @param $forceInit Optionally force initialization
1200 protected final function initGenericArrayKey (string $keyGroup, string $subGroup, $key, bool $forceInit = false) {
1202 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',forceInit=' . intval($forceInit));
1204 // Is it already set?
1205 if (($forceInit === false) && ($this->isGenericArrayKeySet($keyGroup, $subGroup, $key))) {
1206 // Already initialized
1207 trigger_error(__METHOD__ . ':keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' already initialized.');
1212 $this->genericArray[$keyGroup][$subGroup][$key] = [];
1216 * Initializes given generic array element
1218 * @param $keyGroup Main group for the key
1219 * @param $subGroup Sub group for the key
1220 * @param $key Key to use
1221 * @param $element Element to use
1222 * @param $forceInit Optionally force initialization
1225 protected final function initGenericArrayElement (string $keyGroup, string $subGroup, $key, $element, bool $forceInit = false) {
1227 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element . ',forceInit=' . intval($forceInit));
1229 // Is it already set?
1230 if (($forceInit === false) && ($this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element))) {
1231 // Already initialized
1232 trigger_error(__METHOD__ . ':keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element . ' already initialized.');
1237 $this->genericArray[$keyGroup][$subGroup][$key][$element] = [];
1241 * Pushes an element to a generic key
1243 * @param $keyGroup Main group for the key
1244 * @param $subGroup Sub group for the key
1245 * @param $key Key to use
1246 * @param $value Value to add/append
1247 * @return $count Number of array elements
1249 protected final function pushValueToGenericArrayKey (string $keyGroup, string $subGroup, $key, $value) {
1251 //* NOISY-DEBUG: */ if (!is_object($value)) $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',value[' . gettype($value) . ']=' . print_r($value, true));
1254 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
1256 $this->initGenericArrayKey($keyGroup, $subGroup, $key);
1260 $count = array_push($this->genericArray[$keyGroup][$subGroup][$key], $value);
1263 //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], true));
1264 //* DEBUG: */ print(__METHOD__ . ': count=' . $count . PHP_EOL);
1269 * Pushes an element to a generic array element
1271 * @param $keyGroup Main group for the key
1272 * @param $subGroup Sub group for the key
1273 * @param $key Key to use
1274 * @param $element Element to check
1275 * @param $value Value to add/append
1276 * @return $count Number of array elements
1278 protected final function pushValueToGenericArrayElement (string $keyGroup, string $subGroup, $key, $element, $value) {
1280 //* 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));
1283 if (!$this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element)) {
1285 $this->initGenericArrayElement($keyGroup, $subGroup, $key, $element);
1289 $count = array_push($this->genericArray[$keyGroup][$subGroup][$key][$element], $value);
1292 //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], true));
1293 //* DEBUG: */ print(__METHOD__ . ': count=' . $count . PHP_EOL);
1298 * Pops an element from a generic group
1300 * @param $keyGroup Main group for the key
1301 * @param $subGroup Sub group for the key
1302 * @param $key Key to unset
1303 * @return $value Last "popped" value
1305 protected final function popGenericArrayElement (string $keyGroup, string $subGroup, $key) {
1307 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1310 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
1312 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' not found.');
1317 $value = array_pop($this->genericArray[$keyGroup][$subGroup][$key]);
1320 //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], true));
1321 //* DEBUG: */ print(__METHOD__ . ': value[' . gettype($value) . ']=' . print_r($value, true) . PHP_EOL);
1326 * Shifts an element from a generic group
1328 * @param $keyGroup Main group for the key
1329 * @param $subGroup Sub group for the key
1330 * @param $key Key to unset
1331 * @return $value Last "popped" value
1333 protected final function shiftGenericArrayElement (string $keyGroup, string $subGroup, $key) {
1335 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1338 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
1340 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' not found.');
1345 $value = array_shift($this->genericArray[$keyGroup][$subGroup][$key]);
1348 //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], true));
1349 //* DEBUG: */ print(__METHOD__ . ': value[' . gettype($value) . ']=' . print_r($value, true) . PHP_EOL);
1354 * Count generic array group
1356 * @param $keyGroup Main group for the key
1357 * @return $count Count of given group
1359 protected final function countGenericArray ($keyGroup) {
1361 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup);
1364 if (!isset($this->genericArray[$keyGroup])) {
1366 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ' not found.');
1371 $count = count($this->genericArray[$keyGroup]);
1374 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',count=' . $count);
1381 * Count generic array sub group
1383 * @param $keyGroup Main group for the key
1384 * @param $subGroup Sub group for the key
1385 * @return $count Count of given group
1387 protected final function countGenericArrayGroup (string $keyGroup, string $subGroup) {
1389 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup);
1392 if (!$this->isGenericArrayGroupSet($keyGroup, $subGroup)) {
1394 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' not found.');
1399 $count = count($this->genericArray[$keyGroup][$subGroup]);
1402 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',count=' . $count);
1409 * Count generic array elements
1411 * @param $keyGroup Main group for the key
1412 * @param $subGroup Sub group for the key
1413 * @para $key Key to count
1414 * @return $count Count of given key
1416 protected final function countGenericArrayElements (string $keyGroup, string $subGroup, $key) {
1418 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1421 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
1423 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' not found.');
1425 } elseif (!$this->isValidGenericArrayGroup($keyGroup, $subGroup)) {
1427 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' is not an array.');
1432 $count = count($this->genericArray[$keyGroup][$subGroup][$key]);
1435 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',count=' . $count);
1442 * Getter for whole generic group array
1444 * @param $keyGroup Key group to get
1445 * @return $array Whole generic array group
1447 protected final function getGenericArray ($keyGroup) {
1449 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup);
1452 if (!isset($this->genericArray[$keyGroup])) {
1454 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ' does not exist.');
1459 return $this->genericArray[$keyGroup];
1463 * Setter for generic array key
1465 * @param $keyGroup Key group to get
1466 * @param $subGroup Sub group for the key
1467 * @param $key Key to unset
1468 * @param $value Mixed value from generic array element
1471 protected final function setGenericArrayKey (string $keyGroup, string $subGroup, $key, $value) {
1473 //* NOISY-DEBUG: */ if (!is_object($value)) $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',value[' . gettype($value) . ']=' . print_r($value, true));
1476 $this->genericArray[$keyGroup][$subGroup][$key] = $value;
1480 * Getter for generic array key
1482 * @param $keyGroup Key group to get
1483 * @param $subGroup Sub group for the key
1484 * @param $key Key to unset
1485 * @return $value Mixed value from generic array element
1487 protected final function getGenericArrayKey (string $keyGroup, string $subGroup, $key) {
1489 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1492 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
1494 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' does not exist.');
1499 return $this->genericArray[$keyGroup][$subGroup][$key];
1503 * Sets a value in given generic array key/element
1505 * @param $keyGroup Main group for the key
1506 * @param $subGroup Sub group for the key
1507 * @param $key Key to set
1508 * @param $element Element to set
1509 * @param $value Value to set
1512 protected final function setGenericArrayElement (string $keyGroup, string $subGroup, $key, $element, $value) {
1514 //* 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));
1517 $this->genericArray[$keyGroup][$subGroup][$key][$element] = $value;
1521 * Getter for generic array element
1523 * @param $keyGroup Key group to get
1524 * @param $subGroup Sub group for the key
1525 * @param $key Key to look for
1526 * @param $element Element to look for
1527 * @return $value Mixed value from generic array element
1529 protected final function getGenericArrayElement (string $keyGroup, string $subGroup, $key, $element) {
1531 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element);
1534 if (!$this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element)) {
1536 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element . ' does not exist.');
1541 return $this->genericArray[$keyGroup][$subGroup][$key][$element];
1545 * Checks if a given sub group is valid (array)
1547 * @param $keyGroup Key group to get
1548 * @param $subGroup Sub group for the key
1549 * @return $isValid Whether given sub group is valid
1551 protected final function isValidGenericArrayGroup (string $keyGroup, string $subGroup) {
1553 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup);
1556 $isValid = (($this->isGenericArrayGroupSet($keyGroup, $subGroup)) && (is_array($this->getGenericSubArray($keyGroup, $subGroup))));
1563 * Checks if a given key is valid (array)
1565 * @param $keyGroup Key group to get
1566 * @param $subGroup Sub group for the key
1567 * @param $key Key to check
1568 * @return $isValid Whether given sub group is valid
1570 protected final function isValidGenericArrayKey (string $keyGroup, string $subGroup, $key) {
1572 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1575 $isValid = (($this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) && (is_array($this->getGenericArrayKey($keyGroup, $subGroup, $key))));
1582 * Initializes the web output instance
1586 protected function initWebOutputInstance () {
1587 // Init web output instance
1588 $outputInstance = ObjectFactory::createObjectByConfiguredName('output_class');
1591 $this->setWebOutputInstance($outputInstance);
1595 * Translates boolean true to 'Y' and false to 'N'
1597 * @param $boolean Boolean value
1598 * @return $translated Translated boolean value
1600 public static final function translateBooleanToYesNo (bool $boolean) {
1601 // Make sure it is really boolean
1602 assert(is_bool($boolean));
1605 $translated = ($boolean === true) ? 'Y' : 'N';
1607 // ... and return it
1612 * Creates a full-qualified file name (FQFN) for given file name by adding
1613 * a configured temporary file path to it.
1615 * @param $infoInstance An instance of a SplFileInfo class
1616 * @return $tempInstance An instance of a SplFileInfo class (temporary file)
1617 * @throw PathWriteProtectedException If the path in 'temp_file_path' is write-protected
1618 * @throws FileIoException If the file cannot be written
1620 protected static function createTempPathForFile (SplFileInfo $infoInstance) {
1622 $basePath = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('temp_file_path');
1624 // Is the path writeable?
1625 if (!is_writable($basePath)) {
1626 // Path is write-protected
1627 throw new PathWriteProtectedException($infoInstance, self::EXCEPTION_PATH_CANNOT_BE_WRITTEN);
1631 $tempInstance = new SplFileInfo($basePath . DIRECTORY_SEPARATOR . $infoInstance->getBasename());
1634 if (!FrameworkBootstrap::isReachableFilePath($tempInstance)) {
1636 throw new FileIoException($tempInstance, self::EXCEPTION_FILE_NOT_REACHABLE);
1640 return $tempInstance;
1644 * "Getter" for a printable state name
1646 * @return $stateName Name of the node's state in a printable format
1647 * @todo Move this class away from this monolithic place (not whole class is monolithic)
1649 public final function getPrintableState () {
1650 // Default is 'null'
1651 $stateName = 'null';
1653 // Get the state instance
1654 $stateInstance = $this->getStateInstance();
1656 // Is it an instance of Stateable?
1657 if ($stateInstance instanceof Stateable) {
1658 // Then use that state name
1659 $stateName = $stateInstance->getStateName();