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\Database\Frontend\DatabaseWrapper;
9 use Org\Mxchange\CoreFramework\EntryPoint\ApplicationEntryPoint;
10 use Org\Mxchange\CoreFramework\Factory\Database\Wrapper\DatabaseWrapperFactory;
11 use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
12 use Org\Mxchange\CoreFramework\Filesystem\PathWriteProtectedException;
13 use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
14 use Org\Mxchange\CoreFramework\Generic\NullPointerException;
15 use Org\Mxchange\CoreFramework\Generic\UnsupportedOperationException;
16 use Org\Mxchange\CoreFramework\Loader\ClassLoader;
17 use Org\Mxchange\CoreFramework\Manager\ManageableApplication;
18 use Org\Mxchange\CoreFramework\Middleware\Debug\DebugMiddleware;
19 use Org\Mxchange\CoreFramework\Registry\GenericRegistry;
20 use Org\Mxchange\CoreFramework\Result\Database\CachedDatabaseResult;
21 use Org\Mxchange\CoreFramework\State\Stateable;
22 use Org\Mxchange\CoreFramework\Stream\Output\OutputStreamer;
23 use Org\Mxchange\CoreFramework\Utils\String\StringUtils;
27 use \InvalidArgumentException;
32 * The simulator system class is the super class of all other classes. This
33 * class handles saving of games etc.
35 * @author Roland Haeder <webmaster@shipsimu.org>
37 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2020 Core Developer Team
38 * @license GNU GPL 3.0 or any newer version
39 * @link http://www.shipsimu.org
41 * This program is free software: you can redistribute it and/or modify
42 * it under the terms of the GNU General Public License as published by
43 * the Free Software Foundation, either version 3 of the License, or
44 * (at your option) any later version.
46 * This program is distributed in the hope that it will be useful,
47 * but WITHOUT ANY WARRANTY; without even the implied warranty of
48 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
49 * GNU General Public License for more details.
51 * You should have received a copy of the GNU General Public License
52 * along with this program. If not, see <http://www.gnu.org/licenses/>.
54 abstract class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
56 * Length of output from hash()
58 private static $hashLength = NULL;
61 * Self-referencing instance
63 private static $instance = NULL;
68 private $realClass = __CLASS__;
71 * An instance of a database wrapper class
73 private $wrapperInstance = NULL;
78 private $stateInstance = NULL;
83 private $callbackInstance = NULL;
88 private $genericArray = [];
90 /***********************
91 * Exception codes.... *
92 ***********************/
94 // @todo Try to clean these constants up
95 const EXCEPTION_IS_NULL_POINTER = 0x001;
96 const EXCEPTION_IS_NO_OBJECT = 0x002;
97 const EXCEPTION_IS_NO_ARRAY = 0x003;
98 const EXCEPTION_MISSING_METHOD = 0x004;
99 const EXCEPTION_CLASSES_NOT_MATCHING = 0x005;
100 const EXCEPTION_INDEX_OUT_OF_BOUNDS = 0x006;
101 const EXCEPTION_DIMENSION_ARRAY_INVALID = 0x007;
102 const EXCEPTION_ITEM_NOT_TRADEABLE = 0x008;
103 const EXCEPTION_ITEM_NOT_IN_PRICE_LIST = 0x009;
104 const EXCEPTION_GENDER_IS_WRONG = 0x00a;
105 const EXCEPTION_BIRTH_DATE_IS_INVALID = 0x00b;
106 const EXCEPTION_EMPTY_STRUCTURES_ARRAY = 0x00c;
107 const EXCEPTION_HAS_ALREADY_PERSONELL_LIST = 0x00d;
108 const EXCEPTION_NOT_ENOUGTH_UNEMPLOYEES = 0x00e;
109 const EXCEPTION_TOTAL_PRICE_NOT_CALCULATED = 0x00f;
110 const EXCEPTION_HARBOR_HAS_NO_SHIPYARDS = 0x010;
111 const EXCEPTION_CONTRACT_PARTNER_INVALID = 0x011;
112 const EXCEPTION_CONTRACT_PARTNER_MISMATCH = 0x012;
113 const EXCEPTION_CONTRACT_ALREADY_SIGNED = 0x013;
114 const EXCEPTION_UNEXPECTED_EMPTY_STRING = 0x014;
115 const EXCEPTION_PATH_NOT_FOUND = 0x015;
116 const EXCEPTION_INVALID_PATH_NAME = 0x016;
117 const EXCEPTION_READ_PROTECED_PATH = 0x017;
118 const EXCEPTION_WRITE_PROTECED_PATH = 0x018;
119 const EXCEPTION_DIR_POINTER_INVALID = 0x019;
120 const EXCEPTION_FILE_POINTER_INVALID = 0x01a;
121 const EXCEPTION_INVALID_RESOURCE = 0x01b;
122 const EXCEPTION_UNEXPECTED_OBJECT = 0x01c;
123 const EXCEPTION_LIMIT_ELEMENT_IS_UNSUPPORTED = 0x01d;
124 const EXCEPTION_GETTER_IS_MISSING = 0x01e;
125 const EXCEPTION_ARRAY_EXPECTED = 0x01f;
126 const EXCEPTION_ARRAY_HAS_INVALID_COUNT = 0x020;
127 const EXCEPTION_ID_IS_INVALID_FORMAT = 0x021;
128 const EXCEPTION_MD5_CHECKSUMS_MISMATCH = 0x022;
129 const EXCEPTION_UNEXPECTED_STRING_SIZE = 0x023;
130 const EXCEPTION_SIMULATOR_ID_INVALID = 0x024;
131 const EXCEPTION_MISMATCHING_COMPRESSORS = 0x025;
132 const EXCEPTION_CONTAINER_ITEM_IS_NULL = 0x026;
133 const EXCEPTION_ITEM_IS_NO_ARRAY = 0x027;
134 const EXCEPTION_CONTAINER_MAYBE_DAMAGED = 0x028;
135 const EXCEPTION_INVALID_STRING = 0x029;
136 const EXCEPTION_VARIABLE_NOT_SET = 0x02a;
137 const EXCEPTION_ATTRIBUTES_ARE_MISSING = 0x02b;
138 const EXCEPTION_ARRAY_ELEMENTS_MISSING = 0x02c;
139 const EXCEPTION_TEMPLATE_ENGINE_UNSUPPORTED = 0x02d;
140 const EXCEPTION_UNSPPORTED_OPERATION = 0x02e;
141 const EXCEPTION_FACTORY_REQUIRE_PARAMETER = 0x02f;
142 const EXCEPTION_MISSING_ELEMENT = 0x030;
143 const EXCEPTION_HEADERS_ALREADY_SENT = 0x031;
144 const EXCEPTION_DEFAULT_CONTROLLER_GONE = 0x032;
145 const EXCEPTION_CLASS_NOT_FOUND = 0x033;
146 const EXCEPTION_REQUIRED_INTERFACE_MISSING = 0x034;
147 const EXCEPTION_FATAL_ERROR = 0x035;
148 const EXCEPTION_FILE_NOT_FOUND = 0x036;
149 const EXCEPTION_ASSERTION_FAILED = 0x037;
150 const EXCEPTION_FILE_NOT_REACHABLE = 0x038;
151 const EXCEPTION_FILE_CANNOT_BE_READ = 0x039;
152 const EXCEPTION_FILE_CANNOT_BE_WRITTEN = 0x03a;
153 const EXCEPTION_PATH_CANNOT_BE_WRITTEN = 0x03b;
154 const EXCEPTION_DATABASE_UPDATED_NOT_ALLOWED = 0x03c;
155 const EXCEPTION_FILTER_CHAIN_INTERCEPTED = 0x03d;
156 const EXCEPTION_INVALID_SOCKET = 0x03e;
157 const EXCEPTION_SELF_INSTANCE = 0x03f;
160 * Startup time in miliseconds
162 private static $startupTime = 0;
165 * Protected super constructor
167 * @param $className Name of the class
170 protected function __construct (string $className) {
172 $this->setRealClass($className);
174 // Is the startup time set? (0 cannot be true anymore)
175 if (self::$startupTime == 0) {
177 self::$startupTime = microtime(true);
182 * Destructor for all classes. You should not call this method on your own.
186 public function __destruct () {
187 // Is this object already destroyed?
188 if ($this->__toString() != 'DestructedObject') {
189 // Destroy all informations about this class but keep some text about it alive
190 $this->setRealClass('DestructedObject');
191 } elseif ((defined('DEBUG_DESTRUCTOR')) && (is_object($this->getDebugInstance()))) {
192 // Already destructed object
193 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('The object <span class="object_name">%s</span> is already destroyed.',
197 // Do not call this twice
198 trigger_error(__METHOD__ . ': Called twice.');
204 * The __call() method where all non-implemented methods end up
206 * @param $methodName Name of the missing method
207 * @args $args Arguments passed to the method
210 public final function __call (string $methodName, array $args = NULL) {
212 self::$instance = $this;
214 // Call static method
215 self::__callStatic($methodName, $args);
217 // Clear self-instance
218 self::$instance = NULL;
222 * The __callStatic() method where all non-implemented static methods end up
224 * @param $methodName Name of the missing method
225 * @param $args Arguments passed to the method
227 * @throws InvalidArgumentException If self::$instance is not a framework's own object
229 public static final function __callStatic (string $methodName, array $args = NULL) {
230 // Init argument string and class name
231 //* PRINT-DEBUG: */ printf('[%s:%d]: methodName=%s,args[]=%s - CALLED!' . PHP_EOL, __METHOD__, __LINE__, $methodName, gettype($args));
233 $className = 'unknown';
235 // Is self-instance set?
236 if (self::$instance instanceof FrameworkInterface) {
237 // Framework's own instance
238 $className = self::$instance->__toString();
239 } elseif (!is_null(self::$instance)) {
241 throw new InvalidArgumentException(sprintf('self::instance[%s] is not expected.', gettype(self::$instance)), self::EXCEPTION_SELF_INSTANCE);
244 // Is it NULL, empty or an array?
245 if (is_null($args)) {
247 $argsString = 'NULL';
248 } elseif (is_array($args)) {
252 // Some arguments are there
253 foreach ($args as $arg) {
254 // Add data about the argument
255 $argsString .= gettype($arg) . ':';
258 // Found a NULL argument
259 $argsString .= 'NULL';
260 } elseif (is_string($arg)) {
261 // Add length for strings
262 $argsString .= strlen($arg);
263 } elseif ((is_int($arg)) || (is_float($arg))) {
266 } elseif (is_array($arg)) {
267 // .. or size if array
268 $argsString .= count($arg);
269 } elseif (is_object($arg)) {
271 $reflection = new ReflectionClass($arg);
273 // Is an other object, maybe no __toString() available
274 $argsString .= $reflection->getName();
275 } elseif ($arg === true) {
276 // ... is boolean 'true'
277 $argsString .= 'true';
278 } elseif ($arg === false) {
279 // ... is boolean 'false'
280 $argsString .= 'false';
283 // Comma for next one
288 if (substr($argsString, -2, 1) == ',') {
290 $argsString = substr($argsString, 0, -2);
297 // Output stub message
298 // @TODO __CLASS__ does always return BaseFrameworkSystem but not the extending (=child) class
299 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s::%s]: Stub! Args: %s',
310 * Getter for $realClass
312 * @return $realClass The name of the real class (not BaseFrameworkSystem)
314 public function __toString () {
315 return $this->realClass;
319 * Magic method to catch setting of missing but set class fields/attributes
321 * @param $name Name of the field/attribute
322 * @param $value Value to store
325 public final function __set (string $name, $value) {
326 $this->debugBackTrace(sprintf('Tried to set a missing field. name=%s, value[%s]=%s',
329 print_r($value, true)
334 * Magic method to catch getting of missing fields/attributes
336 * @param $name Name of the field/attribute
339 public final function __get (string $name) {
340 $this->debugBackTrace(sprintf('Tried to get a missing field. name=%s',
346 * Magic method to catch unsetting of missing fields/attributes
348 * @param $name Name of the field/attribute
351 public final function __unset (string $name) {
352 $this->debugBackTrace(sprintf('Tried to unset a missing field. name=%s',
358 * Magic method to catch object serialization
360 * @return $unsupported Unsupported method
361 * @throws UnsupportedOperationException Objects of this framework cannot be serialized
363 public final function __sleep () {
364 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
368 * Magic method to catch object deserialization
370 * @return $unsupported Unsupported method
371 * @throws UnsupportedOperationException Objects of this framework cannot be serialized
373 public final function __wakeup () {
374 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
378 * Magic method to catch calls when an object instance is called
380 * @return $unsupported Unsupported method
381 * @throws UnsupportedOperationException Objects of this framework cannot be serialized
383 public final function __invoke () {
384 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
388 * Setter for the real class name
390 * @param $realClass Class name (string)
393 public final function setRealClass (string $realClass) {
395 $this->realClass = $realClass;
399 * Setter for debug instance
401 * @param $debugInstance The instance for debug output class
404 public final function setDebugInstance (DebugMiddleware $debugInstance) {
405 GenericRegistry::getRegistry()->addInstance('debug', $debugInstance);
409 * Getter for debug instance
411 * @return $debugInstance Instance to class DebugConsoleOutput or DebugWebOutput
413 public final function getDebugInstance () {
414 // Get debug instance
415 $debugInstance = GenericRegistry::getRegistry()->getInstance('debug');
418 return $debugInstance;
422 * Setter for web output instance
424 * @param $webInstance The instance for web output class
427 public final function setWebOutputInstance (OutputStreamer $webInstance) {
428 GenericRegistry::getRegistry()->addInstance('web_output', $webInstance);
432 * Getter for web output instance
434 * @return $webOutputInstance - Instance to class WebOutput
436 public final function getWebOutputInstance () {
437 $webOutputInstance = GenericRegistry::getRegistry()->getInstance('web_output');
438 return $webOutputInstance;
442 * Setter for DatabaseWrapper instance
444 * @param $wrapperInstance An instance of an DatabaseWrapper
447 public final function setWrapperInstance (DatabaseWrapper $wrapperInstance) {
448 $this->wrapperInstance = $wrapperInstance;
452 * Getter for DatabaseWrapper instance
454 * @return $wrapperInstance An instance of an DatabaseWrapper
456 public final function getWrapperInstance () {
457 return $this->wrapperInstance;
461 * Setter for state instance
463 * @param $stateInstance A Stateable instance
466 public final function setStateInstance (Stateable $stateInstance) {
467 $this->stateInstance = $stateInstance;
471 * Getter for state instance
473 * @return $stateInstance A Stateable instance
475 public final function getStateInstance () {
476 return $this->stateInstance;
480 * Setter for call-back instance
482 * @param $callbackInstance An instance of a FrameworkInterface class
485 public final function setCallbackInstance (FrameworkInterface $callbackInstance) {
486 $this->callbackInstance = $callbackInstance;
490 * Getter for call-back instance
492 * @return $callbackInstance An instance of a FrameworkInterface class
494 protected final function getCallbackInstance () {
495 return $this->callbackInstance;
499 * Checks whether an object equals this object. You should overwrite this
500 * method to implement own equality checks
502 * @param $objectInstance An instance of a FrameworkInterface object
503 * @return $equals Whether both objects equals
505 public function equals (FrameworkInterface $objectInstance) {
508 $this->__toString() == $objectInstance->__toString()
510 $this->hashCode() == $objectInstance->hashCode()
518 * Generates a generic hash code of this class. You should really overwrite
519 * this method with your own hash code generator code. But keep KISS in mind.
521 * @return $hashCode A generic hash code respresenting this whole class
523 public function hashCode () {
525 return crc32($this->__toString());
529 * Appends a trailing slash to a string
531 * @param $str A string (maybe) without trailing slash
532 * @return $str A string with an auto-appended trailing slash
534 public final function addMissingTrailingSlash ($str) {
535 // Is there a trailing slash?
536 if (substr($str, -1, 1) != '/') {
540 // Return string with trailing slash
545 * Debugs this instance by putting out it's full content
547 * @param $message Optional message to show in debug output
550 public final function debugInstance ($message = '') {
551 // Restore the error handler to avoid trouble with missing array elements or undeclared variables
552 restore_error_handler();
558 if (!empty($message)) {
560 $content = sprintf('<div class="debug_message">
562 </div>' . PHP_EOL, $message);
565 // Generate the output
566 $content .= sprintf('<pre>%s</pre>',
575 ApplicationEntryPoint::exitApplication(sprintf('<div class="debug_header">
578 <div class="debug_content">
582 <div class="debug_include_list">
587 ClassLoader::getSelfInstance()->getPrintableIncludeList()
592 * Replaces control characters with printable output
594 * @param $str String with control characters
595 * @return $str Replaced string
597 protected function replaceControlCharacters ($str) {
600 chr(13), '[r]', str_replace(
601 chr(10), '[n]', str_replace(
611 * Output a partial stub message for the caller method
613 * @param $message An optional message to display
616 protected function partialStub ($message = '') {
618 $stubMessage = 'Partial stub!';
620 // Is an extra message given?
621 if (!empty($message)) {
622 // Then add it as well
623 $stubMessage .= ' Message: ' . $message;
626 // Debug instance is there?
627 if (!is_null($this->getDebugInstance())) {
628 // Output stub message
629 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput($stubMessage);
632 trigger_error($stubMessage);
638 * Outputs a debug backtrace and stops further script execution
640 * @param $message An optional message to output
641 * @param $doExit Whether exit the program (true is default)
644 public function debugBackTrace ($message = '', $doExit = true) {
645 // Sorry, there is no other way getting this nice backtrace
646 if (!empty($message)) {
648 printf('Message: %s<br />' . PHP_EOL, $message);
652 debug_print_backtrace();
656 if ($doExit === true) {
662 * Creates an instance of a debugger instance
664 * @param $className Name of the class (currently unsupported)
665 * @param $lineNumber Line number where the call was made
666 * @return $debugInstance An instance of a debugger class
667 * @deprecated Not fully, as the new Logger facilities are not finished yet.
669 public final static function createDebugInstance ($className, $lineNumber = NULL) {
670 // Is the instance set?
671 if (!GenericRegistry::getRegistry()->instanceExists('debug')) {
672 // Init debug instance
673 $debugInstance = NULL;
677 // Get a debugger instance
678 $debugInstance = DebugMiddleware::createDebugMiddleware(FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('debug_' . FrameworkBootstrap::getRequestTypeFromSystem() . '_class'), $className);
679 } catch (NullPointerException $e) {
680 // Didn't work, no instance there
681 exit(sprintf('Cannot create debugInstance! Exception=%s,message=%s,className=%s,lineNumber=%d' . PHP_EOL, $e->__toString(), $e->getMessage(), $className, $lineNumber));
684 // Empty string should be ignored and used for testing the middleware
685 DebugMiddleware::getSelfInstance()->output('');
687 // Set it in registry
688 GenericRegistry::getRegistry()->addInstance('debug', $debugInstance);
690 // Get instance from registry
691 $debugInstance = GenericRegistry::getRegistry()->getDebugInstance();
695 return $debugInstance;
699 * Simple output of a message with line-break
701 * @param $message Message to output
704 public function outputLine ($message) {
706 print($message . PHP_EOL);
710 * Outputs a debug message whether to debug instance (should be set!) or
711 * dies with or ptints the message. Do NEVER EVER rewrite the exit() call to
712 * ApplicationEntryPoint::app_exit(), this would cause an endless loop.
714 * @param $message Message we shall send out...
715 * @param $doPrint Whether print or die here (default: print)
716 * @paran $stripTags Whether to strip tags (default: false)
719 public function debugOutput ($message, $doPrint = true, $stripTags = false) {
720 // Set debug instance to NULL
721 $debugInstance = NULL;
724 $backtrace = debug_backtrace(!DEBUG_BACKTRACE_PROVIDE_OBJECT);
726 // Is function partialStub/__callStatic ?
727 if (in_array($backtrace[1]['function'], array('partialStub', '__call', '__callStatic'))) {
728 // Prepend class::function:line from 3rd element
729 $message = sprintf('[%s::%s:%d]: %s',
730 $backtrace[2]['class'],
731 $backtrace[2]['function'],
732 (isset($backtrace[2]['line']) ? $backtrace[2]['line'] : '0'),
736 // Prepend class::function:line from 2nd element
737 $message = sprintf('[%s::%s:%d]: %s',
738 $backtrace[1]['class'],
739 $backtrace[1]['function'],
740 (isset($backtrace[1]['line']) ? $backtrace[1]['line'] : '0'),
747 // Get debug instance
748 $debugInstance = $this->getDebugInstance();
749 } catch (NullPointerException $e) {
750 // The debug instance is not set (yet)
753 // Is the debug instance there?
754 if (is_object($debugInstance)) {
755 // Use debug output handler
756 $debugInstance->output($message, $stripTags);
758 if ($doPrint === false) {
759 // Die here if not printed
763 // Are debug times enabled?
764 if (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('debug_' . FrameworkBootstrap::getRequestTypeFromSystem() . '_output_timings') == 'Y') {
766 $message = $this->getPrintableExecutionTime() . $message;
770 if ($doPrint === true) {
772 $this->outputLine($message);
781 * Marks up the code by adding e.g. line numbers
783 * @param $phpCode Unmarked PHP code
784 * @return $markedCode Marked PHP code
786 public function markupCode ($phpCode) {
791 $errorArray = error_get_last();
793 // Init the code with error message
794 if (is_array($errorArray)) {
796 $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>',
797 basename($errorArray['file']),
799 $errorArray['message'],
804 // Add line number to the code
805 foreach (explode(chr(10), $phpCode) as $lineNo => $code) {
807 $markedCode .= sprintf('<span id="code_line">%s</span>: %s' . PHP_EOL,
809 htmlentities($code, ENT_QUOTES)
818 * "Getter" for databse entry
820 * @return $entry An array with database entries
821 * @throws NullPointerException If the database result is not found
822 * @throws InvalidDatabaseResultException If the database result is invalid
823 * @todo Monolithic method, should be moved to proper classes
825 protected final function getDatabaseEntry () {
826 // Is there an instance?
827 if (!$this->getResultInstance() instanceof SearchableResult) {
828 // Throw an exception here
829 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
833 $this->getResultInstance()->rewind();
835 // Do we have an entry?
836 if ($this->getResultInstance()->valid() === false) {
837 // @TODO Move the constant to e.g. BaseDatabaseResult when there is a non-cached database result available
838 throw new InvalidDatabaseResultException(array($this, $this->getResultInstance()), CachedDatabaseResult::EXCEPTION_INVALID_DATABASE_RESULT);
842 $this->getResultInstance()->next();
845 $entry = $this->getResultInstance()->current();
852 * Getter for field name
854 * @param $fieldName Field name which we shall get
855 * @return $fieldValue Field value from the user
856 * @throws NullPointerException If the result instance is null
858 public final function getField (string $fieldName) {
859 // Default field value
862 // Get result instance
863 $resultInstance = $this->getResultInstance();
865 // Is this instance null?
866 if (is_null($resultInstance)) {
867 // Then the user instance is no longer valid (expired cookies?)
868 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
872 $fieldArray = $resultInstance->current();
873 //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput($fieldName.':<pre>'.print_r($fieldArray, true).'</pre>');
875 // Convert dashes to underscore
876 $fieldName2 = StringUtils::convertDashesToUnderscores($fieldName);
878 // Does the field exist?
879 if ($this->isFieldSet($fieldName)) {
881 $fieldValue = $fieldArray[$fieldName2];
882 } elseif (defined('DEVELOPER')) {
883 // Missing field entry, may require debugging
884 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']:fieldArray<pre>=' . print_r($fieldArray, true) . '</pre>,fieldName=' . $fieldName . ' not found!');
886 // Missing field entry, may require debugging
887 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']:fieldName=' . $fieldName . ' not found!');
895 * Checks if given field is set
897 * @param $fieldName Field name to check
898 * @return $isSet Whether the given field name is set
899 * @throws NullPointerException If the result instance is null
901 public function isFieldSet (string $fieldName) {
902 // Get result instance
903 $resultInstance = $this->getResultInstance();
905 // Is this instance null?
906 if (is_null($resultInstance)) {
907 // Then the user instance is no longer valid (expired cookies?)
908 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
912 $fieldArray = $resultInstance->current();
913 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('[' . $this->__toString() . ':' . __LINE__ . '] fieldName=' . $fieldName . ',fieldArray=<pre>'.print_r($fieldArray, true).'</pre>');
915 // Convert dashes to underscore
916 $fieldName = StringUtils::convertDashesToUnderscores($fieldName);
919 $isSet = isset($fieldArray[$fieldName]);
926 * Outputs a deprecation warning to the developer.
928 * @param $message The message we shall output to the developer
930 * @todo Write a logging mechanism for productive mode
932 public function deprecationWarning ($message) {
933 // Is developer mode active?
934 if (defined('DEVELOPER')) {
935 // Debug instance is there?
936 if (!is_null($this->getDebugInstance())) {
937 // Output stub message
938 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput($message);
941 trigger_error($message . "<br />\n");
945 // @TODO Finish this part!
946 $this->partialStub('Developer mode inactive. Message:' . $message);
951 * Checks whether the given PHP extension is loaded
953 * @param $phpExtension The PHP extension we shall check
954 * @return $isLoaded Whether the PHP extension is loaded
956 public final function isPhpExtensionLoaded ($phpExtension) {
958 $isLoaded = in_array($phpExtension, get_loaded_extensions());
965 * "Getter" as a time() replacement but with milliseconds. You should use this
966 * method instead of the encapsulated getimeofday() function.
968 * @return $milliTime Timestamp with milliseconds
970 public function getMilliTime () {
971 // Get the time of day as float
972 $milliTime = gettimeofday(true);
979 * Idles (sleeps) for given milliseconds
981 * @return $hasSlept Whether it goes fine
983 public function idle ($milliSeconds) {
984 // Sleep is fine by default
987 // Idle so long with found function
988 if (function_exists('time_sleep_until')) {
989 // Get current time and add idle time
990 $sleepUntil = $this->getMilliTime() + abs($milliSeconds) / 1000;
992 // New PHP 5.1.0 function found, ignore errors
993 $hasSlept = @time_sleep_until($sleepUntil);
996 * My Sun station doesn't have that function even with latest PHP
999 usleep($milliSeconds * 1000);
1007 * Checks whether the given encoded data was encoded with Base64
1009 * @param $encodedData Encoded data we shall check
1010 * @return $isBase64 Whether the encoded data is Base64
1012 protected function isBase64Encoded ($encodedData) {
1014 $isBase64 = (@base64_decode($encodedData, true) !== false);
1021 * Gets a cache key from Criteria instance
1023 * @param $criteriaInstance An instance of a Criteria class
1024 * @param $onlyKeys Only use these keys for a cache key
1025 * @return $cacheKey A cache key suitable for lookup/storage purposes
1027 protected function getCacheKeyByCriteria (Criteria $criteriaInstance, array $onlyKeys = []) {
1029 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FRAMEWORK-SYSTEM: criteriaInstance=' . $criteriaInstance->__toString() . ',onlyKeys()=' . count($onlyKeys) . ' - CALLED!');
1030 $cacheKey = sprintf('%s@%s',
1031 $this->__toString(),
1032 $criteriaInstance->getCacheKey($onlyKeys)
1036 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FRAMEWORK-SYSTEM: cacheKey=' . $cacheKey . ' - EXIT!');
1041 * Getter for startup time in miliseconds
1043 * @return $startupTime Startup time in miliseconds
1045 protected function getStartupTime () {
1046 return self::$startupTime;
1050 * "Getter" for a printable currently execution time in nice braces
1052 * @return $executionTime Current execution time in nice braces
1054 protected function getPrintableExecutionTime () {
1055 // Caculate the execution time
1056 $executionTime = microtime(true) - $this->getStartupTime();
1058 // Pack it in nice braces
1059 $executionTime = sprintf('[ %01.5f ] ', $executionTime);
1062 return $executionTime;
1066 * Hashes a given string with a simple but stronger hash function (no salt)
1067 * and hex-encode it.
1069 * @param $str The string to be hashed
1070 * @return $hash The hash from string $str
1072 public static final function hash ($str) {
1073 // Hash given string with (better secure) hasher
1074 $hash = bin2hex(mhash(MHASH_SHA256, $str));
1081 * "Getter" for length of hash() output. This will be "cached" to speed up
1084 * @return $length Length of hash() output
1086 public static final function getHashLength () {
1088 if (is_null(self::$hashLength)) {
1089 // No, then hash a string and save its length.
1090 self::$hashLength = strlen(self::hash('abc123'));
1094 return self::$hashLength;
1098 * Checks whether the given number is really a number (only chars 0-9).
1100 * @param $num A string consisting only chars between 0 and 9
1101 * @param $castValue Whether to cast the value to double. Do only use this to secure numbers from Requestable classes.
1102 * @param $assertMismatch Whether to assert mismatches
1103 * @return $ret The (hopefully) secured numbered value
1105 public function bigintval ($num, $castValue = true, $assertMismatch = false) {
1106 // Filter all numbers out
1107 $ret = preg_replace('/[^0123456789]/', '', $num);
1110 if ($castValue === true) {
1111 // Cast to biggest numeric type
1112 $ret = (double) $ret;
1115 // Assert only if requested
1116 if ($assertMismatch === true) {
1117 // Has the whole value changed?
1118 assert(('' . $ret . '' != '' . $num . '') && (!is_null($num)));
1126 * Checks whether the given hexadecimal number is really a hex-number (only chars 0-9,a-f).
1128 * @param $num A string consisting only chars between 0 and 9
1129 * @param $assertMismatch Whether to assert mismatches
1130 * @return $ret The (hopefully) secured hext-numbered value
1132 public function hexval ($num, $assertMismatch = false) {
1133 // Filter all numbers out
1134 $ret = preg_replace('/[^0123456789abcdefABCDEF]/', '', $num);
1136 // Assert only if requested
1137 if ($assertMismatch === true) {
1138 // Has the whole value changed?
1139 assert(('' . $ret . '' != '' . $num . '') && (!is_null($num)));
1147 * Determines if an element is set in the generic array
1149 * @param $keyGroup Main group for the key
1150 * @param $subGroup Sub group for the key
1151 * @param $key Key to check
1152 * @param $element Element to check
1153 * @return $isset Whether the given key is set
1155 protected final function isGenericArrayElementSet ($keyGroup, $subGroup, $key, $element) {
1157 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element);
1160 $isset = isset($this->genericArray[$keyGroup][$subGroup][$key][$element]);
1166 * Determines if a key is set in the generic array
1168 * @param $keyGroup Main group for the key
1169 * @param $subGroup Sub group for the key
1170 * @param $key Key to check
1171 * @return $isset Whether the given key is set
1173 protected final function isGenericArrayKeySet ($keyGroup, $subGroup, $key) {
1175 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1178 $isset = isset($this->genericArray[$keyGroup][$subGroup][$key]);
1186 * Determines if a group is set in the generic array
1188 * @param $keyGroup Main group
1189 * @param $subGroup Sub group
1190 * @return $isset Whether the given group is set
1192 protected final function isGenericArrayGroupSet ($keyGroup, $subGroup) {
1194 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup);
1197 $isset = isset($this->genericArray[$keyGroup][$subGroup]);
1204 * Getter for sub key group
1206 * @param $keyGroup Main key group
1207 * @param $subGroup Sub key group
1208 * @return $array An array with all array elements
1210 protected final function getGenericSubArray ($keyGroup, $subGroup) {
1212 if (!$this->isGenericArrayGroupSet($keyGroup, $subGroup)) {
1213 // No, then abort here
1214 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' not found.');
1219 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',value=' . print_r($this->genericArray[$keyGroup][$subGroup], true));
1222 return $this->genericArray[$keyGroup][$subGroup];
1226 * Unsets a given key in generic array
1228 * @param $keyGroup Main group for the key
1229 * @param $subGroup Sub group for the key
1230 * @param $key Key to unset
1233 protected final function unsetGenericArrayKey ($keyGroup, $subGroup, $key) {
1235 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1238 unset($this->genericArray[$keyGroup][$subGroup][$key]);
1242 * Unsets a given element in generic array
1244 * @param $keyGroup Main group for the key
1245 * @param $subGroup Sub group for the key
1246 * @param $key Key to unset
1247 * @param $element Element to unset
1250 protected final function unsetGenericArrayElement ($keyGroup, $subGroup, $key, $element) {
1252 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element);
1255 unset($this->genericArray[$keyGroup][$subGroup][$key][$element]);
1259 * Append a string to a given generic array key
1261 * @param $keyGroup Main group for the key
1262 * @param $subGroup Sub group for the key
1263 * @param $key Key to unset
1264 * @param $value Value to add/append
1267 protected final function appendStringToGenericArrayKey ($keyGroup, $subGroup, $key, $value, $appendGlue = '') {
1269 //* 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);
1271 // Is it already there?
1272 if ($this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
1274 $this->genericArray[$keyGroup][$subGroup][$key] .= $appendGlue . (string) $value;
1277 $this->genericArray[$keyGroup][$subGroup][$key] = (string) $value;
1282 * Append a string to a given generic array element
1284 * @param $keyGroup Main group for the key
1285 * @param $subGroup Sub group for the key
1286 * @param $key Key to unset
1287 * @param $element Element to check
1288 * @param $value Value to add/append
1291 protected final function appendStringToGenericArrayElement ($keyGroup, $subGroup, $key, $element, $value, $appendGlue = '') {
1293 //* 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);
1295 // Is it already there?
1296 if ($this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element)) {
1298 $this->genericArray[$keyGroup][$subGroup][$key][$element] .= $appendGlue . (string) $value;
1301 $this->setStringGenericArrayElement($keyGroup, $subGroup, $key, $element, $value);
1306 * Sets a string in a given generic array element
1308 * @param $keyGroup Main group for the key
1309 * @param $subGroup Sub group for the key
1310 * @param $key Key to unset
1311 * @param $element Element to check
1312 * @param $value Value to add/append
1315 protected final function setStringGenericArrayElement ($keyGroup, $subGroup, $key, $element, $value, $appendGlue = '') {
1317 //* 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);
1320 $this->genericArray[$keyGroup][$subGroup][$key][$element] = (string) $value;
1324 * Initializes given generic array group
1326 * @param $keyGroup Main group for the key
1327 * @param $subGroup Sub group for the key
1328 * @param $key Key to use
1329 * @param $forceInit Optionally force initialization
1332 protected final function initGenericArrayGroup ($keyGroup, $subGroup, $forceInit = false) {
1334 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',forceInit=' . intval($forceInit));
1336 // Is it already set?
1337 if (($forceInit === false) && ($this->isGenericArrayGroupSet($keyGroup, $subGroup))) {
1338 // Already initialized
1339 trigger_error(__METHOD__ . ':keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' already initialized.');
1344 $this->genericArray[$keyGroup][$subGroup] = [];
1348 * Initializes given generic array key
1350 * @param $keyGroup Main group for the key
1351 * @param $subGroup Sub group for the key
1352 * @param $key Key to use
1353 * @param $forceInit Optionally force initialization
1356 protected final function initGenericArrayKey ($keyGroup, $subGroup, $key, $forceInit = false) {
1358 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',forceInit=' . intval($forceInit));
1360 // Is it already set?
1361 if (($forceInit === false) && ($this->isGenericArrayKeySet($keyGroup, $subGroup, $key))) {
1362 // Already initialized
1363 trigger_error(__METHOD__ . ':keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' already initialized.');
1368 $this->genericArray[$keyGroup][$subGroup][$key] = [];
1372 * Initializes given generic array element
1374 * @param $keyGroup Main group for the key
1375 * @param $subGroup Sub group for the key
1376 * @param $key Key to use
1377 * @param $element Element to use
1378 * @param $forceInit Optionally force initialization
1381 protected final function initGenericArrayElement ($keyGroup, $subGroup, $key, $element, $forceInit = false) {
1383 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element . ',forceInit=' . intval($forceInit));
1385 // Is it already set?
1386 if (($forceInit === false) && ($this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element))) {
1387 // Already initialized
1388 trigger_error(__METHOD__ . ':keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element . ' already initialized.');
1393 $this->genericArray[$keyGroup][$subGroup][$key][$element] = [];
1397 * Pushes an element to a generic key
1399 * @param $keyGroup Main group for the key
1400 * @param $subGroup Sub group for the key
1401 * @param $key Key to use
1402 * @param $value Value to add/append
1403 * @return $count Number of array elements
1405 protected final function pushValueToGenericArrayKey ($keyGroup, $subGroup, $key, $value) {
1407 //* NOISY-DEBUG: */ if (!is_object($value)) $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',value[' . gettype($value) . ']=' . print_r($value, true));
1410 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
1412 $this->initGenericArrayKey($keyGroup, $subGroup, $key);
1416 $count = array_push($this->genericArray[$keyGroup][$subGroup][$key], $value);
1419 //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], true));
1420 //* DEBUG: */ print(__METHOD__ . ': count=' . $count . PHP_EOL);
1425 * Pushes an element to a generic array element
1427 * @param $keyGroup Main group for the key
1428 * @param $subGroup Sub group for the key
1429 * @param $key Key to use
1430 * @param $element Element to check
1431 * @param $value Value to add/append
1432 * @return $count Number of array elements
1434 protected final function pushValueToGenericArrayElement ($keyGroup, $subGroup, $key, $element, $value) {
1436 //* 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));
1439 if (!$this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element)) {
1441 $this->initGenericArrayElement($keyGroup, $subGroup, $key, $element);
1445 $count = array_push($this->genericArray[$keyGroup][$subGroup][$key][$element], $value);
1448 //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], true));
1449 //* DEBUG: */ print(__METHOD__ . ': count=' . $count . PHP_EOL);
1454 * Pops an element from a generic group
1456 * @param $keyGroup Main group for the key
1457 * @param $subGroup Sub group for the key
1458 * @param $key Key to unset
1459 * @return $value Last "popped" value
1461 protected final function popGenericArrayElement ($keyGroup, $subGroup, $key) {
1463 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1466 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
1468 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' not found.');
1473 $value = array_pop($this->genericArray[$keyGroup][$subGroup][$key]);
1476 //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], true));
1477 //* DEBUG: */ print(__METHOD__ . ': value[' . gettype($value) . ']=' . print_r($value, true) . PHP_EOL);
1482 * Shifts an element from a generic group
1484 * @param $keyGroup Main group for the key
1485 * @param $subGroup Sub group for the key
1486 * @param $key Key to unset
1487 * @return $value Last "popped" value
1489 protected final function shiftGenericArrayElement ($keyGroup, $subGroup, $key) {
1491 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1494 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
1496 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' not found.');
1501 $value = array_shift($this->genericArray[$keyGroup][$subGroup][$key]);
1504 //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], true));
1505 //* DEBUG: */ print(__METHOD__ . ': value[' . gettype($value) . ']=' . print_r($value, true) . PHP_EOL);
1510 * Count generic array group
1512 * @param $keyGroup Main group for the key
1513 * @return $count Count of given group
1515 protected final function countGenericArray ($keyGroup) {
1517 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup);
1520 if (!isset($this->genericArray[$keyGroup])) {
1522 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ' not found.');
1527 $count = count($this->genericArray[$keyGroup]);
1530 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',count=' . $count);
1537 * Count generic array sub group
1539 * @param $keyGroup Main group for the key
1540 * @param $subGroup Sub group for the key
1541 * @return $count Count of given group
1543 protected final function countGenericArrayGroup ($keyGroup, $subGroup) {
1545 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup);
1548 if (!$this->isGenericArrayGroupSet($keyGroup, $subGroup)) {
1550 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' not found.');
1555 $count = count($this->genericArray[$keyGroup][$subGroup]);
1558 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',count=' . $count);
1565 * Count generic array elements
1567 * @param $keyGroup Main group for the key
1568 * @param $subGroup Sub group for the key
1569 * @para $key Key to count
1570 * @return $count Count of given key
1572 protected final function countGenericArrayElements ($keyGroup, $subGroup, $key) {
1574 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1577 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
1579 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' not found.');
1581 } elseif (!$this->isValidGenericArrayGroup($keyGroup, $subGroup)) {
1583 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' is not an array.');
1588 $count = count($this->genericArray[$keyGroup][$subGroup][$key]);
1591 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',count=' . $count);
1598 * Getter for whole generic group array
1600 * @param $keyGroup Key group to get
1601 * @return $array Whole generic array group
1603 protected final function getGenericArray ($keyGroup) {
1605 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup);
1608 if (!isset($this->genericArray[$keyGroup])) {
1610 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ' does not exist.');
1615 return $this->genericArray[$keyGroup];
1619 * Setter for generic array key
1621 * @param $keyGroup Key group to get
1622 * @param $subGroup Sub group for the key
1623 * @param $key Key to unset
1624 * @param $value Mixed value from generic array element
1627 protected final function setGenericArrayKey ($keyGroup, $subGroup, $key, $value) {
1629 //* NOISY-DEBUG: */ if (!is_object($value)) $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',value[' . gettype($value) . ']=' . print_r($value, true));
1632 $this->genericArray[$keyGroup][$subGroup][$key] = $value;
1636 * Getter for generic array key
1638 * @param $keyGroup Key group to get
1639 * @param $subGroup Sub group for the key
1640 * @param $key Key to unset
1641 * @return $value Mixed value from generic array element
1643 protected final function getGenericArrayKey ($keyGroup, $subGroup, $key) {
1645 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1648 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
1650 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' does not exist.');
1655 return $this->genericArray[$keyGroup][$subGroup][$key];
1659 * Sets a value in given generic array key/element
1661 * @param $keyGroup Main group for the key
1662 * @param $subGroup Sub group for the key
1663 * @param $key Key to set
1664 * @param $element Element to set
1665 * @param $value Value to set
1668 protected final function setGenericArrayElement ($keyGroup, $subGroup, $key, $element, $value) {
1670 //* 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));
1673 $this->genericArray[$keyGroup][$subGroup][$key][$element] = $value;
1677 * Getter for generic array element
1679 * @param $keyGroup Key group to get
1680 * @param $subGroup Sub group for the key
1681 * @param $key Key to look for
1682 * @param $element Element to look for
1683 * @return $value Mixed value from generic array element
1685 protected final function getGenericArrayElement ($keyGroup, $subGroup, $key, $element) {
1687 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element);
1690 if (!$this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element)) {
1692 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element . ' does not exist.');
1697 return $this->genericArray[$keyGroup][$subGroup][$key][$element];
1701 * Checks if a given sub group is valid (array)
1703 * @param $keyGroup Key group to get
1704 * @param $subGroup Sub group for the key
1705 * @return $isValid Whether given sub group is valid
1707 protected final function isValidGenericArrayGroup ($keyGroup, $subGroup) {
1709 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup);
1712 $isValid = (($this->isGenericArrayGroupSet($keyGroup, $subGroup)) && (is_array($this->getGenericSubArray($keyGroup, $subGroup))));
1719 * Checks if a given key is valid (array)
1721 * @param $keyGroup Key group to get
1722 * @param $subGroup Sub group for the key
1723 * @param $key Key to check
1724 * @return $isValid Whether given sub group is valid
1726 protected final function isValidGenericArrayKey ($keyGroup, $subGroup, $key) {
1728 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1731 $isValid = (($this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) && (is_array($this->getGenericArrayKey($keyGroup, $subGroup, $key))));
1738 * Initializes the web output instance
1742 protected function initWebOutputInstance () {
1743 // Get application instance
1744 $applicationInstance = GenericRegistry::getRegistry()->getInstance('application');
1746 // Init web output instance
1747 $outputInstance = ObjectFactory::createObjectByConfiguredName('output_class', array($applicationInstance));
1750 $this->setWebOutputInstance($outputInstance);
1754 * Translates boolean true to 'Y' and false to 'N'
1756 * @param $boolean Boolean value
1757 * @return $translated Translated boolean value
1759 public static final function translateBooleanToYesNo (bool $boolean) {
1760 // Make sure it is really boolean
1761 assert(is_bool($boolean));
1764 $translated = ($boolean === true) ? 'Y' : 'N';
1766 // ... and return it
1771 * Creates a full-qualified file name (FQFN) for given file name by adding
1772 * a configured temporary file path to it.
1774 * @param $infoInstance An instance of a SplFileInfo class
1775 * @return $tempInstance An instance of a SplFileInfo class (temporary file)
1776 * @throw PathWriteProtectedException If the path in 'temp_file_path' is write-protected
1777 * @throws FileIoException If the file cannot be written
1779 protected static function createTempPathForFile (SplFileInfo $infoInstance) {
1781 $basePath = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('temp_file_path');
1783 // Is the path writeable?
1784 if (!is_writable($basePath)) {
1785 // Path is write-protected
1786 throw new PathWriteProtectedException($infoInstance, self::EXCEPTION_PATH_CANNOT_BE_WRITTEN);
1790 $tempInstance = new SplFileInfo($basePath . DIRECTORY_SEPARATOR . $infoInstance->getBasename());
1793 if (!FrameworkBootstrap::isReachableFilePath($tempInstance)) {
1795 throw new FileIoException($tempInstance, self::EXCEPTION_FILE_NOT_REACHABLE);
1799 return $tempInstance;
1803 * "Getter" for a printable state name
1805 * @return $stateName Name of the node's state in a printable format
1807 public final function getPrintableState () {
1808 // Default is 'null'
1809 $stateName = 'null';
1811 // Get the state instance
1812 $stateInstance = $this->getStateInstance();
1814 // Is it an instance of Stateable?
1815 if ($stateInstance instanceof Stateable) {
1816 // Then use that state name
1817 $stateName = $stateInstance->getStateName();