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\PathWriteProtectedException;
10 use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
11 use Org\Mxchange\CoreFramework\Generic\NullPointerException;
12 use Org\Mxchange\CoreFramework\Generic\UnsupportedOperationException;
13 use Org\Mxchange\CoreFramework\Helper\Application\ApplicationHelper;
14 use Org\Mxchange\CoreFramework\Loader\ClassLoader;
15 use Org\Mxchange\CoreFramework\Manager\ManageableApplication;
16 use Org\Mxchange\CoreFramework\Middleware\Debug\DebugMiddleware;
17 use Org\Mxchange\CoreFramework\Registry\GenericRegistry;
18 use Org\Mxchange\CoreFramework\Result\Database\CachedDatabaseResult;
19 use Org\Mxchange\CoreFramework\State\Stateable;
20 use Org\Mxchange\CoreFramework\Stream\Output\OutputStreamer;
21 use Org\Mxchange\CoreFramework\Utils\Strings\StringUtils;
25 use \InvalidArgumentException;
30 * The simulator system class is the super class of all other classes. This
31 * class handles saving of games etc.
33 * @author Roland Haeder <webmaster@shipsimu.org>
35 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2021 Core Developer Team
36 * @license GNU GPL 3.0 or any newer version
37 * @link http://www.shipsimu.org
39 * This program is free software: you can redistribute it and/or modify
40 * it under the terms of the GNU General Public License as published by
41 * the Free Software Foundation, either version 3 of the License, or
42 * (at your option) any later version.
44 * This program is distributed in the hope that it will be useful,
45 * but WITHOUT ANY WARRANTY; without even the implied warranty of
46 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
47 * GNU General Public License for more details.
49 * You should have received a copy of the GNU General Public License
50 * along with this program. If not, see <http://www.gnu.org/licenses/>.
52 abstract class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
54 * Self-referencing instance
56 private static $selfInstance = NULL;
61 private $realClass = __CLASS__;
66 private $callbackInstance = NULL;
71 private $genericArray = [];
73 /***********************
74 * Exception codes.... *
75 ***********************/
77 // @todo Try to clean these constants up
78 const EXCEPTION_IS_NULL_POINTER = 0x001;
79 const EXCEPTION_IS_NO_OBJECT = 0x002;
80 const EXCEPTION_IS_NO_ARRAY = 0x003;
81 const EXCEPTION_MISSING_METHOD = 0x004;
82 const EXCEPTION_CLASSES_NOT_MATCHING = 0x005;
83 const EXCEPTION_INDEX_OUT_OF_BOUNDS = 0x006;
84 const EXCEPTION_DIMENSION_ARRAY_INVALID = 0x007;
85 const EXCEPTION_ITEM_NOT_TRADEABLE = 0x008;
86 const EXCEPTION_ITEM_NOT_IN_PRICE_LIST = 0x009;
87 const EXCEPTION_GENDER_IS_WRONG = 0x00a;
88 const EXCEPTION_BIRTH_DATE_IS_INVALID = 0x00b;
89 const EXCEPTION_EMPTY_STRUCTURES_ARRAY = 0x00c;
90 const EXCEPTION_HAS_ALREADY_PERSONELL_LIST = 0x00d;
91 const EXCEPTION_NOT_ENOUGTH_UNEMPLOYEES = 0x00e;
92 const EXCEPTION_TOTAL_PRICE_NOT_CALCULATED = 0x00f;
93 const EXCEPTION_HARBOR_HAS_NO_SHIPYARDS = 0x010;
94 const EXCEPTION_CONTRACT_PARTNER_INVALID = 0x011;
95 const EXCEPTION_CONTRACT_PARTNER_MISMATCH = 0x012;
96 const EXCEPTION_CONTRACT_ALREADY_SIGNED = 0x013;
97 const EXCEPTION_UNEXPECTED_EMPTY_STRING = 0x014;
98 const EXCEPTION_PATH_NOT_FOUND = 0x015;
99 const EXCEPTION_INVALID_PATH_NAME = 0x016;
100 const EXCEPTION_READ_PROTECED_PATH = 0x017;
101 const EXCEPTION_WRITE_PROTECED_PATH = 0x018;
102 const EXCEPTION_DIR_POINTER_INVALID = 0x019;
103 const EXCEPTION_FILE_POINTER_INVALID = 0x01a;
104 const EXCEPTION_INVALID_RESOURCE = 0x01b;
105 const EXCEPTION_UNEXPECTED_OBJECT = 0x01c;
106 const EXCEPTION_LIMIT_ELEMENT_IS_UNSUPPORTED = 0x01d;
107 const EXCEPTION_GETTER_IS_MISSING = 0x01e;
108 const EXCEPTION_ARRAY_EXPECTED = 0x01f;
109 const EXCEPTION_ARRAY_HAS_INVALID_COUNT = 0x020;
110 const EXCEPTION_ID_IS_INVALID_FORMAT = 0x021;
111 const EXCEPTION_MD5_CHECKSUMS_MISMATCH = 0x022;
112 const EXCEPTION_UNEXPECTED_STRING_SIZE = 0x023;
113 const EXCEPTION_SIMULATOR_ID_INVALID = 0x024;
114 const EXCEPTION_MISMATCHING_COMPRESSORS = 0x025;
115 const EXCEPTION_CONTAINER_ITEM_IS_NULL = 0x026;
116 const EXCEPTION_ITEM_IS_NO_ARRAY = 0x027;
117 const EXCEPTION_CONTAINER_MAYBE_DAMAGED = 0x028;
118 const EXCEPTION_INVALID_STRING = 0x029;
119 const EXCEPTION_VARIABLE_NOT_SET = 0x02a;
120 const EXCEPTION_ATTRIBUTES_ARE_MISSING = 0x02b;
121 const EXCEPTION_ARRAY_ELEMENTS_MISSING = 0x02c;
122 const EXCEPTION_TEMPLATE_ENGINE_UNSUPPORTED = 0x02d;
123 const EXCEPTION_UNSPPORTED_OPERATION = 0x02e;
124 const EXCEPTION_FACTORY_REQUIRE_PARAMETER = 0x02f;
125 const EXCEPTION_MISSING_ELEMENT = 0x030;
126 const EXCEPTION_HEADERS_ALREADY_SENT = 0x031;
127 const EXCEPTION_DEFAULT_CONTROLLER_GONE = 0x032;
128 const EXCEPTION_CLASS_NOT_FOUND = 0x033;
129 const EXCEPTION_REQUIRED_INTERFACE_MISSING = 0x034;
130 const EXCEPTION_FATAL_ERROR = 0x035;
131 const EXCEPTION_FILE_NOT_FOUND = 0x036;
132 const EXCEPTION_ASSERTION_FAILED = 0x037;
133 const EXCEPTION_FILE_NOT_REACHABLE = 0x038;
134 const EXCEPTION_FILE_CANNOT_BE_READ = 0x039;
135 const EXCEPTION_FILE_CANNOT_BE_WRITTEN = 0x03a;
136 const EXCEPTION_PATH_CANNOT_BE_WRITTEN = 0x03b;
137 const EXCEPTION_DATABASE_UPDATED_NOT_ALLOWED = 0x03c;
138 const EXCEPTION_FILTER_CHAIN_INTERCEPTED = 0x03d;
139 const EXCEPTION_INVALID_SOCKET = 0x03e;
140 const EXCEPTION_SELF_INSTANCE = 0x03f;
143 * Startup time in miliseconds
145 private static $startupTime = 0;
148 * Protected super constructor
150 * @param $className Name of the class
153 protected function __construct (string $className) {
155 $this->setRealClass($className);
157 // Is the startup time set? (0 cannot be true anymore)
158 if (self::$startupTime == 0) {
160 self::$startupTime = microtime(true);
165 * Destructor for all classes. You should not call this method on your own.
169 public function __destruct () {
170 // Is this object already destroyed?
171 if ($this->__toString() != 'DestructedObject') {
172 // Destroy all informations about this class but keep some text about it alive
173 $this->setRealClass('DestructedObject');
174 } elseif ((defined('DEBUG_DESTRUCTOR')) && (is_object($this->getDebugInstance()))) {
175 // Already destructed object
176 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('The object <span class="object_name">%s</span> is already destroyed.',
180 // Do not call this twice
181 trigger_error(__METHOD__ . ': Called twice.');
187 * The __call() method where all non-implemented methods end up
189 * @param $methodName Name of the missing method
190 * @args $args Arguments passed to the method
193 public final function __call (string $methodName, array $args = NULL) {
195 self::$selfInstance = $this;
197 // Call static method
198 self::__callStatic($methodName, $args);
200 // Clear self-instance
201 self::$selfInstance = NULL;
205 * The __callStatic() method where all non-implemented static methods end up
207 * @param $methodName Name of the missing method
208 * @param $args Arguments passed to the method
210 * @throws InvalidArgumentException If self::$selfInstance is not a framework's own object
212 public static final function __callStatic (string $methodName, array $args = NULL) {
213 // Init argument string and class name
214 //* PRINT-DEBUG: */ printf('[%s:%d]: methodName=%s,args[]=%s - CALLED!' . PHP_EOL, __METHOD__, __LINE__, $methodName, gettype($args));
216 $className = 'unknown';
218 // Is self-instance set?
219 if (self::$selfInstance instanceof FrameworkInterface) {
220 // Framework's own instance
221 $className = self::$selfInstance->__toString();
222 } elseif (!is_null(self::$selfInstance)) {
224 throw new InvalidArgumentException(sprintf('self::instance[%s] is not expected.', gettype(self::$selfInstance)), self::EXCEPTION_SELF_INSTANCE);
227 // Is it NULL, empty or an array?
228 if (is_null($args)) {
230 $argsString = 'NULL';
231 } elseif (is_array($args)) {
235 // Some arguments are there
236 foreach ($args as $arg) {
237 // Add data about the argument
238 $argsString .= gettype($arg) . ':';
241 // Found a NULL argument
242 $argsString .= 'NULL';
243 } elseif (is_string($arg)) {
244 // Add length for strings
245 $argsString .= strlen($arg);
246 } elseif ((is_int($arg)) || (is_float($arg))) {
249 } elseif (is_array($arg)) {
250 // .. or size if array
251 $argsString .= count($arg);
252 } elseif (is_object($arg)) {
254 $reflection = new ReflectionClass($arg);
256 // Is an other object, maybe no __toString() available
257 $argsString .= $reflection->getName();
258 } elseif ($arg === true) {
259 // ... is boolean 'true'
260 $argsString .= 'true';
261 } elseif ($arg === false) {
262 // ... is boolean 'false'
263 $argsString .= 'false';
266 // Comma for next one
271 if (substr($argsString, -2, 1) == ',') {
273 $argsString = substr($argsString, 0, -2);
280 // Output stub message
281 // @TODO __CLASS__ does always return BaseFrameworkSystem but not the extending (=child) class
282 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s::%s]: Stub! Args: %s',
293 * Getter for $realClass
295 * @return $realClass The name of the real class (not BaseFrameworkSystem)
297 public function __toString () {
298 return $this->realClass;
302 * Magic method to catch setting of missing but set class fields/attributes
304 * @param $name Name of the field/attribute
305 * @param $value Value to store
308 public final function __set (string $name, $value) {
309 $this->debugBackTrace(sprintf('Tried to set a missing field. name=%s, value[%s]=%s',
312 print_r($value, true)
317 * Magic method to catch getting of missing fields/attributes
319 * @param $name Name of the field/attribute
322 public final function __get (string $name) {
323 $this->debugBackTrace(sprintf('Tried to get a missing field. name=%s',
329 * Magic method to catch unsetting of missing fields/attributes
331 * @param $name Name of the field/attribute
334 public final function __unset (string $name) {
335 $this->debugBackTrace(sprintf('Tried to unset a missing field. name=%s',
341 * Magic method to catch object serialization
343 * @return $unsupported Unsupported method
344 * @throws UnsupportedOperationException Objects of this framework cannot be serialized
346 public final function __sleep () {
347 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
351 * Magic method to catch object deserialization
353 * @return $unsupported Unsupported method
354 * @throws UnsupportedOperationException Objects of this framework cannot be serialized
356 public final function __wakeup () {
357 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
361 * Magic method to catch calls when an object instance is called
363 * @return $unsupported Unsupported method
364 * @throws UnsupportedOperationException Objects of this framework cannot be serialized
366 public final function __invoke () {
367 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
371 * Setter for the real class name
373 * @param $realClass Class name (string)
376 public final function setRealClass (string $realClass) {
378 $this->realClass = $realClass;
382 * Setter for debug instance
384 * @param $debugInstance The instance for debug output class
387 public final function setDebugInstance (DebugMiddleware $debugInstance) {
388 GenericRegistry::getRegistry()->addInstance('debug', $debugInstance);
392 * Getter for debug instance
394 * @return $debugInstance Instance to class DebugConsoleOutput or DebugWebOutput
396 public final function getDebugInstance () {
397 // Get debug instance
398 $debugInstance = GenericRegistry::getRegistry()->getInstance('debug');
401 return $debugInstance;
405 * Setter for web output instance
407 * @param $webInstance The instance for web output class
410 public final function setWebOutputInstance (OutputStreamer $webInstance) {
411 GenericRegistry::getRegistry()->addInstance('web_output', $webInstance);
415 * Getter for web output instance
417 * @return $webOutputInstance - Instance to class WebOutput
419 public final function getWebOutputInstance () {
420 $webOutputInstance = GenericRegistry::getRegistry()->getInstance('web_output');
421 return $webOutputInstance;
425 * Setter for call-back instance
427 * @param $callbackInstance An instance of a FrameworkInterface class
430 public final function setCallbackInstance (FrameworkInterface $callbackInstance) {
431 $this->callbackInstance = $callbackInstance;
435 * Getter for call-back instance
437 * @return $callbackInstance An instance of a FrameworkInterface class
439 protected final function getCallbackInstance () {
440 return $this->callbackInstance;
444 * Checks whether an object equals this object. You should overwrite this
445 * method to implement own equality checks
447 * @param $objectInstance An instance of a FrameworkInterface object
448 * @return $equals Whether both objects equals
450 public function equals (FrameworkInterface $objectInstance) {
453 $this->__toString() == $objectInstance->__toString()
455 $this->hashCode() == $objectInstance->hashCode()
463 * Generates a generic hash code of this class. You should really overwrite
464 * this method with your own hash code generator code. But keep KISS in mind.
466 * @return $hashCode A generic hash code respresenting this whole class
468 public function hashCode () {
470 return crc32($this->__toString());
474 * Appends a trailing slash to a string
476 * @param $str A string (maybe) without trailing slash
477 * @return $str A string with an auto-appended trailing slash
479 public final function addMissingTrailingSlash (string $str) {
480 // Is there a trailing slash?
481 if (substr($str, -1, 1) != '/') {
485 // Return string with trailing slash
490 * Debugs this instance by putting out it's full content
492 * @param $message Optional message to show in debug output
495 public final function debugInstance (string $message = '') {
496 // Restore the error handler to avoid trouble with missing array elements or undeclared variables
497 restore_error_handler();
503 if (!empty($message)) {
505 $content = sprintf('<div class="debug_message">
507 </div>' . PHP_EOL, $message);
510 // Generate the output
511 $content .= sprintf('<pre>%s</pre>',
520 ApplicationEntryPoint::exitApplication(sprintf('<div class="debug_header">
523 <div class="debug_content">
527 <div class="debug_include_list">
532 ClassLoader::getSelfInstance()->getPrintableIncludeList()
537 * Replaces control characters with printable output
539 * @param $str String with control characters
540 * @return $str Replaced string
542 protected function replaceControlCharacters (string $str) {
545 chr(13), '[r]', str_replace(
546 chr(10), '[n]', str_replace(
556 * Output a partial stub message for the caller method
558 * @param $message An optional message to display
561 protected function partialStub (string $message = '') {
563 $stubMessage = 'Partial stub!';
565 // Is an extra message given?
566 if (!empty($message)) {
567 // Then add it as well
568 $stubMessage .= ' Message: ' . $message;
571 // Debug instance is there?
572 if (!is_null($this->getDebugInstance())) {
573 // Output stub message
574 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput($stubMessage);
577 trigger_error($stubMessage);
583 * Outputs a debug backtrace and stops further script execution
585 * @param $message An optional message to output
586 * @param $doExit Whether exit the program (true is default)
589 public function debugBackTrace (string $message = '', bool $doExit = true) {
590 // Sorry, there is no other way getting this nice backtrace
591 if (!empty($message)) {
593 printf('Message: %s<br />' . PHP_EOL, $message);
597 debug_print_backtrace();
601 if ($doExit === true) {
607 * Creates an instance of a debugger instance
609 * @param $className Name of the class (currently unsupported)
610 * @param $lineNumber Line number where the call was made
611 * @return $debugInstance An instance of a debugger class
612 * @deprecated Not fully, as the new Logger facilities are not finished yet.
614 public final static function createDebugInstance (string $className, int $lineNumber = NULL) {
615 // Validate parameter
616 if (empty($className)) {
618 throw new InvalidArgumentException('Parameter "className" is empty');
619 } elseif (!GenericRegistry::getRegistry()->instanceExists('debug')) {
620 // Init debug instance
621 $debugInstance = NULL;
625 // Get a debugger instance
626 $debugInstance = DebugMiddleware::createDebugMiddleware(FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('debug_' . FrameworkBootstrap::getRequestTypeFromSystem() . '_class'), $className);
627 } catch (NullPointerException $e) {
628 // Didn't work, no instance there
629 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));
632 // Empty string should be ignored and used for testing the middleware
633 DebugMiddleware::getSelfInstance()->output('');
635 // Set it in registry
636 GenericRegistry::getRegistry()->addInstance('debug', $debugInstance);
638 // Get instance from registry
639 $debugInstance = GenericRegistry::getRegistry()->getDebugInstance();
643 return $debugInstance;
647 * Simple output of a message with line-break
649 * @param $message Message to output
652 public function outputLine (string $message) {
654 print($message . PHP_EOL);
658 * Outputs a debug message whether to debug instance (should be set!) or
659 * dies with or ptints the message. Do NEVER EVER rewrite the exit() call to
660 * ApplicationEntryPoint::app_exit(), this would cause an endless loop.
662 * @param $message Message we shall send out...
663 * @param $doPrint Whether print or die here (default: print)
664 * @paran $stripTags Whether to strip tags (default: false)
667 public function debugOutput (string $message, bool $doPrint = true, bool $stripTags = false) {
668 // Set debug instance to NULL
669 $debugInstance = NULL;
672 $backtrace = debug_backtrace(!DEBUG_BACKTRACE_PROVIDE_OBJECT);
674 // Is function partialStub/__callStatic ?
675 if (in_array($backtrace[1]['function'], array('partialStub', '__call', '__callStatic'))) {
676 // Prepend class::function:line from 3rd element
677 $message = sprintf('[%s::%s:%d]: %s',
678 $backtrace[2]['class'],
679 $backtrace[2]['function'],
680 (isset($backtrace[2]['line']) ? $backtrace[2]['line'] : '0'),
684 // Prepend class::function:line from 2nd element
685 $message = sprintf('[%s::%s:%d]: %s',
686 $backtrace[1]['class'],
687 $backtrace[1]['function'],
688 (isset($backtrace[1]['line']) ? $backtrace[1]['line'] : '0'),
695 // Get debug instance
696 $debugInstance = $this->getDebugInstance();
697 } catch (NullPointerException $e) {
698 // The debug instance is not set (yet)
701 // Is the debug instance there?
702 if (is_object($debugInstance)) {
703 // Use debug output handler
704 $debugInstance->output($message, $stripTags);
706 if ($doPrint === false) {
707 // Die here if not printed
711 // Are debug times enabled?
712 if (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('debug_' . FrameworkBootstrap::getRequestTypeFromSystem() . '_output_timings') == 'Y') {
714 $message = $this->getPrintableExecutionTime() . $message;
718 if ($doPrint === true) {
720 $this->outputLine($message);
729 * Marks up the code by adding e.g. line numbers
731 * @param $phpCode Unmarked PHP code
732 * @return $markedCode Marked PHP code
734 public function markupCode (string $phpCode) {
739 $errorArray = error_get_last();
741 // Init the code with error message
742 if (is_array($errorArray)) {
744 $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>',
745 basename($errorArray['file']),
747 $errorArray['message'],
752 // Add line number to the code
753 foreach (explode(chr(10), $phpCode) as $lineNo => $code) {
755 $markedCode .= sprintf('<span id="code_line">%s</span>: %s' . PHP_EOL,
757 htmlentities($code, ENT_QUOTES)
766 * "Getter" for databse entry
768 * @return $entry An array with database entries
769 * @throws NullPointerException If the database result is not found
770 * @throws InvalidDatabaseResultException If the database result is invalid
771 * @todo Monolithic method, should be moved to proper classes
773 protected final function getDatabaseEntry () {
774 // Is there an instance?
775 if (!$this->getResultInstance() instanceof SearchableResult) {
776 // Throw an exception here
777 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
781 $this->getResultInstance()->rewind();
783 // Do we have an entry?
784 if ($this->getResultInstance()->valid() === false) {
785 // @TODO Move the constant to e.g. BaseDatabaseResult when there is a non-cached database result available
786 throw new InvalidDatabaseResultException(array($this, $this->getResultInstance()), CachedDatabaseResult::EXCEPTION_INVALID_DATABASE_RESULT);
790 $this->getResultInstance()->next();
793 $entry = $this->getResultInstance()->current();
800 * Getter for field name
802 * @param $fieldName Field name which we shall get
803 * @return $fieldValue Field value from the user
804 * @throws NullPointerException If the result instance is null
806 public final function getField (string $fieldName) {
807 // Default field value
810 // Get result instance
811 $resultInstance = $this->getResultInstance();
813 // Is this instance null?
814 if (is_null($resultInstance)) {
815 // Then the user instance is no longer valid (expired cookies?)
816 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
820 $fieldArray = $resultInstance->current();
821 //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput($fieldName.':<pre>'.print_r($fieldArray, true).'</pre>');
823 // Convert dashes to underscore
824 $fieldName2 = StringUtils::convertDashesToUnderscores($fieldName);
826 // Does the field exist?
827 if ($this->isFieldSet($fieldName)) {
829 $fieldValue = $fieldArray[$fieldName2];
830 } elseif (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('developer_mode_enabled')) {
831 // Missing field entry, may require debugging
832 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FRAMEWORK-SYSTEM: fieldArray<pre>=' . print_r($fieldArray, true) . '</pre>,fieldName=' . $fieldName . ' not found!');
834 // Missing field entry, may require debugging
835 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FRAMEWORK-SYSTEM: fieldName=' . $fieldName . ' not found!');
843 * Checks if given field is set
845 * @param $fieldName Field name to check
846 * @return $isSet Whether the given field name is set
847 * @throws NullPointerException If the result instance is null
849 public function isFieldSet (string $fieldName) {
850 // Get result instance
851 $resultInstance = $this->getResultInstance();
853 // Is this instance null?
854 if (is_null($resultInstance)) {
855 // Then the user instance is no longer valid (expired cookies?)
856 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
860 $fieldArray = $resultInstance->current();
861 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('[' . $this->__toString() . ':' . __LINE__ . '] fieldName=' . $fieldName . ',fieldArray=<pre>'.print_r($fieldArray, true).'</pre>');
863 // Convert dashes to underscore
864 $fieldName = StringUtils::convertDashesToUnderscores($fieldName);
867 $isSet = isset($fieldArray[$fieldName]);
874 * Outputs a deprecation warning to the developer.
876 * @param $message The message we shall output to the developer
878 * @todo Write a logging mechanism for productive mode
880 public function deprecationWarning (string $message) {
881 // Is developer mode active?
882 if (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('developer_mode_enabled')) {
883 // Debug instance is there?
884 if (!is_null($this->getDebugInstance())) {
885 // Output stub message
886 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput($message);
889 trigger_error($message . "<br />\n");
893 // @TODO Finish this part!
894 $this->partialStub('Developer mode inactive. Message:' . $message);
899 * Checks whether the given PHP extension is loaded
901 * @param $phpExtension The PHP extension we shall check
902 * @return $isLoaded Whether the PHP extension is loaded
904 public final function isPhpExtensionLoaded (string $phpExtension) {
906 $isLoaded = in_array($phpExtension, get_loaded_extensions());
913 * "Getter" as a time() replacement but with milliseconds. You should use this
914 * method instead of the encapsulated getimeofday() function.
916 * @return $milliTime Timestamp with milliseconds
918 public function getMilliTime () {
919 // Get the time of day as float
920 $milliTime = gettimeofday(true);
927 * Idles (sleeps) for given milliseconds
929 * @return $hasSlept Whether it goes fine
931 public function idle (int $milliSeconds) {
932 // Sleep is fine by default
935 // Idle so long with found function
936 if (function_exists('time_sleep_until')) {
937 // Get current time and add idle time
938 $sleepUntil = $this->getMilliTime() + abs($milliSeconds) / 1000;
940 // New PHP 5.1.0 function found, ignore errors
941 $hasSlept = @time_sleep_until($sleepUntil);
944 * My Sun station doesn't have that function even with latest PHP
947 usleep($milliSeconds * 1000);
955 * Checks whether the given encoded data was encoded with Base64
957 * @param $encodedData Encoded data we shall check
958 * @return $isBase64 Whether the encoded data is Base64
960 protected function isBase64Encoded (string $encodedData) {
962 $isBase64 = (@base64_decode($encodedData, true) !== false);
969 * Getter for startup time in miliseconds
971 * @return $startupTime Startup time in miliseconds
973 protected function getStartupTime () {
974 return self::$startupTime;
978 * "Getter" for a printable currently execution time in nice braces
980 * @return $executionTime Current execution time in nice braces
982 protected function getPrintableExecutionTime () {
983 // Calculate execution time and pack it in nice braces
984 $executionTime = sprintf('[ %01.5f ] ', (microtime(true) - $this->getStartupTime()));
987 return $executionTime;
991 * Determines if an element is set in the generic array
993 * @param $keyGroup Main group for the key
994 * @param $subGroup Sub group for the key
995 * @param $key Key to check
996 * @param $element Element to check
997 * @return $isset Whether the given key is set
999 protected final function isGenericArrayElementSet (string $keyGroup, string $subGroup, $key, $element) {
1001 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element);
1002 $isset = isset($this->genericArray[$keyGroup][$subGroup][$key][$element]);
1008 * Determines if a key is set in the generic array
1010 * @param $keyGroup Main group for the key
1011 * @param $subGroup Sub group for the key
1012 * @param $key Key to check
1013 * @return $isset Whether the given key is set
1015 protected final function isGenericArrayKeySet (string $keyGroup, string $subGroup, $key) {
1017 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1018 $isset = isset($this->genericArray[$keyGroup][$subGroup][$key]);
1026 * Determines if a group is set in the generic array
1028 * @param $keyGroup Main group
1029 * @param $subGroup Sub group
1030 * @return $isset Whether the given group is set
1032 protected final function isGenericArrayGroupSet (string $keyGroup, string $subGroup) {
1034 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup);
1035 $isset = isset($this->genericArray[$keyGroup][$subGroup]);
1042 * Getter for sub key group
1044 * @param $keyGroup Main key group
1045 * @param $subGroup Sub key group
1046 * @return $array An array with all array elements
1048 protected final function getGenericSubArray (string $keyGroup, string $subGroup) {
1050 if (!$this->isGenericArrayGroupSet($keyGroup, $subGroup)) {
1051 // No, then abort here
1052 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' not found.');
1057 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',value=' . print_r($this->genericArray[$keyGroup][$subGroup], true));
1058 return $this->genericArray[$keyGroup][$subGroup];
1062 * Unsets a given key in generic array
1064 * @param $keyGroup Main group for the key
1065 * @param $subGroup Sub group for the key
1066 * @param $key Key to unset
1069 protected final function unsetGenericArrayKey (string $keyGroup, string $subGroup, $key) {
1071 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1072 unset($this->genericArray[$keyGroup][$subGroup][$key]);
1076 * Unsets a given element in generic array
1078 * @param $keyGroup Main group for the key
1079 * @param $subGroup Sub group for the key
1080 * @param $key Key to unset
1081 * @param $element Element to unset
1084 protected final function unsetGenericArrayElement (string $keyGroup, string $subGroup, $key, $element) {
1086 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element);
1089 unset($this->genericArray[$keyGroup][$subGroup][$key][$element]);
1093 * Append a string to a given generic array key
1095 * @param $keyGroup Main group for the key
1096 * @param $subGroup Sub group for the key
1097 * @param $key Key to unset
1098 * @param $value Value to add/append
1101 protected final function appendStringToGenericArrayKey (string $keyGroup, string $subGroup, $key, string $value, $appendGlue = '') {
1103 //* 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);
1105 // Is it already there?
1106 if ($this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
1108 $this->genericArray[$keyGroup][$subGroup][$key] .= $appendGlue . (string) $value;
1111 $this->genericArray[$keyGroup][$subGroup][$key] = (string) $value;
1116 * Append a string to a given generic array element
1118 * @param $keyGroup Main group for the key
1119 * @param $subGroup Sub group for the key
1120 * @param $key Key to unset
1121 * @param $element Element to check
1122 * @param $value Value to add/append
1125 protected final function appendStringToGenericArrayElement (string $keyGroup, string $subGroup, $key, $element, $value, $appendGlue = '') {
1127 //* 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);
1129 // Is it already there?
1130 if ($this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element)) {
1132 $this->genericArray[$keyGroup][$subGroup][$key][$element] .= $appendGlue . (string) $value;
1135 $this->setStringGenericArrayElement($keyGroup, $subGroup, $key, $element, $value);
1140 * Sets a string in a given generic array element
1142 * @param $keyGroup Main group for the key
1143 * @param $subGroup Sub group for the key
1144 * @param $key Key to unset
1145 * @param $element Element to check
1146 * @param $value Value to add/append
1149 protected final function setStringGenericArrayElement (string $keyGroup, string $subGroup, $key, $element, $value, $appendGlue = '') {
1151 //* 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);
1154 $this->genericArray[$keyGroup][$subGroup][$key][$element] = (string) $value;
1158 * Initializes given generic array group
1160 * @param $keyGroup Main group for the key
1161 * @param $subGroup Sub group for the key
1162 * @param $key Key to use
1163 * @param $forceInit Optionally force initialization
1166 protected final function initGenericArrayGroup (string $keyGroup, string $subGroup, bool $forceInit = false) {
1168 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',forceInit=' . intval($forceInit));
1170 // Is it already set?
1171 if (($forceInit === false) && ($this->isGenericArrayGroupSet($keyGroup, $subGroup))) {
1172 // Already initialized
1173 trigger_error(__METHOD__ . ':keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' already initialized.');
1178 $this->genericArray[$keyGroup][$subGroup] = [];
1182 * Initializes given generic array key
1184 * @param $keyGroup Main group for the key
1185 * @param $subGroup Sub group for the key
1186 * @param $key Key to use
1187 * @param $forceInit Optionally force initialization
1190 protected final function initGenericArrayKey (string $keyGroup, string $subGroup, $key, bool $forceInit = false) {
1192 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',forceInit=' . intval($forceInit));
1194 // Is it already set?
1195 if (($forceInit === false) && ($this->isGenericArrayKeySet($keyGroup, $subGroup, $key))) {
1196 // Already initialized
1197 trigger_error(__METHOD__ . ':keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' already initialized.');
1202 $this->genericArray[$keyGroup][$subGroup][$key] = [];
1206 * Initializes given generic array element
1208 * @param $keyGroup Main group for the key
1209 * @param $subGroup Sub group for the key
1210 * @param $key Key to use
1211 * @param $element Element to use
1212 * @param $forceInit Optionally force initialization
1215 protected final function initGenericArrayElement (string $keyGroup, string $subGroup, $key, $element, bool $forceInit = false) {
1217 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element . ',forceInit=' . intval($forceInit));
1219 // Is it already set?
1220 if (($forceInit === false) && ($this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element))) {
1221 // Already initialized
1222 trigger_error(__METHOD__ . ':keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element . ' already initialized.');
1227 $this->genericArray[$keyGroup][$subGroup][$key][$element] = [];
1231 * Pushes an element to a generic key
1233 * @param $keyGroup Main group for the key
1234 * @param $subGroup Sub group for the key
1235 * @param $key Key to use
1236 * @param $value Value to add/append
1237 * @return $count Number of array elements
1239 protected final function pushValueToGenericArrayKey (string $keyGroup, string $subGroup, $key, $value) {
1241 //* NOISY-DEBUG: */ if (!is_object($value)) $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',value[' . gettype($value) . ']=' . print_r($value, true));
1244 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
1246 $this->initGenericArrayKey($keyGroup, $subGroup, $key);
1250 $count = array_push($this->genericArray[$keyGroup][$subGroup][$key], $value);
1253 //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], true));
1254 //* DEBUG: */ print(__METHOD__ . ': count=' . $count . PHP_EOL);
1259 * Pushes an element to a generic array element
1261 * @param $keyGroup Main group for the key
1262 * @param $subGroup Sub group for the key
1263 * @param $key Key to use
1264 * @param $element Element to check
1265 * @param $value Value to add/append
1266 * @return $count Number of array elements
1268 protected final function pushValueToGenericArrayElement (string $keyGroup, string $subGroup, $key, $element, $value) {
1270 //* 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));
1273 if (!$this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element)) {
1275 $this->initGenericArrayElement($keyGroup, $subGroup, $key, $element);
1279 $count = array_push($this->genericArray[$keyGroup][$subGroup][$key][$element], $value);
1282 //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], true));
1283 //* DEBUG: */ print(__METHOD__ . ': count=' . $count . PHP_EOL);
1288 * Pops an element from a generic group
1290 * @param $keyGroup Main group for the key
1291 * @param $subGroup Sub group for the key
1292 * @param $key Key to unset
1293 * @return $value Last "popped" value
1295 protected final function popGenericArrayElement (string $keyGroup, string $subGroup, $key) {
1297 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1300 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
1302 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' not found.');
1307 $value = array_pop($this->genericArray[$keyGroup][$subGroup][$key]);
1310 //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], true));
1311 //* DEBUG: */ print(__METHOD__ . ': value[' . gettype($value) . ']=' . print_r($value, true) . PHP_EOL);
1316 * Shifts an element from a generic group
1318 * @param $keyGroup Main group for the key
1319 * @param $subGroup Sub group for the key
1320 * @param $key Key to unset
1321 * @return $value Last "popped" value
1323 protected final function shiftGenericArrayElement (string $keyGroup, string $subGroup, $key) {
1325 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1328 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
1330 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' not found.');
1335 $value = array_shift($this->genericArray[$keyGroup][$subGroup][$key]);
1338 //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], true));
1339 //* DEBUG: */ print(__METHOD__ . ': value[' . gettype($value) . ']=' . print_r($value, true) . PHP_EOL);
1344 * Count generic array group
1346 * @param $keyGroup Main group for the key
1347 * @return $count Count of given group
1349 protected final function countGenericArray ($keyGroup) {
1351 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup);
1354 if (!isset($this->genericArray[$keyGroup])) {
1356 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ' not found.');
1361 $count = count($this->genericArray[$keyGroup]);
1364 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',count=' . $count);
1371 * Count generic array sub group
1373 * @param $keyGroup Main group for the key
1374 * @param $subGroup Sub group for the key
1375 * @return $count Count of given group
1377 protected final function countGenericArrayGroup (string $keyGroup, string $subGroup) {
1379 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup);
1382 if (!$this->isGenericArrayGroupSet($keyGroup, $subGroup)) {
1384 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' not found.');
1389 $count = count($this->genericArray[$keyGroup][$subGroup]);
1392 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',count=' . $count);
1399 * Count generic array elements
1401 * @param $keyGroup Main group for the key
1402 * @param $subGroup Sub group for the key
1403 * @para $key Key to count
1404 * @return $count Count of given key
1406 protected final function countGenericArrayElements (string $keyGroup, string $subGroup, $key) {
1408 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1411 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
1413 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' not found.');
1415 } elseif (!$this->isValidGenericArrayGroup($keyGroup, $subGroup)) {
1417 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' is not an array.');
1422 $count = count($this->genericArray[$keyGroup][$subGroup][$key]);
1425 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',count=' . $count);
1432 * Getter for whole generic group array
1434 * @param $keyGroup Key group to get
1435 * @return $array Whole generic array group
1437 protected final function getGenericArray ($keyGroup) {
1439 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup);
1442 if (!isset($this->genericArray[$keyGroup])) {
1444 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ' does not exist.');
1449 return $this->genericArray[$keyGroup];
1453 * Setter for generic array key
1455 * @param $keyGroup Key group to get
1456 * @param $subGroup Sub group for the key
1457 * @param $key Key to unset
1458 * @param $value Mixed value from generic array element
1461 protected final function setGenericArrayKey (string $keyGroup, string $subGroup, $key, $value) {
1463 //* NOISY-DEBUG: */ if (!is_object($value)) $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',value[' . gettype($value) . ']=' . print_r($value, true));
1466 $this->genericArray[$keyGroup][$subGroup][$key] = $value;
1470 * Getter for generic array key
1472 * @param $keyGroup Key group to get
1473 * @param $subGroup Sub group for the key
1474 * @param $key Key to unset
1475 * @return $value Mixed value from generic array element
1477 protected final function getGenericArrayKey (string $keyGroup, string $subGroup, $key) {
1479 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1482 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
1484 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' does not exist.');
1489 return $this->genericArray[$keyGroup][$subGroup][$key];
1493 * Sets a value in given generic array key/element
1495 * @param $keyGroup Main group for the key
1496 * @param $subGroup Sub group for the key
1497 * @param $key Key to set
1498 * @param $element Element to set
1499 * @param $value Value to set
1502 protected final function setGenericArrayElement (string $keyGroup, string $subGroup, $key, $element, $value) {
1504 //* 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));
1507 $this->genericArray[$keyGroup][$subGroup][$key][$element] = $value;
1511 * Getter for generic array element
1513 * @param $keyGroup Key group to get
1514 * @param $subGroup Sub group for the key
1515 * @param $key Key to look for
1516 * @param $element Element to look for
1517 * @return $value Mixed value from generic array element
1519 protected final function getGenericArrayElement (string $keyGroup, string $subGroup, $key, $element) {
1521 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element);
1524 if (!$this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element)) {
1526 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element . ' does not exist.');
1531 return $this->genericArray[$keyGroup][$subGroup][$key][$element];
1535 * Checks if a given sub group is valid (array)
1537 * @param $keyGroup Key group to get
1538 * @param $subGroup Sub group for the key
1539 * @return $isValid Whether given sub group is valid
1541 protected final function isValidGenericArrayGroup (string $keyGroup, string $subGroup) {
1543 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup);
1546 $isValid = (($this->isGenericArrayGroupSet($keyGroup, $subGroup)) && (is_array($this->getGenericSubArray($keyGroup, $subGroup))));
1553 * Checks if a given key is valid (array)
1555 * @param $keyGroup Key group to get
1556 * @param $subGroup Sub group for the key
1557 * @param $key Key to check
1558 * @return $isValid Whether given sub group is valid
1560 protected final function isValidGenericArrayKey (string $keyGroup, string $subGroup, $key) {
1562 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1565 $isValid = (($this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) && (is_array($this->getGenericArrayKey($keyGroup, $subGroup, $key))));
1572 * Initializes the web output instance
1576 protected function initWebOutputInstance () {
1577 // Init web output instance
1578 $outputInstance = ObjectFactory::createObjectByConfiguredName('output_class');
1581 $this->setWebOutputInstance($outputInstance);
1585 * Translates boolean true to 'Y' and false to 'N'
1587 * @param $boolean Boolean value
1588 * @return $translated Translated boolean value
1590 public static final function translateBooleanToYesNo (bool $boolean) {
1591 // Make sure it is really boolean
1592 assert(is_bool($boolean));
1595 $translated = ($boolean === true) ? 'Y' : 'N';
1597 // ... and return it
1602 * Creates a full-qualified file name (FQFN) for given file name by adding
1603 * a configured temporary file path to it.
1605 * @param $infoInstance An instance of a SplFileInfo class
1606 * @return $tempInstance An instance of a SplFileInfo class (temporary file)
1607 * @throw PathWriteProtectedException If the path in 'temp_file_path' is write-protected
1608 * @throws FileIoException If the file cannot be written
1610 protected static function createTempPathForFile (SplFileInfo $infoInstance) {
1612 $basePath = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('temp_file_path');
1614 // Is the path writeable?
1615 if (!is_writable($basePath)) {
1616 // Path is write-protected
1617 throw new PathWriteProtectedException($infoInstance, self::EXCEPTION_PATH_CANNOT_BE_WRITTEN);
1621 $tempInstance = new SplFileInfo($basePath . DIRECTORY_SEPARATOR . $infoInstance->getBasename());
1624 if (!FrameworkBootstrap::isReachableFilePath($tempInstance)) {
1626 throw new FileIoException($tempInstance, self::EXCEPTION_FILE_NOT_REACHABLE);
1630 return $tempInstance;
1634 * "Getter" for a printable state name
1636 * @return $stateName Name of the node's state in a printable format
1637 * @todo Move this class away from this monolithic place (not whole class is monolithic)
1639 public final function getPrintableState () {
1640 // Default is 'null'
1641 $stateName = 'null';
1643 // Get the state instance
1644 $stateInstance = $this->getStateInstance();
1646 // Is it an instance of Stateable?
1647 if ($stateInstance instanceof Stateable) {
1648 // Then use that state name
1649 $stateName = $stateInstance->getStateName();