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\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\Loader\ClassLoader;
15 use Org\Mxchange\CoreFramework\Manager\ManageableApplication;
16 use Org\Mxchange\CoreFramework\Middleware\Debug\DebugMiddleware;
17 use Org\Mxchange\CoreFramework\Registry\GenericRegistry;
18 use Org\Mxchange\CoreFramework\Result\Database\CachedDatabaseResult;
19 use Org\Mxchange\CoreFramework\State\Stateable;
20 use Org\Mxchange\CoreFramework\Stream\Output\OutputStreamer;
21 use Org\Mxchange\CoreFramework\Utils\String\StringUtils;
25 use \InvalidArgumentException;
30 * The simulator system class is the super class of all other classes. This
31 * class handles saving of games etc.
33 * @author Roland Haeder <webmaster@shipsimu.org>
35 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2020 Core Developer Team
36 * @license GNU GPL 3.0 or any newer version
37 * @link http://www.shipsimu.org
39 * This program is free software: you can redistribute it and/or modify
40 * it under the terms of the GNU General Public License as published by
41 * the Free Software Foundation, either version 3 of the License, or
42 * (at your option) any later version.
44 * This program is distributed in the hope that it will be useful,
45 * but WITHOUT ANY WARRANTY; without even the implied warranty of
46 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
47 * GNU General Public License for more details.
49 * You should have received a copy of the GNU General Public License
50 * along with this program. If not, see <http://www.gnu.org/licenses/>.
52 abstract class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
54 * Length of output from hash()
56 private static $hashLength = NULL;
59 * Self-referencing instance
61 private static $selfInstance = NULL;
66 private $realClass = __CLASS__;
71 private $callbackInstance = NULL;
76 private $genericArray = [];
78 /***********************
79 * Exception codes.... *
80 ***********************/
82 // @todo Try to clean these constants up
83 const EXCEPTION_IS_NULL_POINTER = 0x001;
84 const EXCEPTION_IS_NO_OBJECT = 0x002;
85 const EXCEPTION_IS_NO_ARRAY = 0x003;
86 const EXCEPTION_MISSING_METHOD = 0x004;
87 const EXCEPTION_CLASSES_NOT_MATCHING = 0x005;
88 const EXCEPTION_INDEX_OUT_OF_BOUNDS = 0x006;
89 const EXCEPTION_DIMENSION_ARRAY_INVALID = 0x007;
90 const EXCEPTION_ITEM_NOT_TRADEABLE = 0x008;
91 const EXCEPTION_ITEM_NOT_IN_PRICE_LIST = 0x009;
92 const EXCEPTION_GENDER_IS_WRONG = 0x00a;
93 const EXCEPTION_BIRTH_DATE_IS_INVALID = 0x00b;
94 const EXCEPTION_EMPTY_STRUCTURES_ARRAY = 0x00c;
95 const EXCEPTION_HAS_ALREADY_PERSONELL_LIST = 0x00d;
96 const EXCEPTION_NOT_ENOUGTH_UNEMPLOYEES = 0x00e;
97 const EXCEPTION_TOTAL_PRICE_NOT_CALCULATED = 0x00f;
98 const EXCEPTION_HARBOR_HAS_NO_SHIPYARDS = 0x010;
99 const EXCEPTION_CONTRACT_PARTNER_INVALID = 0x011;
100 const EXCEPTION_CONTRACT_PARTNER_MISMATCH = 0x012;
101 const EXCEPTION_CONTRACT_ALREADY_SIGNED = 0x013;
102 const EXCEPTION_UNEXPECTED_EMPTY_STRING = 0x014;
103 const EXCEPTION_PATH_NOT_FOUND = 0x015;
104 const EXCEPTION_INVALID_PATH_NAME = 0x016;
105 const EXCEPTION_READ_PROTECED_PATH = 0x017;
106 const EXCEPTION_WRITE_PROTECED_PATH = 0x018;
107 const EXCEPTION_DIR_POINTER_INVALID = 0x019;
108 const EXCEPTION_FILE_POINTER_INVALID = 0x01a;
109 const EXCEPTION_INVALID_RESOURCE = 0x01b;
110 const EXCEPTION_UNEXPECTED_OBJECT = 0x01c;
111 const EXCEPTION_LIMIT_ELEMENT_IS_UNSUPPORTED = 0x01d;
112 const EXCEPTION_GETTER_IS_MISSING = 0x01e;
113 const EXCEPTION_ARRAY_EXPECTED = 0x01f;
114 const EXCEPTION_ARRAY_HAS_INVALID_COUNT = 0x020;
115 const EXCEPTION_ID_IS_INVALID_FORMAT = 0x021;
116 const EXCEPTION_MD5_CHECKSUMS_MISMATCH = 0x022;
117 const EXCEPTION_UNEXPECTED_STRING_SIZE = 0x023;
118 const EXCEPTION_SIMULATOR_ID_INVALID = 0x024;
119 const EXCEPTION_MISMATCHING_COMPRESSORS = 0x025;
120 const EXCEPTION_CONTAINER_ITEM_IS_NULL = 0x026;
121 const EXCEPTION_ITEM_IS_NO_ARRAY = 0x027;
122 const EXCEPTION_CONTAINER_MAYBE_DAMAGED = 0x028;
123 const EXCEPTION_INVALID_STRING = 0x029;
124 const EXCEPTION_VARIABLE_NOT_SET = 0x02a;
125 const EXCEPTION_ATTRIBUTES_ARE_MISSING = 0x02b;
126 const EXCEPTION_ARRAY_ELEMENTS_MISSING = 0x02c;
127 const EXCEPTION_TEMPLATE_ENGINE_UNSUPPORTED = 0x02d;
128 const EXCEPTION_UNSPPORTED_OPERATION = 0x02e;
129 const EXCEPTION_FACTORY_REQUIRE_PARAMETER = 0x02f;
130 const EXCEPTION_MISSING_ELEMENT = 0x030;
131 const EXCEPTION_HEADERS_ALREADY_SENT = 0x031;
132 const EXCEPTION_DEFAULT_CONTROLLER_GONE = 0x032;
133 const EXCEPTION_CLASS_NOT_FOUND = 0x033;
134 const EXCEPTION_REQUIRED_INTERFACE_MISSING = 0x034;
135 const EXCEPTION_FATAL_ERROR = 0x035;
136 const EXCEPTION_FILE_NOT_FOUND = 0x036;
137 const EXCEPTION_ASSERTION_FAILED = 0x037;
138 const EXCEPTION_FILE_NOT_REACHABLE = 0x038;
139 const EXCEPTION_FILE_CANNOT_BE_READ = 0x039;
140 const EXCEPTION_FILE_CANNOT_BE_WRITTEN = 0x03a;
141 const EXCEPTION_PATH_CANNOT_BE_WRITTEN = 0x03b;
142 const EXCEPTION_DATABASE_UPDATED_NOT_ALLOWED = 0x03c;
143 const EXCEPTION_FILTER_CHAIN_INTERCEPTED = 0x03d;
144 const EXCEPTION_INVALID_SOCKET = 0x03e;
145 const EXCEPTION_SELF_INSTANCE = 0x03f;
148 * Startup time in miliseconds
150 private static $startupTime = 0;
153 * Protected super constructor
155 * @param $className Name of the class
158 protected function __construct (string $className) {
160 $this->setRealClass($className);
162 // Is the startup time set? (0 cannot be true anymore)
163 if (self::$startupTime == 0) {
165 self::$startupTime = microtime(true);
170 * Destructor for all classes. You should not call this method on your own.
174 public function __destruct () {
175 // Is this object already destroyed?
176 if ($this->__toString() != 'DestructedObject') {
177 // Destroy all informations about this class but keep some text about it alive
178 $this->setRealClass('DestructedObject');
179 } elseif ((defined('DEBUG_DESTRUCTOR')) && (is_object($this->getDebugInstance()))) {
180 // Already destructed object
181 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('The object <span class="object_name">%s</span> is already destroyed.',
185 // Do not call this twice
186 trigger_error(__METHOD__ . ': Called twice.');
192 * The __call() method where all non-implemented methods end up
194 * @param $methodName Name of the missing method
195 * @args $args Arguments passed to the method
198 public final function __call (string $methodName, array $args = NULL) {
200 self::$selfInstance = $this;
202 // Call static method
203 self::__callStatic($methodName, $args);
205 // Clear self-instance
206 self::$selfInstance = NULL;
210 * The __callStatic() method where all non-implemented static methods end up
212 * @param $methodName Name of the missing method
213 * @param $args Arguments passed to the method
215 * @throws InvalidArgumentException If self::$selfInstance is not a framework's own object
217 public static final function __callStatic (string $methodName, array $args = NULL) {
218 // Init argument string and class name
219 //* PRINT-DEBUG: */ printf('[%s:%d]: methodName=%s,args[]=%s - CALLED!' . PHP_EOL, __METHOD__, __LINE__, $methodName, gettype($args));
221 $className = 'unknown';
223 // Is self-instance set?
224 if (self::$selfInstance instanceof FrameworkInterface) {
225 // Framework's own instance
226 $className = self::$selfInstance->__toString();
227 } elseif (!is_null(self::$selfInstance)) {
229 throw new InvalidArgumentException(sprintf('self::instance[%s] is not expected.', gettype(self::$selfInstance)), self::EXCEPTION_SELF_INSTANCE);
232 // Is it NULL, empty or an array?
233 if (is_null($args)) {
235 $argsString = 'NULL';
236 } elseif (is_array($args)) {
240 // Some arguments are there
241 foreach ($args as $arg) {
242 // Add data about the argument
243 $argsString .= gettype($arg) . ':';
246 // Found a NULL argument
247 $argsString .= 'NULL';
248 } elseif (is_string($arg)) {
249 // Add length for strings
250 $argsString .= strlen($arg);
251 } elseif ((is_int($arg)) || (is_float($arg))) {
254 } elseif (is_array($arg)) {
255 // .. or size if array
256 $argsString .= count($arg);
257 } elseif (is_object($arg)) {
259 $reflection = new ReflectionClass($arg);
261 // Is an other object, maybe no __toString() available
262 $argsString .= $reflection->getName();
263 } elseif ($arg === true) {
264 // ... is boolean 'true'
265 $argsString .= 'true';
266 } elseif ($arg === false) {
267 // ... is boolean 'false'
268 $argsString .= 'false';
271 // Comma for next one
276 if (substr($argsString, -2, 1) == ',') {
278 $argsString = substr($argsString, 0, -2);
285 // Output stub message
286 // @TODO __CLASS__ does always return BaseFrameworkSystem but not the extending (=child) class
287 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s::%s]: Stub! Args: %s',
298 * Getter for $realClass
300 * @return $realClass The name of the real class (not BaseFrameworkSystem)
302 public function __toString () {
303 return $this->realClass;
307 * Magic method to catch setting of missing but set class fields/attributes
309 * @param $name Name of the field/attribute
310 * @param $value Value to store
313 public final function __set (string $name, $value) {
314 $this->debugBackTrace(sprintf('Tried to set a missing field. name=%s, value[%s]=%s',
317 print_r($value, true)
322 * Magic method to catch getting of missing fields/attributes
324 * @param $name Name of the field/attribute
327 public final function __get (string $name) {
328 $this->debugBackTrace(sprintf('Tried to get a missing field. name=%s',
334 * Magic method to catch unsetting of missing fields/attributes
336 * @param $name Name of the field/attribute
339 public final function __unset (string $name) {
340 $this->debugBackTrace(sprintf('Tried to unset a missing field. name=%s',
346 * Magic method to catch object serialization
348 * @return $unsupported Unsupported method
349 * @throws UnsupportedOperationException Objects of this framework cannot be serialized
351 public final function __sleep () {
352 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
356 * Magic method to catch object deserialization
358 * @return $unsupported Unsupported method
359 * @throws UnsupportedOperationException Objects of this framework cannot be serialized
361 public final function __wakeup () {
362 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
366 * Magic method to catch calls when an object instance is called
368 * @return $unsupported Unsupported method
369 * @throws UnsupportedOperationException Objects of this framework cannot be serialized
371 public final function __invoke () {
372 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
376 * Setter for the real class name
378 * @param $realClass Class name (string)
381 public final function setRealClass (string $realClass) {
383 $this->realClass = $realClass;
387 * Setter for debug instance
389 * @param $debugInstance The instance for debug output class
392 public final function setDebugInstance (DebugMiddleware $debugInstance) {
393 GenericRegistry::getRegistry()->addInstance('debug', $debugInstance);
397 * Getter for debug instance
399 * @return $debugInstance Instance to class DebugConsoleOutput or DebugWebOutput
401 public final function getDebugInstance () {
402 // Get debug instance
403 $debugInstance = GenericRegistry::getRegistry()->getInstance('debug');
406 return $debugInstance;
410 * Setter for web output instance
412 * @param $webInstance The instance for web output class
415 public final function setWebOutputInstance (OutputStreamer $webInstance) {
416 GenericRegistry::getRegistry()->addInstance('web_output', $webInstance);
420 * Getter for web output instance
422 * @return $webOutputInstance - Instance to class WebOutput
424 public final function getWebOutputInstance () {
425 $webOutputInstance = GenericRegistry::getRegistry()->getInstance('web_output');
426 return $webOutputInstance;
430 * Setter for call-back instance
432 * @param $callbackInstance An instance of a FrameworkInterface class
435 public final function setCallbackInstance (FrameworkInterface $callbackInstance) {
436 $this->callbackInstance = $callbackInstance;
440 * Getter for call-back instance
442 * @return $callbackInstance An instance of a FrameworkInterface class
444 protected final function getCallbackInstance () {
445 return $this->callbackInstance;
449 * Checks whether an object equals this object. You should overwrite this
450 * method to implement own equality checks
452 * @param $objectInstance An instance of a FrameworkInterface object
453 * @return $equals Whether both objects equals
455 public function equals (FrameworkInterface $objectInstance) {
458 $this->__toString() == $objectInstance->__toString()
460 $this->hashCode() == $objectInstance->hashCode()
468 * Generates a generic hash code of this class. You should really overwrite
469 * this method with your own hash code generator code. But keep KISS in mind.
471 * @return $hashCode A generic hash code respresenting this whole class
473 public function hashCode () {
475 return crc32($this->__toString());
479 * Appends a trailing slash to a string
481 * @param $str A string (maybe) without trailing slash
482 * @return $str A string with an auto-appended trailing slash
484 public final function addMissingTrailingSlash ($str) {
485 // Is there a trailing slash?
486 if (substr($str, -1, 1) != '/') {
490 // Return string with trailing slash
495 * Debugs this instance by putting out it's full content
497 * @param $message Optional message to show in debug output
500 public final function debugInstance ($message = '') {
501 // Restore the error handler to avoid trouble with missing array elements or undeclared variables
502 restore_error_handler();
508 if (!empty($message)) {
510 $content = sprintf('<div class="debug_message">
512 </div>' . PHP_EOL, $message);
515 // Generate the output
516 $content .= sprintf('<pre>%s</pre>',
525 ApplicationEntryPoint::exitApplication(sprintf('<div class="debug_header">
528 <div class="debug_content">
532 <div class="debug_include_list">
537 ClassLoader::getSelfInstance()->getPrintableIncludeList()
542 * Replaces control characters with printable output
544 * @param $str String with control characters
545 * @return $str Replaced string
547 protected function replaceControlCharacters ($str) {
550 chr(13), '[r]', str_replace(
551 chr(10), '[n]', str_replace(
561 * Output a partial stub message for the caller method
563 * @param $message An optional message to display
566 protected function partialStub ($message = '') {
568 $stubMessage = 'Partial stub!';
570 // Is an extra message given?
571 if (!empty($message)) {
572 // Then add it as well
573 $stubMessage .= ' Message: ' . $message;
576 // Debug instance is there?
577 if (!is_null($this->getDebugInstance())) {
578 // Output stub message
579 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput($stubMessage);
582 trigger_error($stubMessage);
588 * Outputs a debug backtrace and stops further script execution
590 * @param $message An optional message to output
591 * @param $doExit Whether exit the program (true is default)
594 public function debugBackTrace ($message = '', $doExit = true) {
595 // Sorry, there is no other way getting this nice backtrace
596 if (!empty($message)) {
598 printf('Message: %s<br />' . PHP_EOL, $message);
602 debug_print_backtrace();
606 if ($doExit === true) {
612 * Creates an instance of a debugger instance
614 * @param $className Name of the class (currently unsupported)
615 * @param $lineNumber Line number where the call was made
616 * @return $debugInstance An instance of a debugger class
617 * @deprecated Not fully, as the new Logger facilities are not finished yet.
619 public final static function createDebugInstance ($className, $lineNumber = NULL) {
620 // Is the instance set?
621 if (!GenericRegistry::getRegistry()->instanceExists('debug')) {
622 // Init debug instance
623 $debugInstance = NULL;
627 // Get a debugger instance
628 $debugInstance = DebugMiddleware::createDebugMiddleware(FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('debug_' . FrameworkBootstrap::getRequestTypeFromSystem() . '_class'), $className);
629 } catch (NullPointerException $e) {
630 // Didn't work, no instance there
631 exit(sprintf('Cannot create debugInstance! Exception=%s,message=%s,className=%s,lineNumber=%d' . PHP_EOL, $e->__toString(), $e->getMessage(), $className, $lineNumber));
634 // Empty string should be ignored and used for testing the middleware
635 DebugMiddleware::getSelfInstance()->output('');
637 // Set it in registry
638 GenericRegistry::getRegistry()->addInstance('debug', $debugInstance);
640 // Get instance from registry
641 $debugInstance = GenericRegistry::getRegistry()->getDebugInstance();
645 return $debugInstance;
649 * Simple output of a message with line-break
651 * @param $message Message to output
654 public function outputLine ($message) {
656 print($message . PHP_EOL);
660 * Outputs a debug message whether to debug instance (should be set!) or
661 * dies with or ptints the message. Do NEVER EVER rewrite the exit() call to
662 * ApplicationEntryPoint::app_exit(), this would cause an endless loop.
664 * @param $message Message we shall send out...
665 * @param $doPrint Whether print or die here (default: print)
666 * @paran $stripTags Whether to strip tags (default: false)
669 public function debugOutput ($message, $doPrint = true, $stripTags = false) {
670 // Set debug instance to NULL
671 $debugInstance = NULL;
674 $backtrace = debug_backtrace(!DEBUG_BACKTRACE_PROVIDE_OBJECT);
676 // Is function partialStub/__callStatic ?
677 if (in_array($backtrace[1]['function'], array('partialStub', '__call', '__callStatic'))) {
678 // Prepend class::function:line from 3rd element
679 $message = sprintf('[%s::%s:%d]: %s',
680 $backtrace[2]['class'],
681 $backtrace[2]['function'],
682 (isset($backtrace[2]['line']) ? $backtrace[2]['line'] : '0'),
686 // Prepend class::function:line from 2nd element
687 $message = sprintf('[%s::%s:%d]: %s',
688 $backtrace[1]['class'],
689 $backtrace[1]['function'],
690 (isset($backtrace[1]['line']) ? $backtrace[1]['line'] : '0'),
697 // Get debug instance
698 $debugInstance = $this->getDebugInstance();
699 } catch (NullPointerException $e) {
700 // The debug instance is not set (yet)
703 // Is the debug instance there?
704 if (is_object($debugInstance)) {
705 // Use debug output handler
706 $debugInstance->output($message, $stripTags);
708 if ($doPrint === false) {
709 // Die here if not printed
713 // Are debug times enabled?
714 if (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('debug_' . FrameworkBootstrap::getRequestTypeFromSystem() . '_output_timings') == 'Y') {
716 $message = $this->getPrintableExecutionTime() . $message;
720 if ($doPrint === true) {
722 $this->outputLine($message);
731 * Marks up the code by adding e.g. line numbers
733 * @param $phpCode Unmarked PHP code
734 * @return $markedCode Marked PHP code
736 public function markupCode ($phpCode) {
741 $errorArray = error_get_last();
743 // Init the code with error message
744 if (is_array($errorArray)) {
746 $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>',
747 basename($errorArray['file']),
749 $errorArray['message'],
754 // Add line number to the code
755 foreach (explode(chr(10), $phpCode) as $lineNo => $code) {
757 $markedCode .= sprintf('<span id="code_line">%s</span>: %s' . PHP_EOL,
759 htmlentities($code, ENT_QUOTES)
768 * "Getter" for databse entry
770 * @return $entry An array with database entries
771 * @throws NullPointerException If the database result is not found
772 * @throws InvalidDatabaseResultException If the database result is invalid
773 * @todo Monolithic method, should be moved to proper classes
775 protected final function getDatabaseEntry () {
776 // Is there an instance?
777 if (!$this->getResultInstance() instanceof SearchableResult) {
778 // Throw an exception here
779 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
783 $this->getResultInstance()->rewind();
785 // Do we have an entry?
786 if ($this->getResultInstance()->valid() === false) {
787 // @TODO Move the constant to e.g. BaseDatabaseResult when there is a non-cached database result available
788 throw new InvalidDatabaseResultException(array($this, $this->getResultInstance()), CachedDatabaseResult::EXCEPTION_INVALID_DATABASE_RESULT);
792 $this->getResultInstance()->next();
795 $entry = $this->getResultInstance()->current();
802 * Getter for field name
804 * @param $fieldName Field name which we shall get
805 * @return $fieldValue Field value from the user
806 * @throws NullPointerException If the result instance is null
808 public final function getField (string $fieldName) {
809 // Default field value
812 // Get result instance
813 $resultInstance = $this->getResultInstance();
815 // Is this instance null?
816 if (is_null($resultInstance)) {
817 // Then the user instance is no longer valid (expired cookies?)
818 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
822 $fieldArray = $resultInstance->current();
823 //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput($fieldName.':<pre>'.print_r($fieldArray, true).'</pre>');
825 // Convert dashes to underscore
826 $fieldName2 = StringUtils::convertDashesToUnderscores($fieldName);
828 // Does the field exist?
829 if ($this->isFieldSet($fieldName)) {
831 $fieldValue = $fieldArray[$fieldName2];
832 } elseif (defined('DEVELOPER')) {
833 // Missing field entry, may require debugging
834 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']:fieldArray<pre>=' . print_r($fieldArray, true) . '</pre>,fieldName=' . $fieldName . ' not found!');
836 // Missing field entry, may require debugging
837 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']:fieldName=' . $fieldName . ' not found!');
845 * Checks if given field is set
847 * @param $fieldName Field name to check
848 * @return $isSet Whether the given field name is set
849 * @throws NullPointerException If the result instance is null
851 public function isFieldSet (string $fieldName) {
852 // Get result instance
853 $resultInstance = $this->getResultInstance();
855 // Is this instance null?
856 if (is_null($resultInstance)) {
857 // Then the user instance is no longer valid (expired cookies?)
858 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
862 $fieldArray = $resultInstance->current();
863 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('[' . $this->__toString() . ':' . __LINE__ . '] fieldName=' . $fieldName . ',fieldArray=<pre>'.print_r($fieldArray, true).'</pre>');
865 // Convert dashes to underscore
866 $fieldName = StringUtils::convertDashesToUnderscores($fieldName);
869 $isSet = isset($fieldArray[$fieldName]);
876 * Outputs a deprecation warning to the developer.
878 * @param $message The message we shall output to the developer
880 * @todo Write a logging mechanism for productive mode
882 public function deprecationWarning ($message) {
883 // Is developer mode active?
884 if (defined('DEVELOPER')) {
885 // Debug instance is there?
886 if (!is_null($this->getDebugInstance())) {
887 // Output stub message
888 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput($message);
891 trigger_error($message . "<br />\n");
895 // @TODO Finish this part!
896 $this->partialStub('Developer mode inactive. Message:' . $message);
901 * Checks whether the given PHP extension is loaded
903 * @param $phpExtension The PHP extension we shall check
904 * @return $isLoaded Whether the PHP extension is loaded
906 public final function isPhpExtensionLoaded ($phpExtension) {
908 $isLoaded = in_array($phpExtension, get_loaded_extensions());
915 * "Getter" as a time() replacement but with milliseconds. You should use this
916 * method instead of the encapsulated getimeofday() function.
918 * @return $milliTime Timestamp with milliseconds
920 public function getMilliTime () {
921 // Get the time of day as float
922 $milliTime = gettimeofday(true);
929 * Idles (sleeps) for given milliseconds
931 * @return $hasSlept Whether it goes fine
933 public function idle ($milliSeconds) {
934 // Sleep is fine by default
937 // Idle so long with found function
938 if (function_exists('time_sleep_until')) {
939 // Get current time and add idle time
940 $sleepUntil = $this->getMilliTime() + abs($milliSeconds) / 1000;
942 // New PHP 5.1.0 function found, ignore errors
943 $hasSlept = @time_sleep_until($sleepUntil);
946 * My Sun station doesn't have that function even with latest PHP
949 usleep($milliSeconds * 1000);
957 * Checks whether the given encoded data was encoded with Base64
959 * @param $encodedData Encoded data we shall check
960 * @return $isBase64 Whether the encoded data is Base64
962 protected function isBase64Encoded ($encodedData) {
964 $isBase64 = (@base64_decode($encodedData, true) !== false);
971 * Gets a cache key from Criteria instance
973 * @param $criteriaInstance An instance of a Criteria class
974 * @param $onlyKeys Only use these keys for a cache key
975 * @return $cacheKey A cache key suitable for lookup/storage purposes
977 protected function getCacheKeyByCriteria (Criteria $criteriaInstance, array $onlyKeys = []) {
979 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FRAMEWORK-SYSTEM: criteriaInstance=' . $criteriaInstance->__toString() . ',onlyKeys()=' . count($onlyKeys) . ' - CALLED!');
980 $cacheKey = sprintf('%s@%s',
982 $criteriaInstance->getCacheKey($onlyKeys)
986 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FRAMEWORK-SYSTEM: cacheKey=' . $cacheKey . ' - EXIT!');
991 * Getter for startup time in miliseconds
993 * @return $startupTime Startup time in miliseconds
995 protected function getStartupTime () {
996 return self::$startupTime;
1000 * "Getter" for a printable currently execution time in nice braces
1002 * @return $executionTime Current execution time in nice braces
1004 protected function getPrintableExecutionTime () {
1005 // Caculate the execution time
1006 $executionTime = microtime(true) - $this->getStartupTime();
1008 // Pack it in nice braces
1009 $executionTime = sprintf('[ %01.5f ] ', $executionTime);
1012 return $executionTime;
1016 * Hashes a given string with a simple but stronger hash function (no salt)
1017 * and hex-encode it.
1019 * @param $str The string to be hashed
1020 * @return $hash The hash from string $str
1022 public static final function hash ($str) {
1023 // Hash given string with (better secure) hasher
1024 $hash = bin2hex(mhash(MHASH_SHA256, $str));
1031 * "Getter" for length of hash() output. This will be "cached" to speed up
1034 * @return $length Length of hash() output
1036 public static final function getHashLength () {
1038 if (is_null(self::$hashLength)) {
1039 // No, then hash a string and save its length.
1040 self::$hashLength = strlen(self::hash('abc123'));
1044 return self::$hashLength;
1048 * Checks whether the given number is really a number (only chars 0-9).
1050 * @param $num A string consisting only chars between 0 and 9
1051 * @param $castValue Whether to cast the value to double. Do only use this to secure numbers from Requestable classes.
1052 * @param $assertMismatch Whether to assert mismatches
1053 * @return $ret The (hopefully) secured numbered value
1055 public function bigintval ($num, $castValue = true, $assertMismatch = false) {
1056 // Filter all numbers out
1057 $ret = preg_replace('/[^0123456789]/', '', $num);
1060 if ($castValue === true) {
1061 // Cast to biggest numeric type
1062 $ret = (double) $ret;
1065 // Assert only if requested
1066 if ($assertMismatch === true) {
1067 // Has the whole value changed?
1068 assert(('' . $ret . '' != '' . $num . '') && (!is_null($num)));
1076 * Checks whether the given hexadecimal number is really a hex-number (only chars 0-9,a-f).
1078 * @param $num A string consisting only chars between 0 and 9
1079 * @param $assertMismatch Whether to assert mismatches
1080 * @return $ret The (hopefully) secured hext-numbered value
1082 public function hexval ($num, $assertMismatch = false) {
1083 // Filter all numbers out
1084 $ret = preg_replace('/[^0123456789abcdefABCDEF]/', '', $num);
1086 // Assert only if requested
1087 if ($assertMismatch === true) {
1088 // Has the whole value changed?
1089 assert(('' . $ret . '' != '' . $num . '') && (!is_null($num)));
1097 * Determines if an element is set in the generic array
1099 * @param $keyGroup Main group for the key
1100 * @param $subGroup Sub group for the key
1101 * @param $key Key to check
1102 * @param $element Element to check
1103 * @return $isset Whether the given key is set
1105 protected final function isGenericArrayElementSet ($keyGroup, $subGroup, $key, $element) {
1107 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element);
1110 $isset = isset($this->genericArray[$keyGroup][$subGroup][$key][$element]);
1116 * Determines if a key is set in the generic array
1118 * @param $keyGroup Main group for the key
1119 * @param $subGroup Sub group for the key
1120 * @param $key Key to check
1121 * @return $isset Whether the given key is set
1123 protected final function isGenericArrayKeySet ($keyGroup, $subGroup, $key) {
1125 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1128 $isset = isset($this->genericArray[$keyGroup][$subGroup][$key]);
1136 * Determines if a group is set in the generic array
1138 * @param $keyGroup Main group
1139 * @param $subGroup Sub group
1140 * @return $isset Whether the given group is set
1142 protected final function isGenericArrayGroupSet ($keyGroup, $subGroup) {
1144 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup);
1147 $isset = isset($this->genericArray[$keyGroup][$subGroup]);
1154 * Getter for sub key group
1156 * @param $keyGroup Main key group
1157 * @param $subGroup Sub key group
1158 * @return $array An array with all array elements
1160 protected final function getGenericSubArray ($keyGroup, $subGroup) {
1162 if (!$this->isGenericArrayGroupSet($keyGroup, $subGroup)) {
1163 // No, then abort here
1164 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' not found.');
1169 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',value=' . print_r($this->genericArray[$keyGroup][$subGroup], true));
1172 return $this->genericArray[$keyGroup][$subGroup];
1176 * Unsets a given key in generic array
1178 * @param $keyGroup Main group for the key
1179 * @param $subGroup Sub group for the key
1180 * @param $key Key to unset
1183 protected final function unsetGenericArrayKey ($keyGroup, $subGroup, $key) {
1185 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1188 unset($this->genericArray[$keyGroup][$subGroup][$key]);
1192 * Unsets a given element in generic array
1194 * @param $keyGroup Main group for the key
1195 * @param $subGroup Sub group for the key
1196 * @param $key Key to unset
1197 * @param $element Element to unset
1200 protected final function unsetGenericArrayElement ($keyGroup, $subGroup, $key, $element) {
1202 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element);
1205 unset($this->genericArray[$keyGroup][$subGroup][$key][$element]);
1209 * Append a string to a given generic array key
1211 * @param $keyGroup Main group for the key
1212 * @param $subGroup Sub group for the key
1213 * @param $key Key to unset
1214 * @param $value Value to add/append
1217 protected final function appendStringToGenericArrayKey ($keyGroup, $subGroup, $key, $value, $appendGlue = '') {
1219 //* 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);
1221 // Is it already there?
1222 if ($this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
1224 $this->genericArray[$keyGroup][$subGroup][$key] .= $appendGlue . (string) $value;
1227 $this->genericArray[$keyGroup][$subGroup][$key] = (string) $value;
1232 * Append a string to a given generic array element
1234 * @param $keyGroup Main group for the key
1235 * @param $subGroup Sub group for the key
1236 * @param $key Key to unset
1237 * @param $element Element to check
1238 * @param $value Value to add/append
1241 protected final function appendStringToGenericArrayElement ($keyGroup, $subGroup, $key, $element, $value, $appendGlue = '') {
1243 //* 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);
1245 // Is it already there?
1246 if ($this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element)) {
1248 $this->genericArray[$keyGroup][$subGroup][$key][$element] .= $appendGlue . (string) $value;
1251 $this->setStringGenericArrayElement($keyGroup, $subGroup, $key, $element, $value);
1256 * Sets a string in a given generic array element
1258 * @param $keyGroup Main group for the key
1259 * @param $subGroup Sub group for the key
1260 * @param $key Key to unset
1261 * @param $element Element to check
1262 * @param $value Value to add/append
1265 protected final function setStringGenericArrayElement ($keyGroup, $subGroup, $key, $element, $value, $appendGlue = '') {
1267 //* 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);
1270 $this->genericArray[$keyGroup][$subGroup][$key][$element] = (string) $value;
1274 * Initializes given generic array group
1276 * @param $keyGroup Main group for the key
1277 * @param $subGroup Sub group for the key
1278 * @param $key Key to use
1279 * @param $forceInit Optionally force initialization
1282 protected final function initGenericArrayGroup ($keyGroup, $subGroup, $forceInit = false) {
1284 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',forceInit=' . intval($forceInit));
1286 // Is it already set?
1287 if (($forceInit === false) && ($this->isGenericArrayGroupSet($keyGroup, $subGroup))) {
1288 // Already initialized
1289 trigger_error(__METHOD__ . ':keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' already initialized.');
1294 $this->genericArray[$keyGroup][$subGroup] = [];
1298 * Initializes given generic array key
1300 * @param $keyGroup Main group for the key
1301 * @param $subGroup Sub group for the key
1302 * @param $key Key to use
1303 * @param $forceInit Optionally force initialization
1306 protected final function initGenericArrayKey ($keyGroup, $subGroup, $key, $forceInit = false) {
1308 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',forceInit=' . intval($forceInit));
1310 // Is it already set?
1311 if (($forceInit === false) && ($this->isGenericArrayKeySet($keyGroup, $subGroup, $key))) {
1312 // Already initialized
1313 trigger_error(__METHOD__ . ':keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' already initialized.');
1318 $this->genericArray[$keyGroup][$subGroup][$key] = [];
1322 * Initializes given generic array element
1324 * @param $keyGroup Main group for the key
1325 * @param $subGroup Sub group for the key
1326 * @param $key Key to use
1327 * @param $element Element to use
1328 * @param $forceInit Optionally force initialization
1331 protected final function initGenericArrayElement ($keyGroup, $subGroup, $key, $element, $forceInit = false) {
1333 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element . ',forceInit=' . intval($forceInit));
1335 // Is it already set?
1336 if (($forceInit === false) && ($this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element))) {
1337 // Already initialized
1338 trigger_error(__METHOD__ . ':keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element . ' already initialized.');
1343 $this->genericArray[$keyGroup][$subGroup][$key][$element] = [];
1347 * Pushes an element to a generic key
1349 * @param $keyGroup Main group for the key
1350 * @param $subGroup Sub group for the key
1351 * @param $key Key to use
1352 * @param $value Value to add/append
1353 * @return $count Number of array elements
1355 protected final function pushValueToGenericArrayKey ($keyGroup, $subGroup, $key, $value) {
1357 //* NOISY-DEBUG: */ if (!is_object($value)) $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',value[' . gettype($value) . ']=' . print_r($value, true));
1360 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
1362 $this->initGenericArrayKey($keyGroup, $subGroup, $key);
1366 $count = array_push($this->genericArray[$keyGroup][$subGroup][$key], $value);
1369 //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], true));
1370 //* DEBUG: */ print(__METHOD__ . ': count=' . $count . PHP_EOL);
1375 * Pushes an element to a generic array element
1377 * @param $keyGroup Main group for the key
1378 * @param $subGroup Sub group for the key
1379 * @param $key Key to use
1380 * @param $element Element to check
1381 * @param $value Value to add/append
1382 * @return $count Number of array elements
1384 protected final function pushValueToGenericArrayElement ($keyGroup, $subGroup, $key, $element, $value) {
1386 //* 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));
1389 if (!$this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element)) {
1391 $this->initGenericArrayElement($keyGroup, $subGroup, $key, $element);
1395 $count = array_push($this->genericArray[$keyGroup][$subGroup][$key][$element], $value);
1398 //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], true));
1399 //* DEBUG: */ print(__METHOD__ . ': count=' . $count . PHP_EOL);
1404 * Pops an element from a generic group
1406 * @param $keyGroup Main group for the key
1407 * @param $subGroup Sub group for the key
1408 * @param $key Key to unset
1409 * @return $value Last "popped" value
1411 protected final function popGenericArrayElement ($keyGroup, $subGroup, $key) {
1413 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1416 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
1418 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' not found.');
1423 $value = array_pop($this->genericArray[$keyGroup][$subGroup][$key]);
1426 //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], true));
1427 //* DEBUG: */ print(__METHOD__ . ': value[' . gettype($value) . ']=' . print_r($value, true) . PHP_EOL);
1432 * Shifts an element from a generic group
1434 * @param $keyGroup Main group for the key
1435 * @param $subGroup Sub group for the key
1436 * @param $key Key to unset
1437 * @return $value Last "popped" value
1439 protected final function shiftGenericArrayElement ($keyGroup, $subGroup, $key) {
1441 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1444 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
1446 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' not found.');
1451 $value = array_shift($this->genericArray[$keyGroup][$subGroup][$key]);
1454 //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], true));
1455 //* DEBUG: */ print(__METHOD__ . ': value[' . gettype($value) . ']=' . print_r($value, true) . PHP_EOL);
1460 * Count generic array group
1462 * @param $keyGroup Main group for the key
1463 * @return $count Count of given group
1465 protected final function countGenericArray ($keyGroup) {
1467 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup);
1470 if (!isset($this->genericArray[$keyGroup])) {
1472 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ' not found.');
1477 $count = count($this->genericArray[$keyGroup]);
1480 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',count=' . $count);
1487 * Count generic array sub group
1489 * @param $keyGroup Main group for the key
1490 * @param $subGroup Sub group for the key
1491 * @return $count Count of given group
1493 protected final function countGenericArrayGroup ($keyGroup, $subGroup) {
1495 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup);
1498 if (!$this->isGenericArrayGroupSet($keyGroup, $subGroup)) {
1500 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' not found.');
1505 $count = count($this->genericArray[$keyGroup][$subGroup]);
1508 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',count=' . $count);
1515 * Count generic array elements
1517 * @param $keyGroup Main group for the key
1518 * @param $subGroup Sub group for the key
1519 * @para $key Key to count
1520 * @return $count Count of given key
1522 protected final function countGenericArrayElements ($keyGroup, $subGroup, $key) {
1524 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1527 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
1529 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' not found.');
1531 } elseif (!$this->isValidGenericArrayGroup($keyGroup, $subGroup)) {
1533 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' is not an array.');
1538 $count = count($this->genericArray[$keyGroup][$subGroup][$key]);
1541 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',count=' . $count);
1548 * Getter for whole generic group array
1550 * @param $keyGroup Key group to get
1551 * @return $array Whole generic array group
1553 protected final function getGenericArray ($keyGroup) {
1555 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup);
1558 if (!isset($this->genericArray[$keyGroup])) {
1560 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ' does not exist.');
1565 return $this->genericArray[$keyGroup];
1569 * Setter for generic array key
1571 * @param $keyGroup Key group to get
1572 * @param $subGroup Sub group for the key
1573 * @param $key Key to unset
1574 * @param $value Mixed value from generic array element
1577 protected final function setGenericArrayKey ($keyGroup, $subGroup, $key, $value) {
1579 //* NOISY-DEBUG: */ if (!is_object($value)) $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',value[' . gettype($value) . ']=' . print_r($value, true));
1582 $this->genericArray[$keyGroup][$subGroup][$key] = $value;
1586 * Getter for generic array key
1588 * @param $keyGroup Key group to get
1589 * @param $subGroup Sub group for the key
1590 * @param $key Key to unset
1591 * @return $value Mixed value from generic array element
1593 protected final function getGenericArrayKey ($keyGroup, $subGroup, $key) {
1595 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1598 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
1600 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' does not exist.');
1605 return $this->genericArray[$keyGroup][$subGroup][$key];
1609 * Sets a value in given generic array key/element
1611 * @param $keyGroup Main group for the key
1612 * @param $subGroup Sub group for the key
1613 * @param $key Key to set
1614 * @param $element Element to set
1615 * @param $value Value to set
1618 protected final function setGenericArrayElement ($keyGroup, $subGroup, $key, $element, $value) {
1620 //* 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));
1623 $this->genericArray[$keyGroup][$subGroup][$key][$element] = $value;
1627 * Getter for generic array element
1629 * @param $keyGroup Key group to get
1630 * @param $subGroup Sub group for the key
1631 * @param $key Key to look for
1632 * @param $element Element to look for
1633 * @return $value Mixed value from generic array element
1635 protected final function getGenericArrayElement ($keyGroup, $subGroup, $key, $element) {
1637 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element);
1640 if (!$this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element)) {
1642 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element . ' does not exist.');
1647 return $this->genericArray[$keyGroup][$subGroup][$key][$element];
1651 * Checks if a given sub group is valid (array)
1653 * @param $keyGroup Key group to get
1654 * @param $subGroup Sub group for the key
1655 * @return $isValid Whether given sub group is valid
1657 protected final function isValidGenericArrayGroup ($keyGroup, $subGroup) {
1659 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup);
1662 $isValid = (($this->isGenericArrayGroupSet($keyGroup, $subGroup)) && (is_array($this->getGenericSubArray($keyGroup, $subGroup))));
1669 * Checks if a given key is valid (array)
1671 * @param $keyGroup Key group to get
1672 * @param $subGroup Sub group for the key
1673 * @param $key Key to check
1674 * @return $isValid Whether given sub group is valid
1676 protected final function isValidGenericArrayKey ($keyGroup, $subGroup, $key) {
1678 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1681 $isValid = (($this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) && (is_array($this->getGenericArrayKey($keyGroup, $subGroup, $key))));
1688 * Initializes the web output instance
1692 protected function initWebOutputInstance () {
1693 // Get application instance
1694 $applicationInstance = GenericRegistry::getRegistry()->getInstance('application');
1696 // Init web output instance
1697 $outputInstance = ObjectFactory::createObjectByConfiguredName('output_class', array($applicationInstance));
1700 $this->setWebOutputInstance($outputInstance);
1704 * Translates boolean true to 'Y' and false to 'N'
1706 * @param $boolean Boolean value
1707 * @return $translated Translated boolean value
1709 public static final function translateBooleanToYesNo (bool $boolean) {
1710 // Make sure it is really boolean
1711 assert(is_bool($boolean));
1714 $translated = ($boolean === true) ? 'Y' : 'N';
1716 // ... and return it
1721 * Creates a full-qualified file name (FQFN) for given file name by adding
1722 * a configured temporary file path to it.
1724 * @param $infoInstance An instance of a SplFileInfo class
1725 * @return $tempInstance An instance of a SplFileInfo class (temporary file)
1726 * @throw PathWriteProtectedException If the path in 'temp_file_path' is write-protected
1727 * @throws FileIoException If the file cannot be written
1729 protected static function createTempPathForFile (SplFileInfo $infoInstance) {
1731 $basePath = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('temp_file_path');
1733 // Is the path writeable?
1734 if (!is_writable($basePath)) {
1735 // Path is write-protected
1736 throw new PathWriteProtectedException($infoInstance, self::EXCEPTION_PATH_CANNOT_BE_WRITTEN);
1740 $tempInstance = new SplFileInfo($basePath . DIRECTORY_SEPARATOR . $infoInstance->getBasename());
1743 if (!FrameworkBootstrap::isReachableFilePath($tempInstance)) {
1745 throw new FileIoException($tempInstance, self::EXCEPTION_FILE_NOT_REACHABLE);
1749 return $tempInstance;
1753 * "Getter" for a printable state name
1755 * @return $stateName Name of the node's state in a printable format
1756 * @todo Move this class away from this monolithic place (not whole class is monolithic)
1758 public final function getPrintableState () {
1759 // Default is 'null'
1760 $stateName = 'null';
1762 // Get the state instance
1763 $stateInstance = $this->getStateInstance();
1765 // Is it an instance of Stateable?
1766 if ($stateInstance instanceof Stateable) {
1767 // Then use that state name
1768 $stateName = $stateInstance->getStateName();