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);
1025 $isset = isset($this->genericArray[$keyGroup][$subGroup][$key][$element]);
1031 * Determines if a key is set in the generic array
1033 * @param $keyGroup Main group for the key
1034 * @param $subGroup Sub group for the key
1035 * @param $key Key to check
1036 * @return $isset Whether the given key is set
1038 protected final function isGenericArrayKeySet (string $keyGroup, string $subGroup, $key) {
1040 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1043 $isset = isset($this->genericArray[$keyGroup][$subGroup][$key]);
1051 * Determines if a group is set in the generic array
1053 * @param $keyGroup Main group
1054 * @param $subGroup Sub group
1055 * @return $isset Whether the given group is set
1057 protected final function isGenericArrayGroupSet (string $keyGroup, string $subGroup) {
1059 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup);
1062 $isset = isset($this->genericArray[$keyGroup][$subGroup]);
1069 * Getter for sub key group
1071 * @param $keyGroup Main key group
1072 * @param $subGroup Sub key group
1073 * @return $array An array with all array elements
1075 protected final function getGenericSubArray (string $keyGroup, string $subGroup) {
1077 if (!$this->isGenericArrayGroupSet($keyGroup, $subGroup)) {
1078 // No, then abort here
1079 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' not found.');
1084 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',value=' . print_r($this->genericArray[$keyGroup][$subGroup], true));
1087 return $this->genericArray[$keyGroup][$subGroup];
1091 * Unsets a given key in generic array
1093 * @param $keyGroup Main group for the key
1094 * @param $subGroup Sub group for the key
1095 * @param $key Key to unset
1098 protected final function unsetGenericArrayKey (string $keyGroup, string $subGroup, $key) {
1100 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1103 unset($this->genericArray[$keyGroup][$subGroup][$key]);
1107 * Unsets a given element in generic array
1109 * @param $keyGroup Main group for the key
1110 * @param $subGroup Sub group for the key
1111 * @param $key Key to unset
1112 * @param $element Element to unset
1115 protected final function unsetGenericArrayElement (string $keyGroup, string $subGroup, $key, $element) {
1117 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element);
1120 unset($this->genericArray[$keyGroup][$subGroup][$key][$element]);
1124 * Append a string to a given generic array key
1126 * @param $keyGroup Main group for the key
1127 * @param $subGroup Sub group for the key
1128 * @param $key Key to unset
1129 * @param $value Value to add/append
1132 protected final function appendStringToGenericArrayKey (string $keyGroup, string $subGroup, $key, string $value, $appendGlue = '') {
1134 //* 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);
1136 // Is it already there?
1137 if ($this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
1139 $this->genericArray[$keyGroup][$subGroup][$key] .= $appendGlue . (string) $value;
1142 $this->genericArray[$keyGroup][$subGroup][$key] = (string) $value;
1147 * Append a string to a given generic array element
1149 * @param $keyGroup Main group for the key
1150 * @param $subGroup Sub group for the key
1151 * @param $key Key to unset
1152 * @param $element Element to check
1153 * @param $value Value to add/append
1156 protected final function appendStringToGenericArrayElement (string $keyGroup, string $subGroup, $key, $element, $value, $appendGlue = '') {
1158 //* 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);
1160 // Is it already there?
1161 if ($this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element)) {
1163 $this->genericArray[$keyGroup][$subGroup][$key][$element] .= $appendGlue . (string) $value;
1166 $this->setStringGenericArrayElement($keyGroup, $subGroup, $key, $element, $value);
1171 * Sets a string in a given generic array element
1173 * @param $keyGroup Main group for the key
1174 * @param $subGroup Sub group for the key
1175 * @param $key Key to unset
1176 * @param $element Element to check
1177 * @param $value Value to add/append
1180 protected final function setStringGenericArrayElement (string $keyGroup, string $subGroup, $key, $element, $value, $appendGlue = '') {
1182 //* 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);
1185 $this->genericArray[$keyGroup][$subGroup][$key][$element] = (string) $value;
1189 * Initializes given generic array group
1191 * @param $keyGroup Main group for the key
1192 * @param $subGroup Sub group for the key
1193 * @param $key Key to use
1194 * @param $forceInit Optionally force initialization
1197 protected final function initGenericArrayGroup (string $keyGroup, string $subGroup, bool $forceInit = false) {
1199 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',forceInit=' . intval($forceInit));
1201 // Is it already set?
1202 if (($forceInit === false) && ($this->isGenericArrayGroupSet($keyGroup, $subGroup))) {
1203 // Already initialized
1204 trigger_error(__METHOD__ . ':keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' already initialized.');
1209 $this->genericArray[$keyGroup][$subGroup] = [];
1213 * Initializes given generic array key
1215 * @param $keyGroup Main group for the key
1216 * @param $subGroup Sub group for the key
1217 * @param $key Key to use
1218 * @param $forceInit Optionally force initialization
1221 protected final function initGenericArrayKey (string $keyGroup, string $subGroup, $key, bool $forceInit = false) {
1223 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',forceInit=' . intval($forceInit));
1225 // Is it already set?
1226 if (($forceInit === false) && ($this->isGenericArrayKeySet($keyGroup, $subGroup, $key))) {
1227 // Already initialized
1228 trigger_error(__METHOD__ . ':keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' already initialized.');
1233 $this->genericArray[$keyGroup][$subGroup][$key] = [];
1237 * Initializes given generic array element
1239 * @param $keyGroup Main group for the key
1240 * @param $subGroup Sub group for the key
1241 * @param $key Key to use
1242 * @param $element Element to use
1243 * @param $forceInit Optionally force initialization
1246 protected final function initGenericArrayElement (string $keyGroup, string $subGroup, $key, $element, bool $forceInit = false) {
1248 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element . ',forceInit=' . intval($forceInit));
1250 // Is it already set?
1251 if (($forceInit === false) && ($this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element))) {
1252 // Already initialized
1253 trigger_error(__METHOD__ . ':keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element . ' already initialized.');
1258 $this->genericArray[$keyGroup][$subGroup][$key][$element] = [];
1262 * Pushes an element to a generic key
1264 * @param $keyGroup Main group for the key
1265 * @param $subGroup Sub group for the key
1266 * @param $key Key to use
1267 * @param $value Value to add/append
1268 * @return $count Number of array elements
1270 protected final function pushValueToGenericArrayKey (string $keyGroup, string $subGroup, $key, $value) {
1272 //* NOISY-DEBUG: */ if (!is_object($value)) $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',value[' . gettype($value) . ']=' . print_r($value, true));
1275 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
1277 $this->initGenericArrayKey($keyGroup, $subGroup, $key);
1281 $count = array_push($this->genericArray[$keyGroup][$subGroup][$key], $value);
1284 //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], true));
1285 //* DEBUG: */ print(__METHOD__ . ': count=' . $count . PHP_EOL);
1290 * Pushes an element to a generic array element
1292 * @param $keyGroup Main group for the key
1293 * @param $subGroup Sub group for the key
1294 * @param $key Key to use
1295 * @param $element Element to check
1296 * @param $value Value to add/append
1297 * @return $count Number of array elements
1299 protected final function pushValueToGenericArrayElement (string $keyGroup, string $subGroup, $key, $element, $value) {
1301 //* 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));
1304 if (!$this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element)) {
1306 $this->initGenericArrayElement($keyGroup, $subGroup, $key, $element);
1310 $count = array_push($this->genericArray[$keyGroup][$subGroup][$key][$element], $value);
1313 //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], true));
1314 //* DEBUG: */ print(__METHOD__ . ': count=' . $count . PHP_EOL);
1319 * Pops an element from a generic group
1321 * @param $keyGroup Main group for the key
1322 * @param $subGroup Sub group for the key
1323 * @param $key Key to unset
1324 * @return $value Last "popped" value
1326 protected final function popGenericArrayElement (string $keyGroup, string $subGroup, $key) {
1328 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1331 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
1333 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' not found.');
1338 $value = array_pop($this->genericArray[$keyGroup][$subGroup][$key]);
1341 //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], true));
1342 //* DEBUG: */ print(__METHOD__ . ': value[' . gettype($value) . ']=' . print_r($value, true) . PHP_EOL);
1347 * Shifts an element from a generic group
1349 * @param $keyGroup Main group for the key
1350 * @param $subGroup Sub group for the key
1351 * @param $key Key to unset
1352 * @return $value Last "popped" value
1354 protected final function shiftGenericArrayElement (string $keyGroup, string $subGroup, $key) {
1356 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1359 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
1361 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' not found.');
1366 $value = array_shift($this->genericArray[$keyGroup][$subGroup][$key]);
1369 //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], true));
1370 //* DEBUG: */ print(__METHOD__ . ': value[' . gettype($value) . ']=' . print_r($value, true) . PHP_EOL);
1375 * Count generic array group
1377 * @param $keyGroup Main group for the key
1378 * @return $count Count of given group
1380 protected final function countGenericArray ($keyGroup) {
1382 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup);
1385 if (!isset($this->genericArray[$keyGroup])) {
1387 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ' not found.');
1392 $count = count($this->genericArray[$keyGroup]);
1395 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',count=' . $count);
1402 * Count generic array sub group
1404 * @param $keyGroup Main group for the key
1405 * @param $subGroup Sub group for the key
1406 * @return $count Count of given group
1408 protected final function countGenericArrayGroup (string $keyGroup, string $subGroup) {
1410 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup);
1413 if (!$this->isGenericArrayGroupSet($keyGroup, $subGroup)) {
1415 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' not found.');
1420 $count = count($this->genericArray[$keyGroup][$subGroup]);
1423 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',count=' . $count);
1430 * Count generic array elements
1432 * @param $keyGroup Main group for the key
1433 * @param $subGroup Sub group for the key
1434 * @para $key Key to count
1435 * @return $count Count of given key
1437 protected final function countGenericArrayElements (string $keyGroup, string $subGroup, $key) {
1439 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1442 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
1444 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' not found.');
1446 } elseif (!$this->isValidGenericArrayGroup($keyGroup, $subGroup)) {
1448 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' is not an array.');
1453 $count = count($this->genericArray[$keyGroup][$subGroup][$key]);
1456 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',count=' . $count);
1463 * Getter for whole generic group array
1465 * @param $keyGroup Key group to get
1466 * @return $array Whole generic array group
1468 protected final function getGenericArray ($keyGroup) {
1470 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup);
1473 if (!isset($this->genericArray[$keyGroup])) {
1475 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ' does not exist.');
1480 return $this->genericArray[$keyGroup];
1484 * Setter for generic array key
1486 * @param $keyGroup Key group to get
1487 * @param $subGroup Sub group for the key
1488 * @param $key Key to unset
1489 * @param $value Mixed value from generic array element
1492 protected final function setGenericArrayKey (string $keyGroup, string $subGroup, $key, $value) {
1494 //* NOISY-DEBUG: */ if (!is_object($value)) $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',value[' . gettype($value) . ']=' . print_r($value, true));
1497 $this->genericArray[$keyGroup][$subGroup][$key] = $value;
1501 * Getter for generic array key
1503 * @param $keyGroup Key group to get
1504 * @param $subGroup Sub group for the key
1505 * @param $key Key to unset
1506 * @return $value Mixed value from generic array element
1508 protected final function getGenericArrayKey (string $keyGroup, string $subGroup, $key) {
1510 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1513 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
1515 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' does not exist.');
1520 return $this->genericArray[$keyGroup][$subGroup][$key];
1524 * Sets a value in given generic array key/element
1526 * @param $keyGroup Main group for the key
1527 * @param $subGroup Sub group for the key
1528 * @param $key Key to set
1529 * @param $element Element to set
1530 * @param $value Value to set
1533 protected final function setGenericArrayElement (string $keyGroup, string $subGroup, $key, $element, $value) {
1535 //* 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));
1538 $this->genericArray[$keyGroup][$subGroup][$key][$element] = $value;
1542 * Getter for generic array element
1544 * @param $keyGroup Key group to get
1545 * @param $subGroup Sub group for the key
1546 * @param $key Key to look for
1547 * @param $element Element to look for
1548 * @return $value Mixed value from generic array element
1550 protected final function getGenericArrayElement (string $keyGroup, string $subGroup, $key, $element) {
1552 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element);
1555 if (!$this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element)) {
1557 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element . ' does not exist.');
1562 return $this->genericArray[$keyGroup][$subGroup][$key][$element];
1566 * Checks if a given sub group is valid (array)
1568 * @param $keyGroup Key group to get
1569 * @param $subGroup Sub group for the key
1570 * @return $isValid Whether given sub group is valid
1572 protected final function isValidGenericArrayGroup (string $keyGroup, string $subGroup) {
1574 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup);
1577 $isValid = (($this->isGenericArrayGroupSet($keyGroup, $subGroup)) && (is_array($this->getGenericSubArray($keyGroup, $subGroup))));
1584 * Checks if a given key is valid (array)
1586 * @param $keyGroup Key group to get
1587 * @param $subGroup Sub group for the key
1588 * @param $key Key to check
1589 * @return $isValid Whether given sub group is valid
1591 protected final function isValidGenericArrayKey (string $keyGroup, string $subGroup, $key) {
1593 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1596 $isValid = (($this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) && (is_array($this->getGenericArrayKey($keyGroup, $subGroup, $key))));
1603 * Initializes the web output instance
1607 protected function initWebOutputInstance () {
1608 // Init web output instance
1609 $outputInstance = ObjectFactory::createObjectByConfiguredName('output_class');
1612 $this->setWebOutputInstance($outputInstance);
1616 * Translates boolean true to 'Y' and false to 'N'
1618 * @param $boolean Boolean value
1619 * @return $translated Translated boolean value
1621 public static final function translateBooleanToYesNo (bool $boolean) {
1622 // Make sure it is really boolean
1623 assert(is_bool($boolean));
1626 $translated = ($boolean === true) ? 'Y' : 'N';
1628 // ... and return it
1633 * Creates a full-qualified file name (FQFN) for given file name by adding
1634 * a configured temporary file path to it.
1636 * @param $infoInstance An instance of a SplFileInfo class
1637 * @return $tempInstance An instance of a SplFileInfo class (temporary file)
1638 * @throw PathWriteProtectedException If the path in 'temp_file_path' is write-protected
1639 * @throws FileIoException If the file cannot be written
1641 protected static function createTempPathForFile (SplFileInfo $infoInstance) {
1643 $basePath = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('temp_file_path');
1645 // Is the path writeable?
1646 if (!is_writable($basePath)) {
1647 // Path is write-protected
1648 throw new PathWriteProtectedException($infoInstance, self::EXCEPTION_PATH_CANNOT_BE_WRITTEN);
1652 $tempInstance = new SplFileInfo($basePath . DIRECTORY_SEPARATOR . $infoInstance->getBasename());
1655 if (!FrameworkBootstrap::isReachableFilePath($tempInstance)) {
1657 throw new FileIoException($tempInstance, self::EXCEPTION_FILE_NOT_REACHABLE);
1661 return $tempInstance;
1665 * "Getter" for a printable state name
1667 * @return $stateName Name of the node's state in a printable format
1668 * @todo Move this class away from this monolithic place (not whole class is monolithic)
1670 public final function getPrintableState () {
1671 // Default is 'null'
1672 $stateName = 'null';
1674 // Get the state instance
1675 $stateInstance = $this->getStateInstance();
1677 // Is it an instance of Stateable?
1678 if ($stateInstance instanceof Stateable) {
1679 // Then use that state name
1680 $stateName = $stateInstance->getStateName();