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\Crypto\Cryptable;
9 use Org\Mxchange\CoreFramework\Database\Frontend\DatabaseWrapper;
10 use Org\Mxchange\CoreFramework\EntryPoint\ApplicationEntryPoint;
11 use Org\Mxchange\CoreFramework\Factory\Database\Wrapper\DatabaseWrapperFactory;
12 use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
13 use Org\Mxchange\CoreFramework\Filesystem\PathWriteProtectedException;
14 use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
15 use Org\Mxchange\CoreFramework\Generic\NullPointerException;
16 use Org\Mxchange\CoreFramework\Generic\UnsupportedOperationException;
17 use Org\Mxchange\CoreFramework\Loader\ClassLoader;
18 use Org\Mxchange\CoreFramework\Manager\ManageableApplication;
19 use Org\Mxchange\CoreFramework\Middleware\Debug\DebugMiddleware;
20 use Org\Mxchange\CoreFramework\Registry\GenericRegistry;
21 use Org\Mxchange\CoreFramework\Result\Database\CachedDatabaseResult;
22 use Org\Mxchange\CoreFramework\Result\Search\SearchableResult;
23 use Org\Mxchange\CoreFramework\State\Stateable;
24 use Org\Mxchange\CoreFramework\Stream\Input\InputStream;
25 use Org\Mxchange\CoreFramework\Stream\Output\OutputStreamer;
26 use Org\Mxchange\CoreFramework\Stream\Output\OutputStream;
27 use Org\Mxchange\CoreFramework\User\ManageableAccount;
28 use Org\Mxchange\CoreFramework\Utils\String\StringUtils;
32 use \InvalidArgumentException;
38 * The simulator system class is the super class of all other classes. This
39 * class handles saving of games etc.
41 * @author Roland Haeder <webmaster@shipsimu.org>
43 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2020 Core Developer Team
44 * @license GNU GPL 3.0 or any newer version
45 * @link http://www.shipsimu.org
47 * This program is free software: you can redistribute it and/or modify
48 * it under the terms of the GNU General Public License as published by
49 * the Free Software Foundation, either version 3 of the License, or
50 * (at your option) any later version.
52 * This program is distributed in the hope that it will be useful,
53 * but WITHOUT ANY WARRANTY; without even the implied warranty of
54 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
55 * GNU General Public License for more details.
57 * You should have received a copy of the GNU General Public License
58 * along with this program. If not, see <http://www.gnu.org/licenses/>.
60 abstract class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
62 * Length of output from hash()
64 private static $hashLength = NULL;
67 * Self-referencing instance
69 private static $instance = NULL;
74 private $realClass = __CLASS__;
77 * Database result instance
79 private $resultInstance = NULL;
82 * Instance for user class
84 private $userInstance = NULL;
87 * Instance of a crypto helper
89 private $cryptoInstance = NULL;
92 * Instance of an Iterator class
94 private $iteratorInstance = NULL;
97 * An instance of a InputStream class
99 private $inputStreamInstance = NULL;
102 * An instance of a OutputStream class
104 private $outputStreamInstance = NULL;
107 * An instance of a database wrapper class
109 private $wrapperInstance = NULL;
114 private $stateInstance = NULL;
119 private $callbackInstance = NULL;
124 private $genericArray = [];
126 /***********************
127 * Exception codes.... *
128 ***********************/
130 // @todo Try to clean these constants up
131 const EXCEPTION_IS_NULL_POINTER = 0x001;
132 const EXCEPTION_IS_NO_OBJECT = 0x002;
133 const EXCEPTION_IS_NO_ARRAY = 0x003;
134 const EXCEPTION_MISSING_METHOD = 0x004;
135 const EXCEPTION_CLASSES_NOT_MATCHING = 0x005;
136 const EXCEPTION_INDEX_OUT_OF_BOUNDS = 0x006;
137 const EXCEPTION_DIMENSION_ARRAY_INVALID = 0x007;
138 const EXCEPTION_ITEM_NOT_TRADEABLE = 0x008;
139 const EXCEPTION_ITEM_NOT_IN_PRICE_LIST = 0x009;
140 const EXCEPTION_GENDER_IS_WRONG = 0x00a;
141 const EXCEPTION_BIRTH_DATE_IS_INVALID = 0x00b;
142 const EXCEPTION_EMPTY_STRUCTURES_ARRAY = 0x00c;
143 const EXCEPTION_HAS_ALREADY_PERSONELL_LIST = 0x00d;
144 const EXCEPTION_NOT_ENOUGTH_UNEMPLOYEES = 0x00e;
145 const EXCEPTION_TOTAL_PRICE_NOT_CALCULATED = 0x00f;
146 const EXCEPTION_HARBOR_HAS_NO_SHIPYARDS = 0x010;
147 const EXCEPTION_CONTRACT_PARTNER_INVALID = 0x011;
148 const EXCEPTION_CONTRACT_PARTNER_MISMATCH = 0x012;
149 const EXCEPTION_CONTRACT_ALREADY_SIGNED = 0x013;
150 const EXCEPTION_UNEXPECTED_EMPTY_STRING = 0x014;
151 const EXCEPTION_PATH_NOT_FOUND = 0x015;
152 const EXCEPTION_INVALID_PATH_NAME = 0x016;
153 const EXCEPTION_READ_PROTECED_PATH = 0x017;
154 const EXCEPTION_WRITE_PROTECED_PATH = 0x018;
155 const EXCEPTION_DIR_POINTER_INVALID = 0x019;
156 const EXCEPTION_FILE_POINTER_INVALID = 0x01a;
157 const EXCEPTION_INVALID_RESOURCE = 0x01b;
158 const EXCEPTION_UNEXPECTED_OBJECT = 0x01c;
159 const EXCEPTION_LIMIT_ELEMENT_IS_UNSUPPORTED = 0x01d;
160 const EXCEPTION_GETTER_IS_MISSING = 0x01e;
161 const EXCEPTION_ARRAY_EXPECTED = 0x01f;
162 const EXCEPTION_ARRAY_HAS_INVALID_COUNT = 0x020;
163 const EXCEPTION_ID_IS_INVALID_FORMAT = 0x021;
164 const EXCEPTION_MD5_CHECKSUMS_MISMATCH = 0x022;
165 const EXCEPTION_UNEXPECTED_STRING_SIZE = 0x023;
166 const EXCEPTION_SIMULATOR_ID_INVALID = 0x024;
167 const EXCEPTION_MISMATCHING_COMPRESSORS = 0x025;
168 const EXCEPTION_CONTAINER_ITEM_IS_NULL = 0x026;
169 const EXCEPTION_ITEM_IS_NO_ARRAY = 0x027;
170 const EXCEPTION_CONTAINER_MAYBE_DAMAGED = 0x028;
171 const EXCEPTION_INVALID_STRING = 0x029;
172 const EXCEPTION_VARIABLE_NOT_SET = 0x02a;
173 const EXCEPTION_ATTRIBUTES_ARE_MISSING = 0x02b;
174 const EXCEPTION_ARRAY_ELEMENTS_MISSING = 0x02c;
175 const EXCEPTION_TEMPLATE_ENGINE_UNSUPPORTED = 0x02d;
176 const EXCEPTION_UNSPPORTED_OPERATION = 0x02e;
177 const EXCEPTION_FACTORY_REQUIRE_PARAMETER = 0x02f;
178 const EXCEPTION_MISSING_ELEMENT = 0x030;
179 const EXCEPTION_HEADERS_ALREADY_SENT = 0x031;
180 const EXCEPTION_DEFAULT_CONTROLLER_GONE = 0x032;
181 const EXCEPTION_CLASS_NOT_FOUND = 0x033;
182 const EXCEPTION_REQUIRED_INTERFACE_MISSING = 0x034;
183 const EXCEPTION_FATAL_ERROR = 0x035;
184 const EXCEPTION_FILE_NOT_FOUND = 0x036;
185 const EXCEPTION_ASSERTION_FAILED = 0x037;
186 const EXCEPTION_FILE_NOT_REACHABLE = 0x038;
187 const EXCEPTION_FILE_CANNOT_BE_READ = 0x039;
188 const EXCEPTION_FILE_CANNOT_BE_WRITTEN = 0x03a;
189 const EXCEPTION_PATH_CANNOT_BE_WRITTEN = 0x03b;
190 const EXCEPTION_DATABASE_UPDATED_NOT_ALLOWED = 0x03c;
191 const EXCEPTION_FILTER_CHAIN_INTERCEPTED = 0x03d;
192 const EXCEPTION_INVALID_SOCKET = 0x03e;
193 const EXCEPTION_SELF_INSTANCE = 0x03f;
196 * Startup time in miliseconds
198 private static $startupTime = 0;
201 * Protected super constructor
203 * @param $className Name of the class
206 protected function __construct (string $className) {
208 $this->setRealClass($className);
210 // Is the startup time set? (0 cannot be true anymore)
211 if (self::$startupTime == 0) {
213 self::$startupTime = microtime(true);
218 * Destructor for all classes. You should not call this method on your own.
222 public function __destruct () {
223 // Flush any updated entries to the database
224 $this->flushPendingUpdates();
226 // Is this object already destroyed?
227 if ($this->__toString() != 'DestructedObject') {
228 // Destroy all informations about this class but keep some text about it alive
229 $this->setRealClass('DestructedObject');
230 } elseif ((defined('DEBUG_DESTRUCTOR')) && (is_object($this->getDebugInstance()))) {
231 // Already destructed object
232 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('The object <span class="object_name">%s</span> is already destroyed.',
236 // Do not call this twice
237 trigger_error(__METHOD__ . ': Called twice.');
243 * The __call() method where all non-implemented methods end up
245 * @param $methodName Name of the missing method
246 * @args $args Arguments passed to the method
249 public final function __call (string $methodName, array $args = NULL) {
251 self::$instance = $this;
253 // Call static method
254 self::__callStatic($methodName, $args);
256 // Clear self-instance
257 self::$instance = NULL;
261 * The __callStatic() method where all non-implemented static methods end up
263 * @param $methodName Name of the missing method
264 * @param $args Arguments passed to the method
266 * @throws InvalidArgumentException If self::$instance is not a framework's own object
268 public static final function __callStatic (string $methodName, array $args = NULL) {
269 // Init argument string and class name
270 //* PRINT-DEBUG: */ printf('[%s:%d]: methodName=%s,args[]=%s - CALLED!' . PHP_EOL, __METHOD__, __LINE__, $methodName, gettype($args));
272 $className = 'unknown';
274 // Is self-instance set?
275 if (self::$instance instanceof FrameworkInterface) {
276 // Framework's own instance
277 $className = self::$instance->__toString();
278 } elseif (!is_null(self::$instance)) {
280 throw new InvalidArgumentException(sprintf('self::instance[%s] is not expected.', gettype(self::$instance)), self::EXCEPTION_SELF_INSTANCE);
283 // Is it NULL, empty or an array?
284 if (is_null($args)) {
286 $argsString = 'NULL';
287 } elseif (is_array($args)) {
291 // Some arguments are there
292 foreach ($args as $arg) {
293 // Add data about the argument
294 $argsString .= gettype($arg) . ':';
297 // Found a NULL argument
298 $argsString .= 'NULL';
299 } elseif (is_string($arg)) {
300 // Add length for strings
301 $argsString .= strlen($arg);
302 } elseif ((is_int($arg)) || (is_float($arg))) {
305 } elseif (is_array($arg)) {
306 // .. or size if array
307 $argsString .= count($arg);
308 } elseif (is_object($arg)) {
310 $reflection = new ReflectionClass($arg);
312 // Is an other object, maybe no __toString() available
313 $argsString .= $reflection->getName();
314 } elseif ($arg === true) {
315 // ... is boolean 'true'
316 $argsString .= 'true';
317 } elseif ($arg === false) {
318 // ... is boolean 'false'
319 $argsString .= 'false';
322 // Comma for next one
327 if (substr($argsString, -2, 1) == ',') {
329 $argsString = substr($argsString, 0, -2);
336 // Output stub message
337 // @TODO __CLASS__ does always return BaseFrameworkSystem but not the extending (=child) class
338 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s::%s]: Stub! Args: %s',
349 * Getter for $realClass
351 * @return $realClass The name of the real class (not BaseFrameworkSystem)
353 public function __toString () {
354 return $this->realClass;
358 * Magic method to catch setting of missing but set class fields/attributes
360 * @param $name Name of the field/attribute
361 * @param $value Value to store
364 public final function __set (string $name, $value) {
365 $this->debugBackTrace(sprintf('Tried to set a missing field. name=%s, value[%s]=%s',
368 print_r($value, true)
373 * Magic method to catch getting of missing fields/attributes
375 * @param $name Name of the field/attribute
378 public final function __get (string $name) {
379 $this->debugBackTrace(sprintf('Tried to get a missing field. name=%s',
385 * Magic method to catch unsetting of missing fields/attributes
387 * @param $name Name of the field/attribute
390 public final function __unset (string $name) {
391 $this->debugBackTrace(sprintf('Tried to unset a missing field. name=%s',
397 * Magic method to catch object serialization
399 * @return $unsupported Unsupported method
400 * @throws UnsupportedOperationException Objects of this framework cannot be serialized
402 public final function __sleep () {
403 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
407 * Magic method to catch object deserialization
409 * @return $unsupported Unsupported method
410 * @throws UnsupportedOperationException Objects of this framework cannot be serialized
412 public final function __wakeup () {
413 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
417 * Magic method to catch calls when an object instance is called
419 * @return $unsupported Unsupported method
420 * @throws UnsupportedOperationException Objects of this framework cannot be serialized
422 public final function __invoke () {
423 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
427 * Setter for the real class name
429 * @param $realClass Class name (string)
432 public final function setRealClass (string $realClass) {
434 $this->realClass = $realClass;
438 * Setter for database result instance
440 * @param $resultInstance An instance of a database result class
442 * @todo SearchableResult and UpdateableResult shall have a super interface to use here
444 protected final function setResultInstance (SearchableResult $resultInstance) {
445 $this->resultInstance = $resultInstance;
449 * Getter for database result instance
451 * @return $resultInstance An instance of a database result class
453 public final function getResultInstance () {
454 return $this->resultInstance;
458 * Setter for debug instance
460 * @param $debugInstance The instance for debug output class
463 public final function setDebugInstance (DebugMiddleware $debugInstance) {
464 GenericRegistry::getRegistry()->addInstance('debug', $debugInstance);
468 * Getter for debug instance
470 * @return $debugInstance Instance to class DebugConsoleOutput or DebugWebOutput
472 public final function getDebugInstance () {
473 // Get debug instance
474 $debugInstance = GenericRegistry::getRegistry()->getInstance('debug');
477 return $debugInstance;
481 * Setter for web output instance
483 * @param $webInstance The instance for web output class
486 public final function setWebOutputInstance (OutputStreamer $webInstance) {
487 GenericRegistry::getRegistry()->addInstance('web_output', $webInstance);
491 * Getter for web output instance
493 * @return $webOutputInstance - Instance to class WebOutput
495 public final function getWebOutputInstance () {
496 $webOutputInstance = GenericRegistry::getRegistry()->getInstance('web_output');
497 return $webOutputInstance;
501 * Protected setter for user instance
503 * @param $userInstance An instance of a user class
506 protected final function setUserInstance (ManageableAccount $userInstance) {
507 $this->userInstance = $userInstance;
511 * Getter for user instance
513 * @return $userInstance An instance of a user class
515 public final function getUserInstance () {
516 return $this->userInstance;
520 * Setter for Cryptable instance
522 * @param $cryptoInstance An instance of a Cryptable class
525 protected final function setCryptoInstance (Cryptable $cryptoInstance) {
526 $this->cryptoInstance = $cryptoInstance;
530 * Getter for Cryptable instance
532 * @return $cryptoInstance An instance of a Cryptable class
534 public final function getCryptoInstance () {
535 return $this->cryptoInstance;
539 * Setter for DatabaseWrapper instance
541 * @param $wrapperInstance An instance of an DatabaseWrapper
544 public final function setWrapperInstance (DatabaseWrapper $wrapperInstance) {
545 $this->wrapperInstance = $wrapperInstance;
549 * Getter for DatabaseWrapper instance
551 * @return $wrapperInstance An instance of an DatabaseWrapper
553 public final function getWrapperInstance () {
554 return $this->wrapperInstance;
558 * Getter for a InputStream instance
560 * @param $inputStreamInstance The InputStream instance
562 protected final function getInputStreamInstance () {
563 return $this->inputStreamInstance;
567 * Setter for a InputStream instance
569 * @param $inputStreamInstance The InputStream instance
572 protected final function setInputStreamInstance (InputStream $inputStreamInstance) {
573 $this->inputStreamInstance = $inputStreamInstance;
577 * Getter for a OutputStream instance
579 * @param $outputStreamInstance The OutputStream instance
581 protected final function getOutputStreamInstance () {
582 return $this->outputStreamInstance;
586 * Setter for a OutputStream instance
588 * @param $outputStreamInstance The OutputStream instance
591 protected final function setOutputStreamInstance (OutputStream $outputStreamInstance) {
592 $this->outputStreamInstance = $outputStreamInstance;
596 * Setter for Iterator instance
598 * @param $iteratorInstance An instance of an Iterator
601 protected final function setIteratorInstance (Iterator $iteratorInstance) {
602 $this->iteratorInstance = $iteratorInstance;
606 * Getter for Iterator instance
608 * @return $iteratorInstance An instance of an Iterator
610 public final function getIteratorInstance () {
611 return $this->iteratorInstance;
615 * Setter for state instance
617 * @param $stateInstance A Stateable instance
620 public final function setStateInstance (Stateable $stateInstance) {
621 $this->stateInstance = $stateInstance;
625 * Getter for state instance
627 * @return $stateInstance A Stateable instance
629 public final function getStateInstance () {
630 return $this->stateInstance;
634 * Setter for call-back instance
636 * @param $callbackInstance An instance of a FrameworkInterface class
639 public final function setCallbackInstance (FrameworkInterface $callbackInstance) {
640 $this->callbackInstance = $callbackInstance;
644 * Getter for call-back instance
646 * @return $callbackInstance An instance of a FrameworkInterface class
648 protected final function getCallbackInstance () {
649 return $this->callbackInstance;
653 * Checks whether an object equals this object. You should overwrite this
654 * method to implement own equality checks
656 * @param $objectInstance An instance of a FrameworkInterface object
657 * @return $equals Whether both objects equals
659 public function equals (FrameworkInterface $objectInstance) {
662 $this->__toString() == $objectInstance->__toString()
664 $this->hashCode() == $objectInstance->hashCode()
672 * Generates a generic hash code of this class. You should really overwrite
673 * this method with your own hash code generator code. But keep KISS in mind.
675 * @return $hashCode A generic hash code respresenting this whole class
677 public function hashCode () {
679 return crc32($this->__toString());
683 * Appends a trailing slash to a string
685 * @param $str A string (maybe) without trailing slash
686 * @return $str A string with an auto-appended trailing slash
688 public final function addMissingTrailingSlash ($str) {
689 // Is there a trailing slash?
690 if (substr($str, -1, 1) != '/') {
694 // Return string with trailing slash
699 * Debugs this instance by putting out it's full content
701 * @param $message Optional message to show in debug output
704 public final function debugInstance ($message = '') {
705 // Restore the error handler to avoid trouble with missing array elements or undeclared variables
706 restore_error_handler();
712 if (!empty($message)) {
714 $content = sprintf('<div class="debug_message">
716 </div>' . PHP_EOL, $message);
719 // Generate the output
720 $content .= sprintf('<pre>%s</pre>',
729 ApplicationEntryPoint::exitApplication(sprintf('<div class="debug_header">
732 <div class="debug_content">
736 <div class="debug_include_list">
741 ClassLoader::getSelfInstance()->getPrintableIncludeList()
746 * Replaces control characters with printable output
748 * @param $str String with control characters
749 * @return $str Replaced string
751 protected function replaceControlCharacters ($str) {
754 chr(13), '[r]', str_replace(
755 chr(10), '[n]', str_replace(
765 * Output a partial stub message for the caller method
767 * @param $message An optional message to display
770 protected function partialStub ($message = '') {
772 $stubMessage = 'Partial stub!';
774 // Is an extra message given?
775 if (!empty($message)) {
776 // Then add it as well
777 $stubMessage .= ' Message: ' . $message;
780 // Debug instance is there?
781 if (!is_null($this->getDebugInstance())) {
782 // Output stub message
783 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput($stubMessage);
786 trigger_error($stubMessage);
792 * Outputs a debug backtrace and stops further script execution
794 * @param $message An optional message to output
795 * @param $doExit Whether exit the program (true is default)
798 public function debugBackTrace ($message = '', $doExit = true) {
799 // Sorry, there is no other way getting this nice backtrace
800 if (!empty($message)) {
802 printf('Message: %s<br />' . PHP_EOL, $message);
806 debug_print_backtrace();
810 if ($doExit === true) {
816 * Creates an instance of a debugger instance
818 * @param $className Name of the class (currently unsupported)
819 * @param $lineNumber Line number where the call was made
820 * @return $debugInstance An instance of a debugger class
821 * @deprecated Not fully, as the new Logger facilities are not finished yet.
823 public final static function createDebugInstance ($className, $lineNumber = NULL) {
824 // Is the instance set?
825 if (!GenericRegistry::getRegistry()->instanceExists('debug')) {
826 // Init debug instance
827 $debugInstance = NULL;
831 // Get a debugger instance
832 $debugInstance = DebugMiddleware::createDebugMiddleware(FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('debug_' . FrameworkBootstrap::getRequestTypeFromSystem() . '_class'), $className);
833 } catch (NullPointerException $e) {
834 // Didn't work, no instance there
835 exit(sprintf('Cannot create debugInstance! Exception=%s,message=%s,className=%s,lineNumber=%d' . PHP_EOL, $e->__toString(), $e->getMessage(), $className, $lineNumber));
838 // Empty string should be ignored and used for testing the middleware
839 DebugMiddleware::getSelfInstance()->output('');
841 // Set it in registry
842 GenericRegistry::getRegistry()->addInstance('debug', $debugInstance);
844 // Get instance from registry
845 $debugInstance = GenericRegistry::getRegistry()->getDebugInstance();
849 return $debugInstance;
853 * Simple output of a message with line-break
855 * @param $message Message to output
858 public function outputLine ($message) {
860 print($message . PHP_EOL);
864 * Outputs a debug message whether to debug instance (should be set!) or
865 * dies with or ptints the message. Do NEVER EVER rewrite the exit() call to
866 * ApplicationEntryPoint::app_exit(), this would cause an endless loop.
868 * @param $message Message we shall send out...
869 * @param $doPrint Whether print or die here (default: print)
870 * @paran $stripTags Whether to strip tags (default: false)
873 public function debugOutput ($message, $doPrint = true, $stripTags = false) {
874 // Set debug instance to NULL
875 $debugInstance = NULL;
878 $backtrace = debug_backtrace(!DEBUG_BACKTRACE_PROVIDE_OBJECT);
880 // Is function partialStub/__callStatic ?
881 if (in_array($backtrace[1]['function'], array('partialStub', '__call', '__callStatic'))) {
882 // Prepend class::function:line from 3rd element
883 $message = sprintf('[%s::%s:%d]: %s',
884 $backtrace[2]['class'],
885 $backtrace[2]['function'],
886 (isset($backtrace[2]['line']) ? $backtrace[2]['line'] : '0'),
890 // Prepend class::function:line from 2nd element
891 $message = sprintf('[%s::%s:%d]: %s',
892 $backtrace[1]['class'],
893 $backtrace[1]['function'],
894 (isset($backtrace[1]['line']) ? $backtrace[1]['line'] : '0'),
901 // Get debug instance
902 $debugInstance = $this->getDebugInstance();
903 } catch (NullPointerException $e) {
904 // The debug instance is not set (yet)
907 // Is the debug instance there?
908 if (is_object($debugInstance)) {
909 // Use debug output handler
910 $debugInstance->output($message, $stripTags);
912 if ($doPrint === false) {
913 // Die here if not printed
917 // Are debug times enabled?
918 if (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('debug_' . FrameworkBootstrap::getRequestTypeFromSystem() . '_output_timings') == 'Y') {
920 $message = $this->getPrintableExecutionTime() . $message;
924 if ($doPrint === true) {
926 $this->outputLine($message);
935 * Marks up the code by adding e.g. line numbers
937 * @param $phpCode Unmarked PHP code
938 * @return $markedCode Marked PHP code
940 public function markupCode ($phpCode) {
945 $errorArray = error_get_last();
947 // Init the code with error message
948 if (is_array($errorArray)) {
950 $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>',
951 basename($errorArray['file']),
953 $errorArray['message'],
958 // Add line number to the code
959 foreach (explode(chr(10), $phpCode) as $lineNo => $code) {
961 $markedCode .= sprintf('<span id="code_line">%s</span>: %s' . PHP_EOL,
963 htmlentities($code, ENT_QUOTES)
972 * "Getter" for databse entry
974 * @return $entry An array with database entries
975 * @throws NullPointerException If the database result is not found
976 * @throws InvalidDatabaseResultException If the database result is invalid
978 protected final function getDatabaseEntry () {
979 // Is there an instance?
980 if (!$this->getResultInstance() instanceof SearchableResult) {
981 // Throw an exception here
982 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
986 $this->getResultInstance()->rewind();
988 // Do we have an entry?
989 if ($this->getResultInstance()->valid() === false) {
990 // @TODO Move the constant to e.g. BaseDatabaseResult when there is a non-cached database result available
991 throw new InvalidDatabaseResultException(array($this, $this->getResultInstance()), CachedDatabaseResult::EXCEPTION_INVALID_DATABASE_RESULT);
995 $this->getResultInstance()->next();
998 $entry = $this->getResultInstance()->current();
1005 * Getter for field name
1007 * @param $fieldName Field name which we shall get
1008 * @return $fieldValue Field value from the user
1009 * @throws NullPointerException If the result instance is null
1011 public final function getField (string $fieldName) {
1012 // Default field value
1015 // Get result instance
1016 $resultInstance = $this->getResultInstance();
1018 // Is this instance null?
1019 if (is_null($resultInstance)) {
1020 // Then the user instance is no longer valid (expired cookies?)
1021 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
1024 // Get current array
1025 $fieldArray = $resultInstance->current();
1026 //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput($fieldName.':<pre>'.print_r($fieldArray, true).'</pre>');
1028 // Convert dashes to underscore
1029 $fieldName2 = StringUtils::convertDashesToUnderscores($fieldName);
1031 // Does the field exist?
1032 if ($this->isFieldSet($fieldName)) {
1034 $fieldValue = $fieldArray[$fieldName2];
1035 } elseif (defined('DEVELOPER')) {
1036 // Missing field entry, may require debugging
1037 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']:fieldArray<pre>=' . print_r($fieldArray, true) . '</pre>,fieldName=' . $fieldName . ' not found!');
1039 // Missing field entry, may require debugging
1040 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']:fieldName=' . $fieldName . ' not found!');
1048 * Checks if given field is set
1050 * @param $fieldName Field name to check
1051 * @return $isSet Whether the given field name is set
1052 * @throws NullPointerException If the result instance is null
1054 public function isFieldSet (string $fieldName) {
1055 // Get result instance
1056 $resultInstance = $this->getResultInstance();
1058 // Is this instance null?
1059 if (is_null($resultInstance)) {
1060 // Then the user instance is no longer valid (expired cookies?)
1061 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
1064 // Get current array
1065 $fieldArray = $resultInstance->current();
1066 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('[' . $this->__toString() . ':' . __LINE__ . '] fieldName=' . $fieldName . ',fieldArray=<pre>'.print_r($fieldArray, true).'</pre>');
1068 // Convert dashes to underscore
1069 $fieldName = StringUtils::convertDashesToUnderscores($fieldName);
1072 $isSet = isset($fieldArray[$fieldName]);
1079 * Flushs all pending updates to the database layer
1083 public function flushPendingUpdates () {
1084 // Get result instance
1085 $resultInstance = $this->getResultInstance();
1087 // Do we have data to update?
1088 if ((is_object($resultInstance)) && ($resultInstance->ifDataNeedsFlush())) {
1089 // Get wrapper class name config entry
1090 $configEntry = $resultInstance->getUpdateInstance()->getWrapperConfigEntry();
1092 // Create object instance
1093 $wrapperInstance = DatabaseWrapperFactory::createWrapperByConfiguredName($configEntry);
1095 // Yes, then send the whole result to the database layer
1096 $wrapperInstance->doUpdateByResult($this->getResultInstance());
1101 * Outputs a deprecation warning to the developer.
1103 * @param $message The message we shall output to the developer
1105 * @todo Write a logging mechanism for productive mode
1107 public function deprecationWarning ($message) {
1108 // Is developer mode active?
1109 if (defined('DEVELOPER')) {
1110 // Debug instance is there?
1111 if (!is_null($this->getDebugInstance())) {
1112 // Output stub message
1113 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput($message);
1116 trigger_error($message . "<br />\n");
1120 // @TODO Finish this part!
1121 $this->partialStub('Developer mode inactive. Message:' . $message);
1126 * Checks whether the given PHP extension is loaded
1128 * @param $phpExtension The PHP extension we shall check
1129 * @return $isLoaded Whether the PHP extension is loaded
1131 public final function isPhpExtensionLoaded ($phpExtension) {
1133 $isLoaded = in_array($phpExtension, get_loaded_extensions());
1140 * "Getter" as a time() replacement but with milliseconds. You should use this
1141 * method instead of the encapsulated getimeofday() function.
1143 * @return $milliTime Timestamp with milliseconds
1145 public function getMilliTime () {
1146 // Get the time of day as float
1147 $milliTime = gettimeofday(true);
1154 * Idles (sleeps) for given milliseconds
1156 * @return $hasSlept Whether it goes fine
1158 public function idle ($milliSeconds) {
1159 // Sleep is fine by default
1162 // Idle so long with found function
1163 if (function_exists('time_sleep_until')) {
1164 // Get current time and add idle time
1165 $sleepUntil = $this->getMilliTime() + abs($milliSeconds) / 1000;
1167 // New PHP 5.1.0 function found, ignore errors
1168 $hasSlept = @time_sleep_until($sleepUntil);
1171 * My Sun station doesn't have that function even with latest PHP
1174 usleep($milliSeconds * 1000);
1182 * Checks whether the given encoded data was encoded with Base64
1184 * @param $encodedData Encoded data we shall check
1185 * @return $isBase64 Whether the encoded data is Base64
1187 protected function isBase64Encoded ($encodedData) {
1189 $isBase64 = (@base64_decode($encodedData, true) !== false);
1196 * Gets a cache key from Criteria instance
1198 * @param $criteriaInstance An instance of a Criteria class
1199 * @param $onlyKeys Only use these keys for a cache key
1200 * @return $cacheKey A cache key suitable for lookup/storage purposes
1202 protected function getCacheKeyByCriteria (Criteria $criteriaInstance, array $onlyKeys = []) {
1204 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FRAMEWORK-SYSTEM: criteriaInstance=' . $criteriaInstance->__toString() . ',onlyKeys()=' . count($onlyKeys) . ' - CALLED!');
1205 $cacheKey = sprintf('%s@%s',
1206 $this->__toString(),
1207 $criteriaInstance->getCacheKey($onlyKeys)
1211 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FRAMEWORK-SYSTEM: cacheKey=' . $cacheKey . ' - EXIT!');
1216 * Getter for startup time in miliseconds
1218 * @return $startupTime Startup time in miliseconds
1220 protected function getStartupTime () {
1221 return self::$startupTime;
1225 * "Getter" for a printable currently execution time in nice braces
1227 * @return $executionTime Current execution time in nice braces
1229 protected function getPrintableExecutionTime () {
1230 // Caculate the execution time
1231 $executionTime = microtime(true) - $this->getStartupTime();
1233 // Pack it in nice braces
1234 $executionTime = sprintf('[ %01.5f ] ', $executionTime);
1237 return $executionTime;
1241 * Hashes a given string with a simple but stronger hash function (no salt)
1242 * and hex-encode it.
1244 * @param $str The string to be hashed
1245 * @return $hash The hash from string $str
1247 public static final function hash ($str) {
1248 // Hash given string with (better secure) hasher
1249 $hash = bin2hex(mhash(MHASH_SHA256, $str));
1256 * "Getter" for length of hash() output. This will be "cached" to speed up
1259 * @return $length Length of hash() output
1261 public static final function getHashLength () {
1263 if (is_null(self::$hashLength)) {
1264 // No, then hash a string and save its length.
1265 self::$hashLength = strlen(self::hash('abc123'));
1269 return self::$hashLength;
1273 * Checks whether the given number is really a number (only chars 0-9).
1275 * @param $num A string consisting only chars between 0 and 9
1276 * @param $castValue Whether to cast the value to double. Do only use this to secure numbers from Requestable classes.
1277 * @param $assertMismatch Whether to assert mismatches
1278 * @return $ret The (hopefully) secured numbered value
1280 public function bigintval ($num, $castValue = true, $assertMismatch = false) {
1281 // Filter all numbers out
1282 $ret = preg_replace('/[^0123456789]/', '', $num);
1285 if ($castValue === true) {
1286 // Cast to biggest numeric type
1287 $ret = (double) $ret;
1290 // Assert only if requested
1291 if ($assertMismatch === true) {
1292 // Has the whole value changed?
1293 assert(('' . $ret . '' != '' . $num . '') && (!is_null($num)));
1301 * Checks whether the given hexadecimal number is really a hex-number (only chars 0-9,a-f).
1303 * @param $num A string consisting only chars between 0 and 9
1304 * @param $assertMismatch Whether to assert mismatches
1305 * @return $ret The (hopefully) secured hext-numbered value
1307 public function hexval ($num, $assertMismatch = false) {
1308 // Filter all numbers out
1309 $ret = preg_replace('/[^0123456789abcdefABCDEF]/', '', $num);
1311 // Assert only if requested
1312 if ($assertMismatch === true) {
1313 // Has the whole value changed?
1314 assert(('' . $ret . '' != '' . $num . '') && (!is_null($num)));
1322 * Determines if an element is set in the generic array
1324 * @param $keyGroup Main group for the key
1325 * @param $subGroup Sub group for the key
1326 * @param $key Key to check
1327 * @param $element Element to check
1328 * @return $isset Whether the given key is set
1330 protected final function isGenericArrayElementSet ($keyGroup, $subGroup, $key, $element) {
1332 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element);
1335 $isset = isset($this->genericArray[$keyGroup][$subGroup][$key][$element]);
1341 * Determines if a key is set in the generic array
1343 * @param $keyGroup Main group for the key
1344 * @param $subGroup Sub group for the key
1345 * @param $key Key to check
1346 * @return $isset Whether the given key is set
1348 protected final function isGenericArrayKeySet ($keyGroup, $subGroup, $key) {
1350 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1353 $isset = isset($this->genericArray[$keyGroup][$subGroup][$key]);
1361 * Determines if a group is set in the generic array
1363 * @param $keyGroup Main group
1364 * @param $subGroup Sub group
1365 * @return $isset Whether the given group is set
1367 protected final function isGenericArrayGroupSet ($keyGroup, $subGroup) {
1369 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup);
1372 $isset = isset($this->genericArray[$keyGroup][$subGroup]);
1379 * Getter for sub key group
1381 * @param $keyGroup Main key group
1382 * @param $subGroup Sub key group
1383 * @return $array An array with all array elements
1385 protected final function getGenericSubArray ($keyGroup, $subGroup) {
1387 if (!$this->isGenericArrayGroupSet($keyGroup, $subGroup)) {
1388 // No, then abort here
1389 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' not found.');
1394 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',value=' . print_r($this->genericArray[$keyGroup][$subGroup], true));
1397 return $this->genericArray[$keyGroup][$subGroup];
1401 * Unsets a given key in generic array
1403 * @param $keyGroup Main group for the key
1404 * @param $subGroup Sub group for the key
1405 * @param $key Key to unset
1408 protected final function unsetGenericArrayKey ($keyGroup, $subGroup, $key) {
1410 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1413 unset($this->genericArray[$keyGroup][$subGroup][$key]);
1417 * Unsets a given element in generic array
1419 * @param $keyGroup Main group for the key
1420 * @param $subGroup Sub group for the key
1421 * @param $key Key to unset
1422 * @param $element Element to unset
1425 protected final function unsetGenericArrayElement ($keyGroup, $subGroup, $key, $element) {
1427 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element);
1430 unset($this->genericArray[$keyGroup][$subGroup][$key][$element]);
1434 * Append a string to a given generic array key
1436 * @param $keyGroup Main group for the key
1437 * @param $subGroup Sub group for the key
1438 * @param $key Key to unset
1439 * @param $value Value to add/append
1442 protected final function appendStringToGenericArrayKey ($keyGroup, $subGroup, $key, $value, $appendGlue = '') {
1444 //* 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);
1446 // Is it already there?
1447 if ($this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
1449 $this->genericArray[$keyGroup][$subGroup][$key] .= $appendGlue . (string) $value;
1452 $this->genericArray[$keyGroup][$subGroup][$key] = (string) $value;
1457 * Append a string to a given generic array element
1459 * @param $keyGroup Main group for the key
1460 * @param $subGroup Sub group for the key
1461 * @param $key Key to unset
1462 * @param $element Element to check
1463 * @param $value Value to add/append
1466 protected final function appendStringToGenericArrayElement ($keyGroup, $subGroup, $key, $element, $value, $appendGlue = '') {
1468 //* 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);
1470 // Is it already there?
1471 if ($this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element)) {
1473 $this->genericArray[$keyGroup][$subGroup][$key][$element] .= $appendGlue . (string) $value;
1476 $this->setStringGenericArrayElement($keyGroup, $subGroup, $key, $element, $value);
1481 * Sets a string in a given generic array element
1483 * @param $keyGroup Main group for the key
1484 * @param $subGroup Sub group for the key
1485 * @param $key Key to unset
1486 * @param $element Element to check
1487 * @param $value Value to add/append
1490 protected final function setStringGenericArrayElement ($keyGroup, $subGroup, $key, $element, $value, $appendGlue = '') {
1492 //* 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);
1495 $this->genericArray[$keyGroup][$subGroup][$key][$element] = (string) $value;
1499 * Initializes given generic array group
1501 * @param $keyGroup Main group for the key
1502 * @param $subGroup Sub group for the key
1503 * @param $key Key to use
1504 * @param $forceInit Optionally force initialization
1507 protected final function initGenericArrayGroup ($keyGroup, $subGroup, $forceInit = false) {
1509 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',forceInit=' . intval($forceInit));
1511 // Is it already set?
1512 if (($forceInit === false) && ($this->isGenericArrayGroupSet($keyGroup, $subGroup))) {
1513 // Already initialized
1514 trigger_error(__METHOD__ . ':keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' already initialized.');
1519 $this->genericArray[$keyGroup][$subGroup] = [];
1523 * Initializes given generic array key
1525 * @param $keyGroup Main group for the key
1526 * @param $subGroup Sub group for the key
1527 * @param $key Key to use
1528 * @param $forceInit Optionally force initialization
1531 protected final function initGenericArrayKey ($keyGroup, $subGroup, $key, $forceInit = false) {
1533 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',forceInit=' . intval($forceInit));
1535 // Is it already set?
1536 if (($forceInit === false) && ($this->isGenericArrayKeySet($keyGroup, $subGroup, $key))) {
1537 // Already initialized
1538 trigger_error(__METHOD__ . ':keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' already initialized.');
1543 $this->genericArray[$keyGroup][$subGroup][$key] = [];
1547 * Initializes given generic array element
1549 * @param $keyGroup Main group for the key
1550 * @param $subGroup Sub group for the key
1551 * @param $key Key to use
1552 * @param $element Element to use
1553 * @param $forceInit Optionally force initialization
1556 protected final function initGenericArrayElement ($keyGroup, $subGroup, $key, $element, $forceInit = false) {
1558 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element . ',forceInit=' . intval($forceInit));
1560 // Is it already set?
1561 if (($forceInit === false) && ($this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element))) {
1562 // Already initialized
1563 trigger_error(__METHOD__ . ':keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element . ' already initialized.');
1568 $this->genericArray[$keyGroup][$subGroup][$key][$element] = [];
1572 * Pushes an element to a generic key
1574 * @param $keyGroup Main group for the key
1575 * @param $subGroup Sub group for the key
1576 * @param $key Key to use
1577 * @param $value Value to add/append
1578 * @return $count Number of array elements
1580 protected final function pushValueToGenericArrayKey ($keyGroup, $subGroup, $key, $value) {
1582 //* NOISY-DEBUG: */ if (!is_object($value)) $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',value[' . gettype($value) . ']=' . print_r($value, true));
1585 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
1587 $this->initGenericArrayKey($keyGroup, $subGroup, $key);
1591 $count = array_push($this->genericArray[$keyGroup][$subGroup][$key], $value);
1594 //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], true));
1595 //* DEBUG: */ print(__METHOD__ . ': count=' . $count . PHP_EOL);
1600 * Pushes an element to a generic array element
1602 * @param $keyGroup Main group for the key
1603 * @param $subGroup Sub group for the key
1604 * @param $key Key to use
1605 * @param $element Element to check
1606 * @param $value Value to add/append
1607 * @return $count Number of array elements
1609 protected final function pushValueToGenericArrayElement ($keyGroup, $subGroup, $key, $element, $value) {
1611 //* 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));
1614 if (!$this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element)) {
1616 $this->initGenericArrayElement($keyGroup, $subGroup, $key, $element);
1620 $count = array_push($this->genericArray[$keyGroup][$subGroup][$key][$element], $value);
1623 //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], true));
1624 //* DEBUG: */ print(__METHOD__ . ': count=' . $count . PHP_EOL);
1629 * Pops an element from a generic group
1631 * @param $keyGroup Main group for the key
1632 * @param $subGroup Sub group for the key
1633 * @param $key Key to unset
1634 * @return $value Last "popped" value
1636 protected final function popGenericArrayElement ($keyGroup, $subGroup, $key) {
1638 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1641 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
1643 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' not found.');
1648 $value = array_pop($this->genericArray[$keyGroup][$subGroup][$key]);
1651 //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], true));
1652 //* DEBUG: */ print(__METHOD__ . ': value[' . gettype($value) . ']=' . print_r($value, true) . PHP_EOL);
1657 * Shifts an element from a generic group
1659 * @param $keyGroup Main group for the key
1660 * @param $subGroup Sub group for the key
1661 * @param $key Key to unset
1662 * @return $value Last "popped" value
1664 protected final function shiftGenericArrayElement ($keyGroup, $subGroup, $key) {
1666 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1669 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
1671 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' not found.');
1676 $value = array_shift($this->genericArray[$keyGroup][$subGroup][$key]);
1679 //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], true));
1680 //* DEBUG: */ print(__METHOD__ . ': value[' . gettype($value) . ']=' . print_r($value, true) . PHP_EOL);
1685 * Count generic array group
1687 * @param $keyGroup Main group for the key
1688 * @return $count Count of given group
1690 protected final function countGenericArray ($keyGroup) {
1692 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup);
1695 if (!isset($this->genericArray[$keyGroup])) {
1697 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ' not found.');
1702 $count = count($this->genericArray[$keyGroup]);
1705 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',count=' . $count);
1712 * Count generic array sub group
1714 * @param $keyGroup Main group for the key
1715 * @param $subGroup Sub group for the key
1716 * @return $count Count of given group
1718 protected final function countGenericArrayGroup ($keyGroup, $subGroup) {
1720 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup);
1723 if (!$this->isGenericArrayGroupSet($keyGroup, $subGroup)) {
1725 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' not found.');
1730 $count = count($this->genericArray[$keyGroup][$subGroup]);
1733 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',count=' . $count);
1740 * Count generic array elements
1742 * @param $keyGroup Main group for the key
1743 * @param $subGroup Sub group for the key
1744 * @para $key Key to count
1745 * @return $count Count of given key
1747 protected final function countGenericArrayElements ($keyGroup, $subGroup, $key) {
1749 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1752 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
1754 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' not found.');
1756 } elseif (!$this->isValidGenericArrayGroup($keyGroup, $subGroup)) {
1758 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' is not an array.');
1763 $count = count($this->genericArray[$keyGroup][$subGroup][$key]);
1766 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',count=' . $count);
1773 * Getter for whole generic group array
1775 * @param $keyGroup Key group to get
1776 * @return $array Whole generic array group
1778 protected final function getGenericArray ($keyGroup) {
1780 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup);
1783 if (!isset($this->genericArray[$keyGroup])) {
1785 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ' does not exist.');
1790 return $this->genericArray[$keyGroup];
1794 * Setter for generic array key
1796 * @param $keyGroup Key group to get
1797 * @param $subGroup Sub group for the key
1798 * @param $key Key to unset
1799 * @param $value Mixed value from generic array element
1802 protected final function setGenericArrayKey ($keyGroup, $subGroup, $key, $value) {
1804 //* NOISY-DEBUG: */ if (!is_object($value)) $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',value[' . gettype($value) . ']=' . print_r($value, true));
1807 $this->genericArray[$keyGroup][$subGroup][$key] = $value;
1811 * Getter for generic array key
1813 * @param $keyGroup Key group to get
1814 * @param $subGroup Sub group for the key
1815 * @param $key Key to unset
1816 * @return $value Mixed value from generic array element
1818 protected final function getGenericArrayKey ($keyGroup, $subGroup, $key) {
1820 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1823 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
1825 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' does not exist.');
1830 return $this->genericArray[$keyGroup][$subGroup][$key];
1834 * Sets a value in given generic array key/element
1836 * @param $keyGroup Main group for the key
1837 * @param $subGroup Sub group for the key
1838 * @param $key Key to set
1839 * @param $element Element to set
1840 * @param $value Value to set
1843 protected final function setGenericArrayElement ($keyGroup, $subGroup, $key, $element, $value) {
1845 //* 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));
1848 $this->genericArray[$keyGroup][$subGroup][$key][$element] = $value;
1852 * Getter for generic array element
1854 * @param $keyGroup Key group to get
1855 * @param $subGroup Sub group for the key
1856 * @param $key Key to look for
1857 * @param $element Element to look for
1858 * @return $value Mixed value from generic array element
1860 protected final function getGenericArrayElement ($keyGroup, $subGroup, $key, $element) {
1862 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element);
1865 if (!$this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element)) {
1867 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element . ' does not exist.');
1872 return $this->genericArray[$keyGroup][$subGroup][$key][$element];
1876 * Checks if a given sub group is valid (array)
1878 * @param $keyGroup Key group to get
1879 * @param $subGroup Sub group for the key
1880 * @return $isValid Whether given sub group is valid
1882 protected final function isValidGenericArrayGroup ($keyGroup, $subGroup) {
1884 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup);
1887 $isValid = (($this->isGenericArrayGroupSet($keyGroup, $subGroup)) && (is_array($this->getGenericSubArray($keyGroup, $subGroup))));
1894 * Checks if a given key is valid (array)
1896 * @param $keyGroup Key group to get
1897 * @param $subGroup Sub group for the key
1898 * @param $key Key to check
1899 * @return $isValid Whether given sub group is valid
1901 protected final function isValidGenericArrayKey ($keyGroup, $subGroup, $key) {
1903 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1906 $isValid = (($this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) && (is_array($this->getGenericArrayKey($keyGroup, $subGroup, $key))));
1913 * Initializes the web output instance
1917 protected function initWebOutputInstance () {
1918 // Get application instance
1919 $applicationInstance = GenericRegistry::getRegistry()->getInstance('application');
1921 // Init web output instance
1922 $outputInstance = ObjectFactory::createObjectByConfiguredName('output_class', array($applicationInstance));
1925 $this->setWebOutputInstance($outputInstance);
1929 * Translates boolean true to 'Y' and false to 'N'
1931 * @param $boolean Boolean value
1932 * @return $translated Translated boolean value
1934 public static final function translateBooleanToYesNo (bool $boolean) {
1935 // Make sure it is really boolean
1936 assert(is_bool($boolean));
1939 $translated = ($boolean === true) ? 'Y' : 'N';
1941 // ... and return it
1946 * Creates a full-qualified file name (FQFN) for given file name by adding
1947 * a configured temporary file path to it.
1949 * @param $infoInstance An instance of a SplFileInfo class
1950 * @return $tempInstance An instance of a SplFileInfo class (temporary file)
1951 * @throw PathWriteProtectedException If the path in 'temp_file_path' is write-protected
1952 * @throws FileIoException If the file cannot be written
1954 protected static function createTempPathForFile (SplFileInfo $infoInstance) {
1956 $basePath = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('temp_file_path');
1958 // Is the path writeable?
1959 if (!is_writable($basePath)) {
1960 // Path is write-protected
1961 throw new PathWriteProtectedException($infoInstance, self::EXCEPTION_PATH_CANNOT_BE_WRITTEN);
1965 $tempInstance = new SplFileInfo($basePath . DIRECTORY_SEPARATOR . $infoInstance->getBasename());
1968 if (!FrameworkBootstrap::isReachableFilePath($tempInstance)) {
1970 throw new FileIoException($tempInstance, self::EXCEPTION_FILE_NOT_REACHABLE);
1974 return $tempInstance;
1978 * "Getter" for a printable state name
1980 * @return $stateName Name of the node's state in a printable format
1982 public final function getPrintableState () {
1983 // Default is 'null'
1984 $stateName = 'null';
1986 // Get the state instance
1987 $stateInstance = $this->getStateInstance();
1989 // Is it an instance of Stateable?
1990 if ($stateInstance instanceof Stateable) {
1991 // Then use that state name
1992 $stateName = $stateInstance->getStateName();