3 namespace Org\Mxchange\CoreFramework\Object;
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
7 use Org\Mxchange\CoreFramework\Criteria\Criteria;
8 use Org\Mxchange\CoreFramework\EntryPoint\ApplicationEntryPoint;
9 use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory;
10 use Org\Mxchange\CoreFramework\Filesystem\PathWriteProtectedException;
11 use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
12 use Org\Mxchange\CoreFramework\Generic\NullPointerException;
13 use Org\Mxchange\CoreFramework\Generic\UnsupportedOperationException;
14 use Org\Mxchange\CoreFramework\Helper\Application\ApplicationHelper;
15 use Org\Mxchange\CoreFramework\Loader\ClassLoader;
16 use Org\Mxchange\CoreFramework\Manager\ManageableApplication;
17 use Org\Mxchange\CoreFramework\Middleware\Debug\DebugMiddleware;
18 use Org\Mxchange\CoreFramework\Registry\GenericRegistry;
19 use Org\Mxchange\CoreFramework\Result\Database\CachedDatabaseResult;
20 use Org\Mxchange\CoreFramework\State\Stateable;
21 use Org\Mxchange\CoreFramework\Stream\Output\OutputStreamer;
22 use Org\Mxchange\CoreFramework\Utils\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 $realClass = __CLASS__;
67 private $callbackInstance = NULL;
72 private $genericArray = [];
74 /***********************
75 * Exception codes.... *
76 ***********************/
78 // @todo Try to clean these constants up
79 const EXCEPTION_IS_NULL_POINTER = 0x001;
80 const EXCEPTION_IS_NO_OBJECT = 0x002;
81 const EXCEPTION_IS_NO_ARRAY = 0x003;
82 const EXCEPTION_MISSING_METHOD = 0x004;
83 const EXCEPTION_CLASSES_NOT_MATCHING = 0x005;
84 const EXCEPTION_INDEX_OUT_OF_BOUNDS = 0x006;
85 const EXCEPTION_DIMENSION_ARRAY_INVALID = 0x007;
86 const EXCEPTION_ITEM_NOT_TRADEABLE = 0x008;
87 const EXCEPTION_ITEM_NOT_IN_PRICE_LIST = 0x009;
88 const EXCEPTION_GENDER_IS_WRONG = 0x00a;
89 const EXCEPTION_BIRTH_DATE_IS_INVALID = 0x00b;
90 const EXCEPTION_EMPTY_STRUCTURES_ARRAY = 0x00c;
91 const EXCEPTION_HAS_ALREADY_PERSONELL_LIST = 0x00d;
92 const EXCEPTION_NOT_ENOUGTH_UNEMPLOYEES = 0x00e;
93 const EXCEPTION_TOTAL_PRICE_NOT_CALCULATED = 0x00f;
94 const EXCEPTION_HARBOR_HAS_NO_SHIPYARDS = 0x010;
95 const EXCEPTION_CONTRACT_PARTNER_INVALID = 0x011;
96 const EXCEPTION_CONTRACT_PARTNER_MISMATCH = 0x012;
97 const EXCEPTION_CONTRACT_ALREADY_SIGNED = 0x013;
98 const EXCEPTION_UNEXPECTED_EMPTY_STRING = 0x014;
99 const EXCEPTION_PATH_NOT_FOUND = 0x015;
100 const EXCEPTION_INVALID_PATH_NAME = 0x016;
101 const EXCEPTION_READ_PROTECED_PATH = 0x017;
102 const EXCEPTION_WRITE_PROTECED_PATH = 0x018;
103 const EXCEPTION_DIR_POINTER_INVALID = 0x019;
104 const EXCEPTION_FILE_POINTER_INVALID = 0x01a;
105 const EXCEPTION_INVALID_RESOURCE = 0x01b;
106 const EXCEPTION_UNEXPECTED_OBJECT = 0x01c;
107 const EXCEPTION_LIMIT_ELEMENT_IS_UNSUPPORTED = 0x01d;
108 const EXCEPTION_GETTER_IS_MISSING = 0x01e;
109 const EXCEPTION_ARRAY_EXPECTED = 0x01f;
110 const EXCEPTION_ARRAY_HAS_INVALID_COUNT = 0x020;
111 const EXCEPTION_ID_IS_INVALID_FORMAT = 0x021;
112 const EXCEPTION_MD5_CHECKSUMS_MISMATCH = 0x022;
113 const EXCEPTION_UNEXPECTED_STRING_SIZE = 0x023;
114 const EXCEPTION_SIMULATOR_ID_INVALID = 0x024;
115 const EXCEPTION_MISMATCHING_COMPRESSORS = 0x025;
116 const EXCEPTION_CONTAINER_ITEM_IS_NULL = 0x026;
117 const EXCEPTION_ITEM_IS_NO_ARRAY = 0x027;
118 const EXCEPTION_CONTAINER_MAYBE_DAMAGED = 0x028;
119 const EXCEPTION_INVALID_STRING = 0x029;
120 const EXCEPTION_VARIABLE_NOT_SET = 0x02a;
121 const EXCEPTION_ATTRIBUTES_ARE_MISSING = 0x02b;
122 const EXCEPTION_ARRAY_ELEMENTS_MISSING = 0x02c;
123 const EXCEPTION_TEMPLATE_ENGINE_UNSUPPORTED = 0x02d;
124 const EXCEPTION_UNSPPORTED_OPERATION = 0x02e;
125 const EXCEPTION_FACTORY_REQUIRE_PARAMETER = 0x02f;
126 const EXCEPTION_MISSING_ELEMENT = 0x030;
127 const EXCEPTION_HEADERS_ALREADY_SENT = 0x031;
128 const EXCEPTION_DEFAULT_CONTROLLER_GONE = 0x032;
129 const EXCEPTION_CLASS_NOT_FOUND = 0x033;
130 const EXCEPTION_REQUIRED_INTERFACE_MISSING = 0x034;
131 const EXCEPTION_FATAL_ERROR = 0x035;
132 const EXCEPTION_FILE_NOT_FOUND = 0x036;
133 const EXCEPTION_ASSERTION_FAILED = 0x037;
134 const EXCEPTION_FILE_NOT_REACHABLE = 0x038;
135 const EXCEPTION_FILE_CANNOT_BE_READ = 0x039;
136 const EXCEPTION_FILE_CANNOT_BE_WRITTEN = 0x03a;
137 const EXCEPTION_PATH_CANNOT_BE_WRITTEN = 0x03b;
138 const EXCEPTION_DATABASE_UPDATED_NOT_ALLOWED = 0x03c;
139 const EXCEPTION_FILTER_CHAIN_INTERCEPTED = 0x03d;
140 const EXCEPTION_INVALID_SOCKET = 0x03e;
141 const EXCEPTION_SELF_INSTANCE = 0x03f;
144 * Startup time in miliseconds
146 private static $startupTime = 0;
149 * Protected super constructor
151 * @param $className Name of the class
154 protected function __construct (string $className) {
156 $this->setRealClass($className);
158 // Is the startup time set? (0 cannot be true anymore)
159 if (self::$startupTime == 0) {
161 self::$startupTime = microtime(true);
166 * Destructor for all classes. You should not call this method on your own.
170 public function __destruct () {
171 // Is this object already destroyed?
172 if ($this->__toString() != 'DestructedObject') {
173 // Destroy all informations about this class but keep some text about it alive
174 $this->setRealClass('DestructedObject');
175 } elseif ((defined('DEBUG_DESTRUCTOR')) && (is_object($this->getDebugInstance()))) {
176 // Already destructed object
177 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('The object <span class="object_name">%s</span> is already destroyed.',
181 // Do not call this twice
182 trigger_error(__METHOD__ . ': Called twice.');
188 * The __call() method where all non-implemented methods end up
190 * @param $methodName Name of the missing method
191 * @args $args Arguments passed to the method
194 public final function __call (string $methodName, array $args = NULL) {
196 self::$selfInstance = $this;
198 // Call static method
199 self::__callStatic($methodName, $args);
201 // Clear self-instance
202 self::$selfInstance = NULL;
206 * The __callStatic() method where all non-implemented static methods end up
208 * @param $methodName Name of the missing method
209 * @param $args Arguments passed to the method
211 * @throws InvalidArgumentException If self::$selfInstance is not a framework's own object
213 public static final function __callStatic (string $methodName, array $args = NULL) {
214 // Init argument string and class name
215 //* PRINT-DEBUG: */ printf('[%s:%d]: methodName=%s,args[]=%s - CALLED!' . PHP_EOL, __METHOD__, __LINE__, $methodName, gettype($args));
217 $className = 'unknown';
219 // Is self-instance set?
220 if (self::$selfInstance instanceof FrameworkInterface) {
221 // Framework's own instance
222 $className = self::$selfInstance->__toString();
223 } elseif (!is_null(self::$selfInstance)) {
225 throw new InvalidArgumentException(sprintf('self::instance[%s] is not expected.', gettype(self::$selfInstance)), self::EXCEPTION_SELF_INSTANCE);
228 // Is it NULL, empty or an array?
229 if (is_null($args)) {
231 $argsString = 'NULL';
232 } elseif (is_array($args)) {
236 // Some arguments are there
237 foreach ($args as $arg) {
238 // Add data about the argument
239 $argsString .= gettype($arg) . ':';
242 // Found a NULL argument
243 $argsString .= 'NULL';
244 } elseif (is_string($arg)) {
245 // Add length for strings
246 $argsString .= strlen($arg);
247 } elseif ((is_int($arg)) || (is_float($arg))) {
250 } elseif (is_array($arg)) {
251 // .. or size if array
252 $argsString .= count($arg);
253 } elseif (is_object($arg)) {
255 $reflection = new ReflectionClass($arg);
257 // Is an other object, maybe no __toString() available
258 $argsString .= $reflection->getName();
259 } elseif ($arg === true) {
260 // ... is boolean 'true'
261 $argsString .= 'true';
262 } elseif ($arg === false) {
263 // ... is boolean 'false'
264 $argsString .= 'false';
267 // Comma for next one
272 if (substr($argsString, -2, 1) == ',') {
274 $argsString = substr($argsString, 0, -2);
281 // Output stub message
282 // @TODO __CLASS__ does always return BaseFrameworkSystem but not the extending (=child) class
283 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s::%s]: Stub! Args: %s',
294 * Getter for $realClass
296 * @return $realClass The name of the real class (not BaseFrameworkSystem)
298 public function __toString () {
299 return $this->realClass;
303 * Magic method to catch setting of missing but set class fields/attributes
305 * @param $name Name of the field/attribute
306 * @param $value Value to store
309 public final function __set (string $name, $value) {
310 $this->debugBackTrace(sprintf('Tried to set a missing field. name=%s, value[%s]=%s',
313 print_r($value, true)
318 * Magic method to catch getting of missing fields/attributes
320 * @param $name Name of the field/attribute
323 public final function __get (string $name) {
324 $this->debugBackTrace(sprintf('Tried to get a missing field. name=%s',
330 * Magic method to catch unsetting of missing fields/attributes
332 * @param $name Name of the field/attribute
335 public final function __unset (string $name) {
336 $this->debugBackTrace(sprintf('Tried to unset a missing field. name=%s',
342 * Magic method to catch object serialization
344 * @return $unsupported Unsupported method
345 * @throws UnsupportedOperationException Objects of this framework cannot be serialized
347 public final function __sleep () {
348 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
352 * Magic method to catch object deserialization
354 * @return $unsupported Unsupported method
355 * @throws UnsupportedOperationException Objects of this framework cannot be serialized
357 public final function __wakeup () {
358 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
362 * Magic method to catch calls when an object instance is called
364 * @return $unsupported Unsupported method
365 * @throws UnsupportedOperationException Objects of this framework cannot be serialized
367 public final function __invoke () {
368 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
372 * Setter for the real class name
374 * @param $realClass Class name (string)
377 public final function setRealClass (string $realClass) {
379 $this->realClass = $realClass;
383 * Setter for debug instance
385 * @param $debugInstance The instance for debug output class
388 public final function setDebugInstance (DebugMiddleware $debugInstance) {
389 GenericRegistry::getRegistry()->addInstance('debug', $debugInstance);
393 * Getter for debug instance
395 * @return $debugInstance Instance to class DebugConsoleOutput or DebugWebOutput
397 public final function getDebugInstance () {
398 // Get debug instance
399 $debugInstance = GenericRegistry::getRegistry()->getInstance('debug');
402 return $debugInstance;
406 * Setter for web output instance
408 * @param $webInstance The instance for web output class
411 public final function setWebOutputInstance (OutputStreamer $webInstance) {
412 GenericRegistry::getRegistry()->addInstance('web_output', $webInstance);
416 * Getter for web output instance
418 * @return $webOutputInstance - Instance to class WebOutput
420 public final function getWebOutputInstance () {
421 $webOutputInstance = GenericRegistry::getRegistry()->getInstance('web_output');
422 return $webOutputInstance;
426 * Setter for call-back instance
428 * @param $callbackInstance An instance of a FrameworkInterface class
431 public final function setCallbackInstance (FrameworkInterface $callbackInstance) {
432 $this->callbackInstance = $callbackInstance;
436 * Getter for call-back instance
438 * @return $callbackInstance An instance of a FrameworkInterface class
440 protected final function getCallbackInstance () {
441 return $this->callbackInstance;
445 * Checks whether an object equals this object. You should overwrite this
446 * method to implement own equality checks
448 * @param $objectInstance An instance of a FrameworkInterface object
449 * @return $equals Whether both objects equals
451 public function equals (FrameworkInterface $objectInstance) {
454 $this->__toString() == $objectInstance->__toString()
456 $this->hashCode() == $objectInstance->hashCode()
464 * Generates a generic hash code of this class. You should really overwrite
465 * this method with your own hash code generator code. But keep KISS in mind.
467 * @return $hashCode A generic hash code respresenting this whole class
469 public function hashCode () {
471 return crc32($this->__toString());
475 * Appends a trailing slash to a string
477 * @param $str A string (maybe) without trailing slash
478 * @return $str A string with an auto-appended trailing slash
480 public final function addMissingTrailingSlash (string $str) {
481 // Is there a trailing slash?
482 if (substr($str, -1, 1) != '/') {
486 // Return string with trailing slash
491 * Debugs this instance by putting out it's full content
493 * @param $message Optional message to show in debug output
496 public final function debugInstance (string $message = '') {
497 // Restore the error handler to avoid trouble with missing array elements or undeclared variables
498 restore_error_handler();
504 if (!empty($message)) {
506 $content = sprintf('<div class="debug_message">
508 </div>' . PHP_EOL, $message);
511 // Generate the output
512 $content .= sprintf('<pre>%s</pre>',
521 ApplicationEntryPoint::exitApplication(sprintf('<div class="debug_header">
524 <div class="debug_content">
528 <div class="debug_include_list">
533 ClassLoader::getSelfInstance()->getPrintableIncludeList()
538 * Replaces control characters with printable output
540 * @param $str String with control characters
541 * @return $str Replaced string
543 protected function replaceControlCharacters (string $str) {
546 chr(13), '[r]', str_replace(
547 chr(10), '[n]', str_replace(
557 * Output a partial stub message for the caller method
559 * @param $message An optional message to display
562 protected function partialStub (string $message = '') {
564 $stubMessage = 'Partial stub!';
566 // Is an extra message given?
567 if (!empty($message)) {
568 // Then add it as well
569 $stubMessage .= ' Message: ' . $message;
572 // Debug instance is there?
573 if (!is_null($this->getDebugInstance())) {
574 // Output stub message
575 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput($stubMessage);
578 trigger_error($stubMessage);
584 * Outputs a debug backtrace and stops further script execution
586 * @param $message An optional message to output
587 * @param $doExit Whether exit the program (true is default)
590 public function debugBackTrace (string $message = '', bool $doExit = true) {
591 // Sorry, there is no other way getting this nice backtrace
592 if (!empty($message)) {
594 printf('Message: %s<br />' . PHP_EOL, $message);
598 debug_print_backtrace();
602 if ($doExit === true) {
608 * Creates an instance of a debugger instance
610 * @param $className Name of the class (currently unsupported)
611 * @param $lineNumber Line number where the call was made
612 * @return $debugInstance An instance of a debugger class
613 * @deprecated Not fully, as the new Logger facilities are not finished yet.
615 public final static function createDebugInstance (string $className, int $lineNumber = NULL) {
616 // Validate parameter
617 if (empty($className)) {
619 throw new InvalidArgumentException('Parameter "className" is empty');
620 } elseif (!GenericRegistry::getRegistry()->instanceExists('debug')) {
621 // Init debug instance
622 $debugInstance = NULL;
626 // Get a debugger instance
627 $debugInstance = DebugMiddleware::createDebugMiddleware(FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('debug_' . FrameworkBootstrap::getRequestTypeFromSystem() . '_class'), $className);
628 } catch (NullPointerException $e) {
629 // Didn't work, no instance there
630 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));
633 // Empty string should be ignored and used for testing the middleware
634 DebugMiddleware::getSelfInstance()->output('');
636 // Set it in registry
637 GenericRegistry::getRegistry()->addInstance('debug', $debugInstance);
639 // Get instance from registry
640 $debugInstance = GenericRegistry::getRegistry()->getDebugInstance();
644 return $debugInstance;
648 * Simple output of a message with line-break
650 * @param $message Message to output
653 public function outputLine (string $message) {
655 print($message . PHP_EOL);
659 * Outputs a debug message whether to debug instance (should be set!) or
660 * dies with or ptints the message. Do NEVER EVER rewrite the exit() call to
661 * ApplicationEntryPoint::app_exit(), this would cause an endless loop.
663 * @param $message Message we shall send out...
664 * @param $doPrint Whether print or die here (default: print)
665 * @paran $stripTags Whether to strip tags (default: false)
668 public function debugOutput (string $message, bool $doPrint = true, bool $stripTags = false) {
669 // Set debug instance to NULL
670 $debugInstance = NULL;
673 $backtrace = debug_backtrace(!DEBUG_BACKTRACE_PROVIDE_OBJECT);
675 // Is function partialStub/__callStatic ?
676 if (in_array($backtrace[1]['function'], array('partialStub', '__call', '__callStatic'))) {
677 // Prepend class::function:line from 3rd element
678 $message = sprintf('[%s::%s:%d]: %s',
679 $backtrace[2]['class'],
680 $backtrace[2]['function'],
681 (isset($backtrace[2]['line']) ? $backtrace[2]['line'] : '0'),
685 // Prepend class::function:line from 2nd element
686 $message = sprintf('[%s::%s:%d]: %s',
687 $backtrace[1]['class'],
688 $backtrace[1]['function'],
689 (isset($backtrace[1]['line']) ? $backtrace[1]['line'] : '0'),
696 // Get debug instance
697 $debugInstance = $this->getDebugInstance();
698 } catch (NullPointerException $e) {
699 // The debug instance is not set (yet)
702 // Is the debug instance there?
703 if (is_object($debugInstance)) {
704 // Use debug output handler
705 $debugInstance->output($message, $stripTags);
707 if ($doPrint === false) {
708 // Die here if not printed
712 // Are debug times enabled?
713 if (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('debug_' . FrameworkBootstrap::getRequestTypeFromSystem() . '_output_timings') == 'Y') {
715 $message = $this->getPrintableExecutionTime() . $message;
719 if ($doPrint === true) {
721 $this->outputLine($message);
730 * Marks up the code by adding e.g. line numbers
732 * @param $phpCode Unmarked PHP code
733 * @return $markedCode Marked PHP code
735 public function markupCode (string $phpCode) {
740 $errorArray = error_get_last();
742 // Init the code with error message
743 if (is_array($errorArray)) {
745 $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>',
746 basename($errorArray['file']),
748 $errorArray['message'],
753 // Add line number to the code
754 foreach (explode(chr(10), $phpCode) as $lineNo => $code) {
756 $markedCode .= sprintf('<span id="code_line">%s</span>: %s' . PHP_EOL,
758 htmlentities($code, ENT_QUOTES)
767 * "Getter" for databse entry
769 * @return $entry An array with database entries
770 * @throws NullPointerException If the database result is not found
771 * @throws InvalidDatabaseResultException If the database result is invalid
772 * @todo Monolithic method, should be moved to proper classes
774 protected final function getDatabaseEntry () {
775 // Is there an instance?
776 if (!$this->getResultInstance() instanceof SearchableResult) {
777 // Throw an exception here
778 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
782 $this->getResultInstance()->rewind();
784 // Do we have an entry?
785 if ($this->getResultInstance()->valid() === false) {
786 // @TODO Move the constant to e.g. BaseDatabaseResult when there is a non-cached database result available
787 throw new InvalidDatabaseResultException(array($this, $this->getResultInstance()), CachedDatabaseResult::EXCEPTION_INVALID_DATABASE_RESULT);
791 $this->getResultInstance()->next();
794 $entry = $this->getResultInstance()->current();
801 * Getter for field name
803 * @param $fieldName Field name which we shall get
804 * @return $fieldValue Field value from the user
805 * @throws NullPointerException If the result instance is null
807 public final function getField (string $fieldName) {
808 // Default field value
811 // Get result instance
812 $resultInstance = $this->getResultInstance();
814 // Is this instance null?
815 if (is_null($resultInstance)) {
816 // Then the user instance is no longer valid (expired cookies?)
817 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
821 $fieldArray = $resultInstance->current();
822 //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput($fieldName.':<pre>'.print_r($fieldArray, true).'</pre>');
824 // Convert dashes to underscore
825 $fieldName2 = StringUtils::convertDashesToUnderscores($fieldName);
827 // Does the field exist?
828 if ($this->isFieldSet($fieldName)) {
830 $fieldValue = $fieldArray[$fieldName2];
831 } elseif (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('developer_mode_enabled')) {
832 // Missing field entry, may require debugging
833 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FRAMEWORK-SYSTEM: fieldArray<pre>=' . print_r($fieldArray, true) . '</pre>,fieldName=' . $fieldName . ' not found!');
835 // Missing field entry, may require debugging
836 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FRAMEWORK-SYSTEM: fieldName=' . $fieldName . ' not found!');
844 * Checks if given field is set
846 * @param $fieldName Field name to check
847 * @return $isSet Whether the given field name is set
848 * @throws NullPointerException If the result instance is null
850 public function isFieldSet (string $fieldName) {
851 // Get result instance
852 $resultInstance = $this->getResultInstance();
854 // Is this instance null?
855 if (is_null($resultInstance)) {
856 // Then the user instance is no longer valid (expired cookies?)
857 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
861 $fieldArray = $resultInstance->current();
862 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('[' . $this->__toString() . ':' . __LINE__ . '] fieldName=' . $fieldName . ',fieldArray=<pre>'.print_r($fieldArray, true).'</pre>');
864 // Convert dashes to underscore
865 $fieldName = StringUtils::convertDashesToUnderscores($fieldName);
868 $isSet = isset($fieldArray[$fieldName]);
875 * Outputs a deprecation warning to the developer.
877 * @param $message The message we shall output to the developer
879 * @todo Write a logging mechanism for productive mode
881 public function deprecationWarning (string $message) {
882 // Is developer mode active?
883 if (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('developer_mode_enabled')) {
884 // Debug instance is there?
885 if (!is_null($this->getDebugInstance())) {
886 // Output stub message
887 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput($message);
890 trigger_error($message . "<br />\n");
894 // @TODO Finish this part!
895 $this->partialStub('Developer mode inactive. Message:' . $message);
900 * Checks whether the given PHP extension is loaded
902 * @param $phpExtension The PHP extension we shall check
903 * @return $isLoaded Whether the PHP extension is loaded
905 public final function isPhpExtensionLoaded (string $phpExtension) {
907 $isLoaded = in_array($phpExtension, get_loaded_extensions());
914 * "Getter" as a time() replacement but with milliseconds. You should use this
915 * method instead of the encapsulated getimeofday() function.
917 * @return $milliTime Timestamp with milliseconds
919 public function getMilliTime () {
920 // Get the time of day as float
921 $milliTime = gettimeofday(true);
928 * Idles (sleeps) for given milliseconds
930 * @return $hasSlept Whether it goes fine
932 public function idle (int $milliSeconds) {
933 // Sleep is fine by default
936 // Idle so long with found function
937 if (function_exists('time_sleep_until')) {
938 // Get current time and add idle time
939 $sleepUntil = $this->getMilliTime() + abs($milliSeconds) / 1000;
941 // New PHP 5.1.0 function found, ignore errors
942 $hasSlept = @time_sleep_until($sleepUntil);
945 * My Sun station doesn't have that function even with latest PHP
948 usleep($milliSeconds * 1000);
956 * Checks whether the given encoded data was encoded with Base64
958 * @param $encodedData Encoded data we shall check
959 * @return $isBase64 Whether the encoded data is Base64
961 protected function isBase64Encoded (string $encodedData) {
963 $isBase64 = (@base64_decode($encodedData, true) !== false);
970 * Gets a cache key from Criteria instance
972 * @param $criteriaInstance An instance of a Criteria class
973 * @param $onlyKeys Only use these keys for a cache key
974 * @return $cacheKey A cache key suitable for lookup/storage purposes
976 protected function getCacheKeyByCriteria (Criteria $criteriaInstance, array $onlyKeys = []) {
978 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FRAMEWORK-SYSTEM: criteriaInstance=' . $criteriaInstance->__toString() . ',onlyKeys()=' . count($onlyKeys) . ' - CALLED!');
979 $cacheKey = sprintf('%s@%s',
981 $criteriaInstance->getCacheKey($onlyKeys)
985 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FRAMEWORK-SYSTEM: cacheKey=' . $cacheKey . ' - EXIT!');
990 * Getter for startup time in miliseconds
992 * @return $startupTime Startup time in miliseconds
994 protected function getStartupTime () {
995 return self::$startupTime;
999 * "Getter" for a printable currently execution time in nice braces
1001 * @return $executionTime Current execution time in nice braces
1003 protected function getPrintableExecutionTime () {
1004 // Calculate execution time and pack it in nice braces
1005 $executionTime = sprintf('[ %01.5f ] ', (microtime(true) - $this->getStartupTime()));
1008 return $executionTime;
1012 * Determines if an element is set in the generic array
1014 * @param $keyGroup Main group for the key
1015 * @param $subGroup Sub group for the key
1016 * @param $key Key to check
1017 * @param $element Element to check
1018 * @return $isset Whether the given key is set
1020 protected final function isGenericArrayElementSet (string $keyGroup, string $subGroup, $key, $element) {
1022 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element);
1023 $isset = isset($this->genericArray[$keyGroup][$subGroup][$key][$element]);
1029 * Determines if a key is set in the generic array
1031 * @param $keyGroup Main group for the key
1032 * @param $subGroup Sub group for the key
1033 * @param $key Key to check
1034 * @return $isset Whether the given key is set
1036 protected final function isGenericArrayKeySet (string $keyGroup, string $subGroup, $key) {
1038 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1039 $isset = isset($this->genericArray[$keyGroup][$subGroup][$key]);
1047 * Determines if a group is set in the generic array
1049 * @param $keyGroup Main group
1050 * @param $subGroup Sub group
1051 * @return $isset Whether the given group is set
1053 protected final function isGenericArrayGroupSet (string $keyGroup, string $subGroup) {
1055 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup);
1056 $isset = isset($this->genericArray[$keyGroup][$subGroup]);
1063 * Getter for sub key group
1065 * @param $keyGroup Main key group
1066 * @param $subGroup Sub key group
1067 * @return $array An array with all array elements
1069 protected final function getGenericSubArray (string $keyGroup, string $subGroup) {
1071 if (!$this->isGenericArrayGroupSet($keyGroup, $subGroup)) {
1072 // No, then abort here
1073 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' not found.');
1078 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',value=' . print_r($this->genericArray[$keyGroup][$subGroup], true));
1079 return $this->genericArray[$keyGroup][$subGroup];
1083 * Unsets a given key in generic array
1085 * @param $keyGroup Main group for the key
1086 * @param $subGroup Sub group for the key
1087 * @param $key Key to unset
1090 protected final function unsetGenericArrayKey (string $keyGroup, string $subGroup, $key) {
1092 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1093 unset($this->genericArray[$keyGroup][$subGroup][$key]);
1097 * Unsets a given element in generic array
1099 * @param $keyGroup Main group for the key
1100 * @param $subGroup Sub group for the key
1101 * @param $key Key to unset
1102 * @param $element Element to unset
1105 protected final function unsetGenericArrayElement (string $keyGroup, string $subGroup, $key, $element) {
1107 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element);
1110 unset($this->genericArray[$keyGroup][$subGroup][$key][$element]);
1114 * Append a string to a given generic array key
1116 * @param $keyGroup Main group for the key
1117 * @param $subGroup Sub group for the key
1118 * @param $key Key to unset
1119 * @param $value Value to add/append
1122 protected final function appendStringToGenericArrayKey (string $keyGroup, string $subGroup, $key, string $value, $appendGlue = '') {
1124 //* 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);
1126 // Is it already there?
1127 if ($this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
1129 $this->genericArray[$keyGroup][$subGroup][$key] .= $appendGlue . (string) $value;
1132 $this->genericArray[$keyGroup][$subGroup][$key] = (string) $value;
1137 * Append a string to a given generic array element
1139 * @param $keyGroup Main group for the key
1140 * @param $subGroup Sub group for the key
1141 * @param $key Key to unset
1142 * @param $element Element to check
1143 * @param $value Value to add/append
1146 protected final function appendStringToGenericArrayElement (string $keyGroup, string $subGroup, $key, $element, $value, $appendGlue = '') {
1148 //* 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);
1150 // Is it already there?
1151 if ($this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element)) {
1153 $this->genericArray[$keyGroup][$subGroup][$key][$element] .= $appendGlue . (string) $value;
1156 $this->setStringGenericArrayElement($keyGroup, $subGroup, $key, $element, $value);
1161 * Sets a string in a given generic array element
1163 * @param $keyGroup Main group for the key
1164 * @param $subGroup Sub group for the key
1165 * @param $key Key to unset
1166 * @param $element Element to check
1167 * @param $value Value to add/append
1170 protected final function setStringGenericArrayElement (string $keyGroup, string $subGroup, $key, $element, $value, $appendGlue = '') {
1172 //* 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);
1175 $this->genericArray[$keyGroup][$subGroup][$key][$element] = (string) $value;
1179 * Initializes given generic array group
1181 * @param $keyGroup Main group for the key
1182 * @param $subGroup Sub group for the key
1183 * @param $key Key to use
1184 * @param $forceInit Optionally force initialization
1187 protected final function initGenericArrayGroup (string $keyGroup, string $subGroup, bool $forceInit = false) {
1189 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',forceInit=' . intval($forceInit));
1191 // Is it already set?
1192 if (($forceInit === false) && ($this->isGenericArrayGroupSet($keyGroup, $subGroup))) {
1193 // Already initialized
1194 trigger_error(__METHOD__ . ':keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' already initialized.');
1199 $this->genericArray[$keyGroup][$subGroup] = [];
1203 * Initializes given generic array key
1205 * @param $keyGroup Main group for the key
1206 * @param $subGroup Sub group for the key
1207 * @param $key Key to use
1208 * @param $forceInit Optionally force initialization
1211 protected final function initGenericArrayKey (string $keyGroup, string $subGroup, $key, bool $forceInit = false) {
1213 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',forceInit=' . intval($forceInit));
1215 // Is it already set?
1216 if (($forceInit === false) && ($this->isGenericArrayKeySet($keyGroup, $subGroup, $key))) {
1217 // Already initialized
1218 trigger_error(__METHOD__ . ':keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' already initialized.');
1223 $this->genericArray[$keyGroup][$subGroup][$key] = [];
1227 * Initializes given generic array element
1229 * @param $keyGroup Main group for the key
1230 * @param $subGroup Sub group for the key
1231 * @param $key Key to use
1232 * @param $element Element to use
1233 * @param $forceInit Optionally force initialization
1236 protected final function initGenericArrayElement (string $keyGroup, string $subGroup, $key, $element, bool $forceInit = false) {
1238 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element . ',forceInit=' . intval($forceInit));
1240 // Is it already set?
1241 if (($forceInit === false) && ($this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element))) {
1242 // Already initialized
1243 trigger_error(__METHOD__ . ':keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element . ' already initialized.');
1248 $this->genericArray[$keyGroup][$subGroup][$key][$element] = [];
1252 * Pushes an element to a generic key
1254 * @param $keyGroup Main group for the key
1255 * @param $subGroup Sub group for the key
1256 * @param $key Key to use
1257 * @param $value Value to add/append
1258 * @return $count Number of array elements
1260 protected final function pushValueToGenericArrayKey (string $keyGroup, string $subGroup, $key, $value) {
1262 //* NOISY-DEBUG: */ if (!is_object($value)) $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',value[' . gettype($value) . ']=' . print_r($value, true));
1265 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
1267 $this->initGenericArrayKey($keyGroup, $subGroup, $key);
1271 $count = array_push($this->genericArray[$keyGroup][$subGroup][$key], $value);
1274 //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], true));
1275 //* DEBUG: */ print(__METHOD__ . ': count=' . $count . PHP_EOL);
1280 * Pushes an element to a generic array element
1282 * @param $keyGroup Main group for the key
1283 * @param $subGroup Sub group for the key
1284 * @param $key Key to use
1285 * @param $element Element to check
1286 * @param $value Value to add/append
1287 * @return $count Number of array elements
1289 protected final function pushValueToGenericArrayElement (string $keyGroup, string $subGroup, $key, $element, $value) {
1291 //* 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));
1294 if (!$this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element)) {
1296 $this->initGenericArrayElement($keyGroup, $subGroup, $key, $element);
1300 $count = array_push($this->genericArray[$keyGroup][$subGroup][$key][$element], $value);
1303 //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], true));
1304 //* DEBUG: */ print(__METHOD__ . ': count=' . $count . PHP_EOL);
1309 * Pops an element from a generic group
1311 * @param $keyGroup Main group for the key
1312 * @param $subGroup Sub group for the key
1313 * @param $key Key to unset
1314 * @return $value Last "popped" value
1316 protected final function popGenericArrayElement (string $keyGroup, string $subGroup, $key) {
1318 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1321 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
1323 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' not found.');
1328 $value = array_pop($this->genericArray[$keyGroup][$subGroup][$key]);
1331 //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], true));
1332 //* DEBUG: */ print(__METHOD__ . ': value[' . gettype($value) . ']=' . print_r($value, true) . PHP_EOL);
1337 * Shifts an element from a generic group
1339 * @param $keyGroup Main group for the key
1340 * @param $subGroup Sub group for the key
1341 * @param $key Key to unset
1342 * @return $value Last "popped" value
1344 protected final function shiftGenericArrayElement (string $keyGroup, string $subGroup, $key) {
1346 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1349 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
1351 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' not found.');
1356 $value = array_shift($this->genericArray[$keyGroup][$subGroup][$key]);
1359 //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], true));
1360 //* DEBUG: */ print(__METHOD__ . ': value[' . gettype($value) . ']=' . print_r($value, true) . PHP_EOL);
1365 * Count generic array group
1367 * @param $keyGroup Main group for the key
1368 * @return $count Count of given group
1370 protected final function countGenericArray ($keyGroup) {
1372 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup);
1375 if (!isset($this->genericArray[$keyGroup])) {
1377 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ' not found.');
1382 $count = count($this->genericArray[$keyGroup]);
1385 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',count=' . $count);
1392 * Count generic array sub group
1394 * @param $keyGroup Main group for the key
1395 * @param $subGroup Sub group for the key
1396 * @return $count Count of given group
1398 protected final function countGenericArrayGroup (string $keyGroup, string $subGroup) {
1400 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup);
1403 if (!$this->isGenericArrayGroupSet($keyGroup, $subGroup)) {
1405 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' not found.');
1410 $count = count($this->genericArray[$keyGroup][$subGroup]);
1413 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',count=' . $count);
1420 * Count generic array elements
1422 * @param $keyGroup Main group for the key
1423 * @param $subGroup Sub group for the key
1424 * @para $key Key to count
1425 * @return $count Count of given key
1427 protected final function countGenericArrayElements (string $keyGroup, string $subGroup, $key) {
1429 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1432 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
1434 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' not found.');
1436 } elseif (!$this->isValidGenericArrayGroup($keyGroup, $subGroup)) {
1438 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' is not an array.');
1443 $count = count($this->genericArray[$keyGroup][$subGroup][$key]);
1446 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',count=' . $count);
1453 * Getter for whole generic group array
1455 * @param $keyGroup Key group to get
1456 * @return $array Whole generic array group
1458 protected final function getGenericArray ($keyGroup) {
1460 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup);
1463 if (!isset($this->genericArray[$keyGroup])) {
1465 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ' does not exist.');
1470 return $this->genericArray[$keyGroup];
1474 * Setter for generic array key
1476 * @param $keyGroup Key group to get
1477 * @param $subGroup Sub group for the key
1478 * @param $key Key to unset
1479 * @param $value Mixed value from generic array element
1482 protected final function setGenericArrayKey (string $keyGroup, string $subGroup, $key, $value) {
1484 //* NOISY-DEBUG: */ if (!is_object($value)) $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',value[' . gettype($value) . ']=' . print_r($value, true));
1487 $this->genericArray[$keyGroup][$subGroup][$key] = $value;
1491 * Getter for generic array key
1493 * @param $keyGroup Key group to get
1494 * @param $subGroup Sub group for the key
1495 * @param $key Key to unset
1496 * @return $value Mixed value from generic array element
1498 protected final function getGenericArrayKey (string $keyGroup, string $subGroup, $key) {
1500 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1503 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
1505 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' does not exist.');
1510 return $this->genericArray[$keyGroup][$subGroup][$key];
1514 * Sets a value in given generic array key/element
1516 * @param $keyGroup Main group for the key
1517 * @param $subGroup Sub group for the key
1518 * @param $key Key to set
1519 * @param $element Element to set
1520 * @param $value Value to set
1523 protected final function setGenericArrayElement (string $keyGroup, string $subGroup, $key, $element, $value) {
1525 //* 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));
1528 $this->genericArray[$keyGroup][$subGroup][$key][$element] = $value;
1532 * Getter for generic array element
1534 * @param $keyGroup Key group to get
1535 * @param $subGroup Sub group for the key
1536 * @param $key Key to look for
1537 * @param $element Element to look for
1538 * @return $value Mixed value from generic array element
1540 protected final function getGenericArrayElement (string $keyGroup, string $subGroup, $key, $element) {
1542 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element);
1545 if (!$this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element)) {
1547 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element . ' does not exist.');
1552 return $this->genericArray[$keyGroup][$subGroup][$key][$element];
1556 * Checks if a given sub group is valid (array)
1558 * @param $keyGroup Key group to get
1559 * @param $subGroup Sub group for the key
1560 * @return $isValid Whether given sub group is valid
1562 protected final function isValidGenericArrayGroup (string $keyGroup, string $subGroup) {
1564 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup);
1567 $isValid = (($this->isGenericArrayGroupSet($keyGroup, $subGroup)) && (is_array($this->getGenericSubArray($keyGroup, $subGroup))));
1574 * Checks if a given key is valid (array)
1576 * @param $keyGroup Key group to get
1577 * @param $subGroup Sub group for the key
1578 * @param $key Key to check
1579 * @return $isValid Whether given sub group is valid
1581 protected final function isValidGenericArrayKey (string $keyGroup, string $subGroup, $key) {
1583 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1586 $isValid = (($this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) && (is_array($this->getGenericArrayKey($keyGroup, $subGroup, $key))));
1593 * Initializes the web output instance
1597 protected function initWebOutputInstance () {
1598 // Init web output instance
1599 $outputInstance = ObjectFactory::createObjectByConfiguredName('output_class');
1602 $this->setWebOutputInstance($outputInstance);
1606 * Translates boolean true to 'Y' and false to 'N'
1608 * @param $boolean Boolean value
1609 * @return $translated Translated boolean value
1611 public static final function translateBooleanToYesNo (bool $boolean) {
1612 // Make sure it is really boolean
1613 assert(is_bool($boolean));
1616 $translated = ($boolean === true) ? 'Y' : 'N';
1618 // ... and return it
1623 * Creates a full-qualified file name (FQFN) for given file name by adding
1624 * a configured temporary file path to it.
1626 * @param $infoInstance An instance of a SplFileInfo class
1627 * @return $tempInstance An instance of a SplFileInfo class (temporary file)
1628 * @throw PathWriteProtectedException If the path in 'temp_file_path' is write-protected
1629 * @throws FileIoException If the file cannot be written
1631 protected static function createTempPathForFile (SplFileInfo $infoInstance) {
1633 $basePath = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('temp_file_path');
1635 // Is the path writeable?
1636 if (!is_writable($basePath)) {
1637 // Path is write-protected
1638 throw new PathWriteProtectedException($infoInstance, self::EXCEPTION_PATH_CANNOT_BE_WRITTEN);
1642 $tempInstance = new SplFileInfo($basePath . DIRECTORY_SEPARATOR . $infoInstance->getBasename());
1645 if (!FrameworkBootstrap::isReachableFilePath($tempInstance)) {
1647 throw new FileIoException($tempInstance, self::EXCEPTION_FILE_NOT_REACHABLE);
1651 return $tempInstance;
1655 * "Getter" for a printable state name
1657 * @return $stateName Name of the node's state in a printable format
1658 * @todo Move this class away from this monolithic place (not whole class is monolithic)
1660 public final function getPrintableState () {
1661 // Default is 'null'
1662 $stateName = 'null';
1664 // Get the state instance
1665 $stateInstance = $this->getStateInstance();
1667 // Is it an instance of Stateable?
1668 if ($stateInstance instanceof Stateable) {
1669 // Then use that state name
1670 $stateName = $stateInstance->getStateName();