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\Handler\Handleable;
18 use Org\Mxchange\CoreFramework\Helper\Helper;
19 use Org\Mxchange\CoreFramework\Loader\ClassLoader;
20 use Org\Mxchange\CoreFramework\Localization\ManageableLanguage;
21 use Org\Mxchange\CoreFramework\Manager\ManageableApplication;
22 use Org\Mxchange\CoreFramework\Middleware\Debug\DebugMiddleware;
23 use Org\Mxchange\CoreFramework\Registry\GenericRegistry;
24 use Org\Mxchange\CoreFramework\Result\Database\CachedDatabaseResult;
25 use Org\Mxchange\CoreFramework\Result\Search\SearchableResult;
26 use Org\Mxchange\CoreFramework\State\Stateable;
27 use Org\Mxchange\CoreFramework\Stream\Input\InputStream;
28 use Org\Mxchange\CoreFramework\Stream\Output\OutputStreamer;
29 use Org\Mxchange\CoreFramework\Stream\Output\OutputStream;
30 use Org\Mxchange\CoreFramework\User\ManageableAccount;
31 use Org\Mxchange\CoreFramework\Utils\String\StringUtils;
35 use \InvalidArgumentException;
41 * The simulator system class is the super class of all other classes. This
42 * class handles saving of games etc.
44 * @author Roland Haeder <webmaster@shipsimu.org>
46 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2020 Core Developer Team
47 * @license GNU GPL 3.0 or any newer version
48 * @link http://www.shipsimu.org
50 * This program is free software: you can redistribute it and/or modify
51 * it under the terms of the GNU General Public License as published by
52 * the Free Software Foundation, either version 3 of the License, or
53 * (at your option) any later version.
55 * This program is distributed in the hope that it will be useful,
56 * but WITHOUT ANY WARRANTY; without even the implied warranty of
57 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
58 * GNU General Public License for more details.
60 * You should have received a copy of the GNU General Public License
61 * along with this program. If not, see <http://www.gnu.org/licenses/>.
63 abstract class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
65 * Length of output from hash()
67 private static $hashLength = NULL;
70 * Self-referencing instance
72 private static $instance = NULL;
77 private $realClass = __CLASS__;
80 * Database result instance
82 private $resultInstance = NULL;
85 * Instance for user class
87 private $userInstance = NULL;
90 * Instance of a crypto helper
92 private $cryptoInstance = NULL;
95 * Instance of an Iterator class
97 private $iteratorInstance = NULL;
100 * A helper instance for the form
102 private $helperInstance = NULL;
105 * An instance of a InputStream class
107 private $inputStreamInstance = NULL;
110 * An instance of a OutputStream class
112 private $outputStreamInstance = NULL;
117 private $handlerInstance = NULL;
120 * An instance of a database wrapper class
122 private $wrapperInstance = NULL;
127 private $stateInstance = NULL;
132 private $callbackInstance = NULL;
137 private $genericArray = array();
139 /***********************
140 * Exception codes.... *
141 ***********************/
143 // @todo Try to clean these constants up
144 const EXCEPTION_IS_NULL_POINTER = 0x001;
145 const EXCEPTION_IS_NO_OBJECT = 0x002;
146 const EXCEPTION_IS_NO_ARRAY = 0x003;
147 const EXCEPTION_MISSING_METHOD = 0x004;
148 const EXCEPTION_CLASSES_NOT_MATCHING = 0x005;
149 const EXCEPTION_INDEX_OUT_OF_BOUNDS = 0x006;
150 const EXCEPTION_DIMENSION_ARRAY_INVALID = 0x007;
151 const EXCEPTION_ITEM_NOT_TRADEABLE = 0x008;
152 const EXCEPTION_ITEM_NOT_IN_PRICE_LIST = 0x009;
153 const EXCEPTION_GENDER_IS_WRONG = 0x00a;
154 const EXCEPTION_BIRTH_DATE_IS_INVALID = 0x00b;
155 const EXCEPTION_EMPTY_STRUCTURES_ARRAY = 0x00c;
156 const EXCEPTION_HAS_ALREADY_PERSONELL_LIST = 0x00d;
157 const EXCEPTION_NOT_ENOUGTH_UNEMPLOYEES = 0x00e;
158 const EXCEPTION_TOTAL_PRICE_NOT_CALCULATED = 0x00f;
159 const EXCEPTION_HARBOR_HAS_NO_SHIPYARDS = 0x010;
160 const EXCEPTION_CONTRACT_PARTNER_INVALID = 0x011;
161 const EXCEPTION_CONTRACT_PARTNER_MISMATCH = 0x012;
162 const EXCEPTION_CONTRACT_ALREADY_SIGNED = 0x013;
163 const EXCEPTION_UNEXPECTED_EMPTY_STRING = 0x014;
164 const EXCEPTION_PATH_NOT_FOUND = 0x015;
165 const EXCEPTION_INVALID_PATH_NAME = 0x016;
166 const EXCEPTION_READ_PROTECED_PATH = 0x017;
167 const EXCEPTION_WRITE_PROTECED_PATH = 0x018;
168 const EXCEPTION_DIR_POINTER_INVALID = 0x019;
169 const EXCEPTION_FILE_POINTER_INVALID = 0x01a;
170 const EXCEPTION_INVALID_RESOURCE = 0x01b;
171 const EXCEPTION_UNEXPECTED_OBJECT = 0x01c;
172 const EXCEPTION_LIMIT_ELEMENT_IS_UNSUPPORTED = 0x01d;
173 const EXCEPTION_GETTER_IS_MISSING = 0x01e;
174 const EXCEPTION_ARRAY_EXPECTED = 0x01f;
175 const EXCEPTION_ARRAY_HAS_INVALID_COUNT = 0x020;
176 const EXCEPTION_ID_IS_INVALID_FORMAT = 0x021;
177 const EXCEPTION_MD5_CHECKSUMS_MISMATCH = 0x022;
178 const EXCEPTION_UNEXPECTED_STRING_SIZE = 0x023;
179 const EXCEPTION_SIMULATOR_ID_INVALID = 0x024;
180 const EXCEPTION_MISMATCHING_COMPRESSORS = 0x025;
181 const EXCEPTION_CONTAINER_ITEM_IS_NULL = 0x026;
182 const EXCEPTION_ITEM_IS_NO_ARRAY = 0x027;
183 const EXCEPTION_CONTAINER_MAYBE_DAMAGED = 0x028;
184 const EXCEPTION_INVALID_STRING = 0x029;
185 const EXCEPTION_VARIABLE_NOT_SET = 0x02a;
186 const EXCEPTION_ATTRIBUTES_ARE_MISSING = 0x02b;
187 const EXCEPTION_ARRAY_ELEMENTS_MISSING = 0x02c;
188 const EXCEPTION_TEMPLATE_ENGINE_UNSUPPORTED = 0x02d;
189 const EXCEPTION_UNSPPORTED_OPERATION = 0x02e;
190 const EXCEPTION_FACTORY_REQUIRE_PARAMETER = 0x02f;
191 const EXCEPTION_MISSING_ELEMENT = 0x030;
192 const EXCEPTION_HEADERS_ALREADY_SENT = 0x031;
193 const EXCEPTION_DEFAULT_CONTROLLER_GONE = 0x032;
194 const EXCEPTION_CLASS_NOT_FOUND = 0x033;
195 const EXCEPTION_REQUIRED_INTERFACE_MISSING = 0x034;
196 const EXCEPTION_FATAL_ERROR = 0x035;
197 const EXCEPTION_FILE_NOT_FOUND = 0x036;
198 const EXCEPTION_ASSERTION_FAILED = 0x037;
199 const EXCEPTION_FILE_NOT_REACHABLE = 0x038;
200 const EXCEPTION_FILE_CANNOT_BE_READ = 0x039;
201 const EXCEPTION_FILE_CANNOT_BE_WRITTEN = 0x03a;
202 const EXCEPTION_PATH_CANNOT_BE_WRITTEN = 0x03b;
203 const EXCEPTION_DATABASE_UPDATED_NOT_ALLOWED = 0x03c;
204 const EXCEPTION_FILTER_CHAIN_INTERCEPTED = 0x03d;
205 const EXCEPTION_INVALID_SOCKET = 0x03e;
206 const EXCEPTION_SELF_INSTANCE = 0x03f;
209 * Startup time in miliseconds
211 private static $startupTime = 0;
214 * Protected super constructor
216 * @param $className Name of the class
219 protected function __construct (string $className) {
221 $this->setRealClass($className);
223 // Is the startup time set? (0 cannot be true anymore)
224 if (self::$startupTime == 0) {
226 self::$startupTime = microtime(true);
231 * Destructor for all classes. You should not call this method on your own.
235 public function __destruct () {
236 // Flush any updated entries to the database
237 $this->flushPendingUpdates();
239 // Is this object already destroyed?
240 if ($this->__toString() != 'DestructedObject') {
241 // Destroy all informations about this class but keep some text about it alive
242 $this->setRealClass('DestructedObject');
243 } elseif ((defined('DEBUG_DESTRUCTOR')) && (is_object($this->getDebugInstance()))) {
244 // Already destructed object
245 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('The object <span class="object_name">%s</span> is already destroyed.',
249 // Do not call this twice
250 trigger_error(__METHOD__ . ': Called twice.');
256 * The __call() method where all non-implemented methods end up
258 * @param $methodName Name of the missing method
259 * @args $args Arguments passed to the method
262 public final function __call (string $methodName, array $args = NULL) {
264 self::$instance = $this;
266 // Call static method
267 self::__callStatic($methodName, $args);
269 // Clear self-instance
270 self::$instance = NULL;
274 * The __callStatic() method where all non-implemented static methods end up
276 * @param $methodName Name of the missing method
277 * @param $args Arguments passed to the method
279 * @throws InvalidArgumentException If self::$instance is not a framework's own object
281 public static final function __callStatic (string $methodName, array $args = NULL) {
282 // Init argument string and class name
283 //* PRINT-DEBUG: */ printf('[%s:%d]: methodName=%s,args[]=%s - CALLED!' . PHP_EOL, __METHOD__, __LINE__, $methodName, gettype($args));
285 $className = 'unknown';
287 // Is self-instance set?
288 if (self::$instance instanceof FrameworkInterface) {
289 // Framework's own instance
290 $className = self::$instance->__toString();
291 } elseif (!is_null(self::$instance)) {
293 throw new InvalidArgumentException(sprintf('self::instance[%s] is not expected.', gettype(self::$instance)), self::EXCEPTION_SELF_INSTANCE);
296 // Is it NULL, empty or an array?
297 if (is_null($args)) {
299 $argsString = 'NULL';
300 } elseif (is_array($args)) {
304 // Some arguments are there
305 foreach ($args as $arg) {
306 // Add data about the argument
307 $argsString .= gettype($arg) . ':';
310 // Found a NULL argument
311 $argsString .= 'NULL';
312 } elseif (is_string($arg)) {
313 // Add length for strings
314 $argsString .= strlen($arg);
315 } elseif ((is_int($arg)) || (is_float($arg))) {
318 } elseif (is_array($arg)) {
319 // .. or size if array
320 $argsString .= count($arg);
321 } elseif (is_object($arg)) {
323 $reflection = new ReflectionClass($arg);
325 // Is an other object, maybe no __toString() available
326 $argsString .= $reflection->getName();
327 } elseif ($arg === true) {
328 // ... is boolean 'true'
329 $argsString .= 'true';
330 } elseif ($arg === false) {
331 // ... is boolean 'false'
332 $argsString .= 'false';
335 // Comma for next one
340 if (substr($argsString, -2, 1) == ',') {
342 $argsString = substr($argsString, 0, -2);
349 // Output stub message
350 // @TODO __CLASS__ does always return BaseFrameworkSystem but not the extending (=child) class
351 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s::%s]: Stub! Args: %s',
362 * Getter for $realClass
364 * @return $realClass The name of the real class (not BaseFrameworkSystem)
366 public function __toString () {
367 return $this->realClass;
371 * Magic method to catch setting of missing but set class fields/attributes
373 * @param $name Name of the field/attribute
374 * @param $value Value to store
377 public final function __set (string $name, $value) {
378 $this->debugBackTrace(sprintf('Tried to set a missing field. name=%s, value[%s]=%s',
381 print_r($value, true)
386 * Magic method to catch getting of missing fields/attributes
388 * @param $name Name of the field/attribute
391 public final function __get (string $name) {
392 $this->debugBackTrace(sprintf('Tried to get a missing field. name=%s',
398 * Magic method to catch unsetting of missing fields/attributes
400 * @param $name Name of the field/attribute
403 public final function __unset (string $name) {
404 $this->debugBackTrace(sprintf('Tried to unset a missing field. name=%s',
410 * Magic method to catch object serialization
412 * @return $unsupported Unsupported method
413 * @throws UnsupportedOperationException Objects of this framework cannot be serialized
415 public final function __sleep () {
416 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
420 * Magic method to catch object deserialization
422 * @return $unsupported Unsupported method
423 * @throws UnsupportedOperationException Objects of this framework cannot be serialized
425 public final function __wakeup () {
426 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
430 * Magic method to catch calls when an object instance is called
432 * @return $unsupported Unsupported method
433 * @throws UnsupportedOperationException Objects of this framework cannot be serialized
435 public final function __invoke () {
436 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
440 * Setter for the real class name
442 * @param $realClass Class name (string)
445 public final function setRealClass (string $realClass) {
447 $this->realClass = $realClass;
451 * Setter for database result instance
453 * @param $resultInstance An instance of a database result class
455 * @todo SearchableResult and UpdateableResult shall have a super interface to use here
457 protected final function setResultInstance (SearchableResult $resultInstance) {
458 $this->resultInstance = $resultInstance;
462 * Getter for database result instance
464 * @return $resultInstance An instance of a database result class
466 public final function getResultInstance () {
467 return $this->resultInstance;
471 * Setter for debug instance
473 * @param $debugInstance The instance for debug output class
476 public final function setDebugInstance (DebugMiddleware $debugInstance) {
477 GenericRegistry::getRegistry()->addInstance('debug', $debugInstance);
481 * Getter for debug instance
483 * @return $debugInstance Instance to class DebugConsoleOutput or DebugWebOutput
485 public final function getDebugInstance () {
486 // Get debug instance
487 $debugInstance = GenericRegistry::getRegistry()->getInstance('debug');
490 return $debugInstance;
494 * Setter for web output instance
496 * @param $webInstance The instance for web output class
499 public final function setWebOutputInstance (OutputStreamer $webInstance) {
500 GenericRegistry::getRegistry()->addInstance('web_output', $webInstance);
504 * Getter for web output instance
506 * @return $webOutputInstance - Instance to class WebOutput
508 public final function getWebOutputInstance () {
509 $webOutputInstance = GenericRegistry::getRegistry()->getInstance('web_output');
510 return $webOutputInstance;
514 * Private getter for language instance
516 * @return $langInstance An instance to the language sub-system
518 protected final function getLanguageInstance () {
519 $langInstance = GenericRegistry::getRegistry()->getInstance('language');
520 return $langInstance;
524 * Setter for language instance
526 * @param $langInstance An instance to the language sub-system
528 * @see LanguageSystem
530 public final function setLanguageInstance (ManageableLanguage $langInstance) {
531 GenericRegistry::getRegistry()->addInstance('language', $langInstance);
535 * Protected setter for user instance
537 * @param $userInstance An instance of a user class
540 protected final function setUserInstance (ManageableAccount $userInstance) {
541 $this->userInstance = $userInstance;
545 * Getter for user instance
547 * @return $userInstance An instance of a user class
549 public final function getUserInstance () {
550 return $this->userInstance;
554 * Setter for Cryptable instance
556 * @param $cryptoInstance An instance of a Cryptable class
559 protected final function setCryptoInstance (Cryptable $cryptoInstance) {
560 $this->cryptoInstance = $cryptoInstance;
564 * Getter for Cryptable instance
566 * @return $cryptoInstance An instance of a Cryptable class
568 public final function getCryptoInstance () {
569 return $this->cryptoInstance;
573 * Setter for DatabaseWrapper instance
575 * @param $wrapperInstance An instance of an DatabaseWrapper
578 public final function setWrapperInstance (DatabaseWrapper $wrapperInstance) {
579 $this->wrapperInstance = $wrapperInstance;
583 * Getter for DatabaseWrapper instance
585 * @return $wrapperInstance An instance of an DatabaseWrapper
587 public final function getWrapperInstance () {
588 return $this->wrapperInstance;
592 * Setter for helper instance
594 * @param $helperInstance An instance of a helper class
597 protected final function setHelperInstance (Helper $helperInstance) {
598 $this->helperInstance = $helperInstance;
602 * Getter for helper instance
604 * @return $helperInstance An instance of a helper class
606 public final function getHelperInstance () {
607 return $this->helperInstance;
611 * Getter for a InputStream instance
613 * @param $inputStreamInstance The InputStream instance
615 protected final function getInputStreamInstance () {
616 return $this->inputStreamInstance;
620 * Setter for a InputStream instance
622 * @param $inputStreamInstance The InputStream instance
625 protected final function setInputStreamInstance (InputStream $inputStreamInstance) {
626 $this->inputStreamInstance = $inputStreamInstance;
630 * Getter for a OutputStream instance
632 * @param $outputStreamInstance The OutputStream instance
634 protected final function getOutputStreamInstance () {
635 return $this->outputStreamInstance;
639 * Setter for a OutputStream instance
641 * @param $outputStreamInstance The OutputStream instance
644 protected final function setOutputStreamInstance (OutputStream $outputStreamInstance) {
645 $this->outputStreamInstance = $outputStreamInstance;
649 * Setter for handler instance
651 * @param $handlerInstance An instance of a Handleable class
654 protected final function setHandlerInstance (Handleable $handlerInstance) {
655 $this->handlerInstance = $handlerInstance;
659 * Getter for handler instance
661 * @return $handlerInstance A Handleable instance
663 protected final function getHandlerInstance () {
664 return $this->handlerInstance;
668 * Setter for Iterator instance
670 * @param $iteratorInstance An instance of an Iterator
673 protected final function setIteratorInstance (Iterator $iteratorInstance) {
674 $this->iteratorInstance = $iteratorInstance;
678 * Getter for Iterator instance
680 * @return $iteratorInstance An instance of an Iterator
682 public final function getIteratorInstance () {
683 return $this->iteratorInstance;
687 * Setter for state instance
689 * @param $stateInstance A Stateable instance
692 public final function setStateInstance (Stateable $stateInstance) {
693 $this->stateInstance = $stateInstance;
697 * Getter for state instance
699 * @return $stateInstance A Stateable instance
701 public final function getStateInstance () {
702 return $this->stateInstance;
706 * Setter for call-back instance
708 * @param $callbackInstance An instance of a FrameworkInterface class
711 public final function setCallbackInstance (FrameworkInterface $callbackInstance) {
712 $this->callbackInstance = $callbackInstance;
716 * Getter for call-back instance
718 * @return $callbackInstance An instance of a FrameworkInterface class
720 protected final function getCallbackInstance () {
721 return $this->callbackInstance;
725 * Checks whether an object equals this object. You should overwrite this
726 * method to implement own equality checks
728 * @param $objectInstance An instance of a FrameworkInterface object
729 * @return $equals Whether both objects equals
731 public function equals (FrameworkInterface $objectInstance) {
734 $this->__toString() == $objectInstance->__toString()
736 $this->hashCode() == $objectInstance->hashCode()
744 * Generates a generic hash code of this class. You should really overwrite
745 * this method with your own hash code generator code. But keep KISS in mind.
747 * @return $hashCode A generic hash code respresenting this whole class
749 public function hashCode () {
751 return crc32($this->__toString());
755 * Appends a trailing slash to a string
757 * @param $str A string (maybe) without trailing slash
758 * @return $str A string with an auto-appended trailing slash
760 public final function addMissingTrailingSlash ($str) {
761 // Is there a trailing slash?
762 if (substr($str, -1, 1) != '/') {
766 // Return string with trailing slash
771 * Debugs this instance by putting out it's full content
773 * @param $message Optional message to show in debug output
776 public final function debugInstance ($message = '') {
777 // Restore the error handler to avoid trouble with missing array elements or undeclared variables
778 restore_error_handler();
784 if (!empty($message)) {
786 $content = sprintf('<div class="debug_message">
788 </div>' . PHP_EOL, $message);
791 // Generate the output
792 $content .= sprintf('<pre>%s</pre>',
801 ApplicationEntryPoint::exitApplication(sprintf('<div class="debug_header">
804 <div class="debug_content">
808 <div class="debug_include_list">
813 ClassLoader::getSelfInstance()->getPrintableIncludeList()
818 * Replaces control characters with printable output
820 * @param $str String with control characters
821 * @return $str Replaced string
823 protected function replaceControlCharacters ($str) {
826 chr(13), '[r]', str_replace(
827 chr(10), '[n]', str_replace(
837 * Output a partial stub message for the caller method
839 * @param $message An optional message to display
842 protected function partialStub ($message = '') {
844 $stubMessage = 'Partial stub!';
846 // Is an extra message given?
847 if (!empty($message)) {
848 // Then add it as well
849 $stubMessage .= ' Message: ' . $message;
852 // Debug instance is there?
853 if (!is_null($this->getDebugInstance())) {
854 // Output stub message
855 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput($stubMessage);
858 trigger_error($stubMessage);
864 * Outputs a debug backtrace and stops further script execution
866 * @param $message An optional message to output
867 * @param $doExit Whether exit the program (true is default)
870 public function debugBackTrace ($message = '', $doExit = true) {
871 // Sorry, there is no other way getting this nice backtrace
872 if (!empty($message)) {
874 printf('Message: %s<br />' . PHP_EOL, $message);
878 debug_print_backtrace();
882 if ($doExit === true) {
888 * Creates an instance of a debugger instance
890 * @param $className Name of the class (currently unsupported)
891 * @param $lineNumber Line number where the call was made
892 * @return $debugInstance An instance of a debugger class
893 * @deprecated Not fully, as the new Logger facilities are not finished yet.
895 public final static function createDebugInstance ($className, $lineNumber = NULL) {
896 // Is the instance set?
897 if (!GenericRegistry::getRegistry()->instanceExists('debug')) {
898 // Init debug instance
899 $debugInstance = NULL;
903 // Get a debugger instance
904 $debugInstance = DebugMiddleware::createDebugMiddleware(FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('debug_' . FrameworkBootstrap::getRequestTypeFromSystem() . '_class'), $className);
905 } catch (NullPointerException $e) {
906 // Didn't work, no instance there
907 exit(sprintf('Cannot create debugInstance! Exception=%s,message=%s,className=%s,lineNumber=%d' . PHP_EOL, $e->__toString(), $e->getMessage(), $className, $lineNumber));
910 // Empty string should be ignored and used for testing the middleware
911 DebugMiddleware::getSelfInstance()->output('');
913 // Set it in registry
914 GenericRegistry::getRegistry()->addInstance('debug', $debugInstance);
916 // Get instance from registry
917 $debugInstance = GenericRegistry::getRegistry()->getDebugInstance();
921 return $debugInstance;
925 * Simple output of a message with line-break
927 * @param $message Message to output
930 public function outputLine ($message) {
932 print($message . PHP_EOL);
936 * Outputs a debug message whether to debug instance (should be set!) or
937 * dies with or ptints the message. Do NEVER EVER rewrite the exit() call to
938 * ApplicationEntryPoint::app_exit(), this would cause an endless loop.
940 * @param $message Message we shall send out...
941 * @param $doPrint Whether print or die here (default: print)
942 * @paran $stripTags Whether to strip tags (default: false)
945 public function debugOutput ($message, $doPrint = true, $stripTags = false) {
946 // Set debug instance to NULL
947 $debugInstance = NULL;
950 $backtrace = debug_backtrace(!DEBUG_BACKTRACE_PROVIDE_OBJECT);
952 // Is function partialStub/__callStatic ?
953 if (in_array($backtrace[1]['function'], array('partialStub', '__call', '__callStatic'))) {
954 // Prepend class::function:line from 3rd element
955 $message = sprintf('[%s::%s:%d]: %s',
956 $backtrace[2]['class'],
957 $backtrace[2]['function'],
958 (isset($backtrace[2]['line']) ? $backtrace[2]['line'] : '0'),
962 // Prepend class::function:line from 2nd element
963 $message = sprintf('[%s::%s:%d]: %s',
964 $backtrace[1]['class'],
965 $backtrace[1]['function'],
966 (isset($backtrace[1]['line']) ? $backtrace[1]['line'] : '0'),
973 // Get debug instance
974 $debugInstance = $this->getDebugInstance();
975 } catch (NullPointerException $e) {
976 // The debug instance is not set (yet)
979 // Is the debug instance there?
980 if (is_object($debugInstance)) {
981 // Use debug output handler
982 $debugInstance->output($message, $stripTags);
984 if ($doPrint === false) {
985 // Die here if not printed
989 // Are debug times enabled?
990 if (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('debug_' . FrameworkBootstrap::getRequestTypeFromSystem() . '_output_timings') == 'Y') {
992 $message = $this->getPrintableExecutionTime() . $message;
996 if ($doPrint === true) {
998 $this->outputLine($message);
1007 * Marks up the code by adding e.g. line numbers
1009 * @param $phpCode Unmarked PHP code
1010 * @return $markedCode Marked PHP code
1012 public function markupCode ($phpCode) {
1017 $errorArray = error_get_last();
1019 // Init the code with error message
1020 if (is_array($errorArray)) {
1022 $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>',
1023 basename($errorArray['file']),
1024 $errorArray['line'],
1025 $errorArray['message'],
1030 // Add line number to the code
1031 foreach (explode(chr(10), $phpCode) as $lineNo => $code) {
1033 $markedCode .= sprintf('<span id="code_line">%s</span>: %s' . PHP_EOL,
1035 htmlentities($code, ENT_QUOTES)
1044 * "Getter" for databse entry
1046 * @return $entry An array with database entries
1047 * @throws NullPointerException If the database result is not found
1048 * @throws InvalidDatabaseResultException If the database result is invalid
1050 protected final function getDatabaseEntry () {
1051 // Is there an instance?
1052 if (!$this->getResultInstance() instanceof SearchableResult) {
1053 // Throw an exception here
1054 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
1058 $this->getResultInstance()->rewind();
1060 // Do we have an entry?
1061 if ($this->getResultInstance()->valid() === false) {
1062 // @TODO Move the constant to e.g. BaseDatabaseResult when there is a non-cached database result available
1063 throw new InvalidDatabaseResultException(array($this, $this->getResultInstance()), CachedDatabaseResult::EXCEPTION_INVALID_DATABASE_RESULT);
1067 $this->getResultInstance()->next();
1070 $entry = $this->getResultInstance()->current();
1077 * Getter for field name
1079 * @param $fieldName Field name which we shall get
1080 * @return $fieldValue Field value from the user
1081 * @throws NullPointerException If the result instance is null
1083 public final function getField (string $fieldName) {
1084 // Default field value
1087 // Get result instance
1088 $resultInstance = $this->getResultInstance();
1090 // Is this instance null?
1091 if (is_null($resultInstance)) {
1092 // Then the user instance is no longer valid (expired cookies?)
1093 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
1096 // Get current array
1097 $fieldArray = $resultInstance->current();
1098 //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput($fieldName.':<pre>'.print_r($fieldArray, true).'</pre>');
1100 // Convert dashes to underscore
1101 $fieldName2 = StringUtils::convertDashesToUnderscores($fieldName);
1103 // Does the field exist?
1104 if ($this->isFieldSet($fieldName)) {
1106 $fieldValue = $fieldArray[$fieldName2];
1107 } elseif (defined('DEVELOPER')) {
1108 // Missing field entry, may require debugging
1109 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']:fieldArray<pre>=' . print_r($fieldArray, true) . '</pre>,fieldName=' . $fieldName . ' not found!');
1111 // Missing field entry, may require debugging
1112 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']:fieldName=' . $fieldName . ' not found!');
1120 * Checks if given field is set
1122 * @param $fieldName Field name to check
1123 * @return $isSet Whether the given field name is set
1124 * @throws NullPointerException If the result instance is null
1126 public function isFieldSet (string $fieldName) {
1127 // Get result instance
1128 $resultInstance = $this->getResultInstance();
1130 // Is this instance null?
1131 if (is_null($resultInstance)) {
1132 // Then the user instance is no longer valid (expired cookies?)
1133 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
1136 // Get current array
1137 $fieldArray = $resultInstance->current();
1138 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('[' . $this->__toString() . ':' . __LINE__ . '] fieldName=' . $fieldName . ',fieldArray=<pre>'.print_r($fieldArray, true).'</pre>');
1140 // Convert dashes to underscore
1141 $fieldName = StringUtils::convertDashesToUnderscores($fieldName);
1144 $isSet = isset($fieldArray[$fieldName]);
1151 * Flushs all pending updates to the database layer
1155 public function flushPendingUpdates () {
1156 // Get result instance
1157 $resultInstance = $this->getResultInstance();
1159 // Do we have data to update?
1160 if ((is_object($resultInstance)) && ($resultInstance->ifDataNeedsFlush())) {
1161 // Get wrapper class name config entry
1162 $configEntry = $resultInstance->getUpdateInstance()->getWrapperConfigEntry();
1164 // Create object instance
1165 $wrapperInstance = DatabaseWrapperFactory::createWrapperByConfiguredName($configEntry);
1167 // Yes, then send the whole result to the database layer
1168 $wrapperInstance->doUpdateByResult($this->getResultInstance());
1173 * Outputs a deprecation warning to the developer.
1175 * @param $message The message we shall output to the developer
1177 * @todo Write a logging mechanism for productive mode
1179 public function deprecationWarning ($message) {
1180 // Is developer mode active?
1181 if (defined('DEVELOPER')) {
1182 // Debug instance is there?
1183 if (!is_null($this->getDebugInstance())) {
1184 // Output stub message
1185 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput($message);
1188 trigger_error($message . "<br />\n");
1192 // @TODO Finish this part!
1193 $this->partialStub('Developer mode inactive. Message:' . $message);
1198 * Checks whether the given PHP extension is loaded
1200 * @param $phpExtension The PHP extension we shall check
1201 * @return $isLoaded Whether the PHP extension is loaded
1203 public final function isPhpExtensionLoaded ($phpExtension) {
1205 $isLoaded = in_array($phpExtension, get_loaded_extensions());
1212 * "Getter" as a time() replacement but with milliseconds. You should use this
1213 * method instead of the encapsulated getimeofday() function.
1215 * @return $milliTime Timestamp with milliseconds
1217 public function getMilliTime () {
1218 // Get the time of day as float
1219 $milliTime = gettimeofday(true);
1226 * Idles (sleeps) for given milliseconds
1228 * @return $hasSlept Whether it goes fine
1230 public function idle ($milliSeconds) {
1231 // Sleep is fine by default
1234 // Idle so long with found function
1235 if (function_exists('time_sleep_until')) {
1236 // Get current time and add idle time
1237 $sleepUntil = $this->getMilliTime() + abs($milliSeconds) / 1000;
1239 // New PHP 5.1.0 function found, ignore errors
1240 $hasSlept = @time_sleep_until($sleepUntil);
1243 * My Sun station doesn't have that function even with latest PHP
1246 usleep($milliSeconds * 1000);
1254 * Checks whether the given encoded data was encoded with Base64
1256 * @param $encodedData Encoded data we shall check
1257 * @return $isBase64 Whether the encoded data is Base64
1259 protected function isBase64Encoded ($encodedData) {
1261 $isBase64 = (@base64_decode($encodedData, true) !== false);
1268 * Gets a cache key from Criteria instance
1270 * @param $criteriaInstance An instance of a Criteria class
1271 * @param $onlyKeys Only use these keys for a cache key
1272 * @return $cacheKey A cache key suitable for lookup/storage purposes
1274 protected function getCacheKeyByCriteria (Criteria $criteriaInstance, array $onlyKeys = array()) {
1276 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FRAMEWORK-SYSTEM: criteriaInstance=' . $criteriaInstance->__toString() . ',onlyKeys()=' . count($onlyKeys) . ' - CALLED!');
1277 $cacheKey = sprintf('%s@%s',
1278 $this->__toString(),
1279 $criteriaInstance->getCacheKey($onlyKeys)
1283 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FRAMEWORK-SYSTEM: cacheKey=' . $cacheKey . ' - EXIT!');
1288 * Getter for startup time in miliseconds
1290 * @return $startupTime Startup time in miliseconds
1292 protected function getStartupTime () {
1293 return self::$startupTime;
1297 * "Getter" for a printable currently execution time in nice braces
1299 * @return $executionTime Current execution time in nice braces
1301 protected function getPrintableExecutionTime () {
1302 // Caculate the execution time
1303 $executionTime = microtime(true) - $this->getStartupTime();
1305 // Pack it in nice braces
1306 $executionTime = sprintf('[ %01.5f ] ', $executionTime);
1309 return $executionTime;
1313 * Hashes a given string with a simple but stronger hash function (no salt)
1314 * and hex-encode it.
1316 * @param $str The string to be hashed
1317 * @return $hash The hash from string $str
1319 public static final function hash ($str) {
1320 // Hash given string with (better secure) hasher
1321 $hash = bin2hex(mhash(MHASH_SHA256, $str));
1328 * "Getter" for length of hash() output. This will be "cached" to speed up
1331 * @return $length Length of hash() output
1333 public static final function getHashLength () {
1335 if (is_null(self::$hashLength)) {
1336 // No, then hash a string and save its length.
1337 self::$hashLength = strlen(self::hash('abc123'));
1341 return self::$hashLength;
1345 * Checks whether the given number is really a number (only chars 0-9).
1347 * @param $num A string consisting only chars between 0 and 9
1348 * @param $castValue Whether to cast the value to double. Do only use this to secure numbers from Requestable classes.
1349 * @param $assertMismatch Whether to assert mismatches
1350 * @return $ret The (hopefully) secured numbered value
1352 public function bigintval ($num, $castValue = true, $assertMismatch = false) {
1353 // Filter all numbers out
1354 $ret = preg_replace('/[^0123456789]/', '', $num);
1357 if ($castValue === true) {
1358 // Cast to biggest numeric type
1359 $ret = (double) $ret;
1362 // Assert only if requested
1363 if ($assertMismatch === true) {
1364 // Has the whole value changed?
1365 assert(('' . $ret . '' != '' . $num . '') && (!is_null($num)));
1373 * Checks whether the given hexadecimal number is really a hex-number (only chars 0-9,a-f).
1375 * @param $num A string consisting only chars between 0 and 9
1376 * @param $assertMismatch Whether to assert mismatches
1377 * @return $ret The (hopefully) secured hext-numbered value
1379 public function hexval ($num, $assertMismatch = false) {
1380 // Filter all numbers out
1381 $ret = preg_replace('/[^0123456789abcdefABCDEF]/', '', $num);
1383 // Assert only if requested
1384 if ($assertMismatch === true) {
1385 // Has the whole value changed?
1386 assert(('' . $ret . '' != '' . $num . '') && (!is_null($num)));
1394 * Determines if an element is set in the generic array
1396 * @param $keyGroup Main group for the key
1397 * @param $subGroup Sub group for the key
1398 * @param $key Key to check
1399 * @param $element Element to check
1400 * @return $isset Whether the given key is set
1402 protected final function isGenericArrayElementSet ($keyGroup, $subGroup, $key, $element) {
1404 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element);
1407 $isset = isset($this->genericArray[$keyGroup][$subGroup][$key][$element]);
1413 * Determines if a key is set in the generic array
1415 * @param $keyGroup Main group for the key
1416 * @param $subGroup Sub group for the key
1417 * @param $key Key to check
1418 * @return $isset Whether the given key is set
1420 protected final function isGenericArrayKeySet ($keyGroup, $subGroup, $key) {
1422 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1425 $isset = isset($this->genericArray[$keyGroup][$subGroup][$key]);
1433 * Determines if a group is set in the generic array
1435 * @param $keyGroup Main group
1436 * @param $subGroup Sub group
1437 * @return $isset Whether the given group is set
1439 protected final function isGenericArrayGroupSet ($keyGroup, $subGroup) {
1441 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup);
1444 $isset = isset($this->genericArray[$keyGroup][$subGroup]);
1451 * Getter for sub key group
1453 * @param $keyGroup Main key group
1454 * @param $subGroup Sub key group
1455 * @return $array An array with all array elements
1457 protected final function getGenericSubArray ($keyGroup, $subGroup) {
1459 if (!$this->isGenericArrayGroupSet($keyGroup, $subGroup)) {
1460 // No, then abort here
1461 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' not found.');
1466 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',value=' . print_r($this->genericArray[$keyGroup][$subGroup], true));
1469 return $this->genericArray[$keyGroup][$subGroup];
1473 * Unsets a given key in generic array
1475 * @param $keyGroup Main group for the key
1476 * @param $subGroup Sub group for the key
1477 * @param $key Key to unset
1480 protected final function unsetGenericArrayKey ($keyGroup, $subGroup, $key) {
1482 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1485 unset($this->genericArray[$keyGroup][$subGroup][$key]);
1489 * Unsets a given element in generic array
1491 * @param $keyGroup Main group for the key
1492 * @param $subGroup Sub group for the key
1493 * @param $key Key to unset
1494 * @param $element Element to unset
1497 protected final function unsetGenericArrayElement ($keyGroup, $subGroup, $key, $element) {
1499 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element);
1502 unset($this->genericArray[$keyGroup][$subGroup][$key][$element]);
1506 * Append a string to a given generic array key
1508 * @param $keyGroup Main group for the key
1509 * @param $subGroup Sub group for the key
1510 * @param $key Key to unset
1511 * @param $value Value to add/append
1514 protected final function appendStringToGenericArrayKey ($keyGroup, $subGroup, $key, $value, $appendGlue = '') {
1516 //* 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);
1518 // Is it already there?
1519 if ($this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
1521 $this->genericArray[$keyGroup][$subGroup][$key] .= $appendGlue . (string) $value;
1524 $this->genericArray[$keyGroup][$subGroup][$key] = (string) $value;
1529 * Append a string to a given generic array element
1531 * @param $keyGroup Main group for the key
1532 * @param $subGroup Sub group for the key
1533 * @param $key Key to unset
1534 * @param $element Element to check
1535 * @param $value Value to add/append
1538 protected final function appendStringToGenericArrayElement ($keyGroup, $subGroup, $key, $element, $value, $appendGlue = '') {
1540 //* 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);
1542 // Is it already there?
1543 if ($this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element)) {
1545 $this->genericArray[$keyGroup][$subGroup][$key][$element] .= $appendGlue . (string) $value;
1548 $this->setStringGenericArrayElement($keyGroup, $subGroup, $key, $element, $value);
1553 * Sets a string in a given generic array element
1555 * @param $keyGroup Main group for the key
1556 * @param $subGroup Sub group for the key
1557 * @param $key Key to unset
1558 * @param $element Element to check
1559 * @param $value Value to add/append
1562 protected final function setStringGenericArrayElement ($keyGroup, $subGroup, $key, $element, $value, $appendGlue = '') {
1564 //* 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);
1567 $this->genericArray[$keyGroup][$subGroup][$key][$element] = (string) $value;
1571 * Initializes given generic array group
1573 * @param $keyGroup Main group for the key
1574 * @param $subGroup Sub group for the key
1575 * @param $key Key to use
1576 * @param $forceInit Optionally force initialization
1579 protected final function initGenericArrayGroup ($keyGroup, $subGroup, $forceInit = false) {
1581 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',forceInit=' . intval($forceInit));
1583 // Is it already set?
1584 if (($forceInit === false) && ($this->isGenericArrayGroupSet($keyGroup, $subGroup))) {
1585 // Already initialized
1586 trigger_error(__METHOD__ . ':keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' already initialized.');
1591 $this->genericArray[$keyGroup][$subGroup] = array();
1595 * Initializes given generic array key
1597 * @param $keyGroup Main group for the key
1598 * @param $subGroup Sub group for the key
1599 * @param $key Key to use
1600 * @param $forceInit Optionally force initialization
1603 protected final function initGenericArrayKey ($keyGroup, $subGroup, $key, $forceInit = false) {
1605 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',forceInit=' . intval($forceInit));
1607 // Is it already set?
1608 if (($forceInit === false) && ($this->isGenericArrayKeySet($keyGroup, $subGroup, $key))) {
1609 // Already initialized
1610 trigger_error(__METHOD__ . ':keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' already initialized.');
1615 $this->genericArray[$keyGroup][$subGroup][$key] = array();
1619 * Initializes given generic array element
1621 * @param $keyGroup Main group for the key
1622 * @param $subGroup Sub group for the key
1623 * @param $key Key to use
1624 * @param $element Element to use
1625 * @param $forceInit Optionally force initialization
1628 protected final function initGenericArrayElement ($keyGroup, $subGroup, $key, $element, $forceInit = false) {
1630 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element . ',forceInit=' . intval($forceInit));
1632 // Is it already set?
1633 if (($forceInit === false) && ($this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element))) {
1634 // Already initialized
1635 trigger_error(__METHOD__ . ':keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element . ' already initialized.');
1640 $this->genericArray[$keyGroup][$subGroup][$key][$element] = array();
1644 * Pushes an element to a generic key
1646 * @param $keyGroup Main group for the key
1647 * @param $subGroup Sub group for the key
1648 * @param $key Key to use
1649 * @param $value Value to add/append
1650 * @return $count Number of array elements
1652 protected final function pushValueToGenericArrayKey ($keyGroup, $subGroup, $key, $value) {
1654 //* NOISY-DEBUG: */ if (!is_object($value)) $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',value[' . gettype($value) . ']=' . print_r($value, true));
1657 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
1659 $this->initGenericArrayKey($keyGroup, $subGroup, $key);
1663 $count = array_push($this->genericArray[$keyGroup][$subGroup][$key], $value);
1666 //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], true));
1667 //* DEBUG: */ print(__METHOD__ . ': count=' . $count . PHP_EOL);
1672 * Pushes an element to a generic array element
1674 * @param $keyGroup Main group for the key
1675 * @param $subGroup Sub group for the key
1676 * @param $key Key to use
1677 * @param $element Element to check
1678 * @param $value Value to add/append
1679 * @return $count Number of array elements
1681 protected final function pushValueToGenericArrayElement ($keyGroup, $subGroup, $key, $element, $value) {
1683 //* 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));
1686 if (!$this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element)) {
1688 $this->initGenericArrayElement($keyGroup, $subGroup, $key, $element);
1692 $count = array_push($this->genericArray[$keyGroup][$subGroup][$key][$element], $value);
1695 //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], true));
1696 //* DEBUG: */ print(__METHOD__ . ': count=' . $count . PHP_EOL);
1701 * Pops an element from a generic group
1703 * @param $keyGroup Main group for the key
1704 * @param $subGroup Sub group for the key
1705 * @param $key Key to unset
1706 * @return $value Last "popped" value
1708 protected final function popGenericArrayElement ($keyGroup, $subGroup, $key) {
1710 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1713 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
1715 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' not found.');
1720 $value = array_pop($this->genericArray[$keyGroup][$subGroup][$key]);
1723 //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], true));
1724 //* DEBUG: */ print(__METHOD__ . ': value[' . gettype($value) . ']=' . print_r($value, true) . PHP_EOL);
1729 * Shifts an element from a generic group
1731 * @param $keyGroup Main group for the key
1732 * @param $subGroup Sub group for the key
1733 * @param $key Key to unset
1734 * @return $value Last "popped" value
1736 protected final function shiftGenericArrayElement ($keyGroup, $subGroup, $key) {
1738 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1741 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
1743 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' not found.');
1748 $value = array_shift($this->genericArray[$keyGroup][$subGroup][$key]);
1751 //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], true));
1752 //* DEBUG: */ print(__METHOD__ . ': value[' . gettype($value) . ']=' . print_r($value, true) . PHP_EOL);
1757 * Count generic array group
1759 * @param $keyGroup Main group for the key
1760 * @return $count Count of given group
1762 protected final function countGenericArray ($keyGroup) {
1764 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup);
1767 if (!isset($this->genericArray[$keyGroup])) {
1769 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ' not found.');
1774 $count = count($this->genericArray[$keyGroup]);
1777 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',count=' . $count);
1784 * Count generic array sub group
1786 * @param $keyGroup Main group for the key
1787 * @param $subGroup Sub group for the key
1788 * @return $count Count of given group
1790 protected final function countGenericArrayGroup ($keyGroup, $subGroup) {
1792 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup);
1795 if (!$this->isGenericArrayGroupSet($keyGroup, $subGroup)) {
1797 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' not found.');
1802 $count = count($this->genericArray[$keyGroup][$subGroup]);
1805 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',count=' . $count);
1812 * Count generic array elements
1814 * @param $keyGroup Main group for the key
1815 * @param $subGroup Sub group for the key
1816 * @para $key Key to count
1817 * @return $count Count of given key
1819 protected final function countGenericArrayElements ($keyGroup, $subGroup, $key) {
1821 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1824 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
1826 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' not found.');
1828 } elseif (!$this->isValidGenericArrayGroup($keyGroup, $subGroup)) {
1830 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' is not an array.');
1835 $count = count($this->genericArray[$keyGroup][$subGroup][$key]);
1838 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',count=' . $count);
1845 * Getter for whole generic group array
1847 * @param $keyGroup Key group to get
1848 * @return $array Whole generic array group
1850 protected final function getGenericArray ($keyGroup) {
1852 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup);
1855 if (!isset($this->genericArray[$keyGroup])) {
1857 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ' does not exist.');
1862 return $this->genericArray[$keyGroup];
1866 * Setter for generic array key
1868 * @param $keyGroup Key group to get
1869 * @param $subGroup Sub group for the key
1870 * @param $key Key to unset
1871 * @param $value Mixed value from generic array element
1874 protected final function setGenericArrayKey ($keyGroup, $subGroup, $key, $value) {
1876 //* NOISY-DEBUG: */ if (!is_object($value)) $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',value[' . gettype($value) . ']=' . print_r($value, true));
1879 $this->genericArray[$keyGroup][$subGroup][$key] = $value;
1883 * Getter for generic array key
1885 * @param $keyGroup Key group to get
1886 * @param $subGroup Sub group for the key
1887 * @param $key Key to unset
1888 * @return $value Mixed value from generic array element
1890 protected final function getGenericArrayKey ($keyGroup, $subGroup, $key) {
1892 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1895 if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
1897 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' does not exist.');
1902 return $this->genericArray[$keyGroup][$subGroup][$key];
1906 * Sets a value in given generic array key/element
1908 * @param $keyGroup Main group for the key
1909 * @param $subGroup Sub group for the key
1910 * @param $key Key to set
1911 * @param $element Element to set
1912 * @param $value Value to set
1915 protected final function setGenericArrayElement ($keyGroup, $subGroup, $key, $element, $value) {
1917 //* 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));
1920 $this->genericArray[$keyGroup][$subGroup][$key][$element] = $value;
1924 * Getter for generic array element
1926 * @param $keyGroup Key group to get
1927 * @param $subGroup Sub group for the key
1928 * @param $key Key to look for
1929 * @param $element Element to look for
1930 * @return $value Mixed value from generic array element
1932 protected final function getGenericArrayElement ($keyGroup, $subGroup, $key, $element) {
1934 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element);
1937 if (!$this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element)) {
1939 trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element . ' does not exist.');
1944 return $this->genericArray[$keyGroup][$subGroup][$key][$element];
1948 * Checks if a given sub group is valid (array)
1950 * @param $keyGroup Key group to get
1951 * @param $subGroup Sub group for the key
1952 * @return $isValid Whether given sub group is valid
1954 protected final function isValidGenericArrayGroup ($keyGroup, $subGroup) {
1956 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup);
1959 $isValid = (($this->isGenericArrayGroupSet($keyGroup, $subGroup)) && (is_array($this->getGenericSubArray($keyGroup, $subGroup))));
1966 * Checks if a given key is valid (array)
1968 * @param $keyGroup Key group to get
1969 * @param $subGroup Sub group for the key
1970 * @param $key Key to check
1971 * @return $isValid Whether given sub group is valid
1973 protected final function isValidGenericArrayKey ($keyGroup, $subGroup, $key) {
1975 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1978 $isValid = (($this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) && (is_array($this->getGenericArrayKey($keyGroup, $subGroup, $key))));
1985 * Initializes the web output instance
1989 protected function initWebOutputInstance () {
1990 // Get application instance
1991 $applicationInstance = GenericRegistry::getRegistry()->getInstance('application');
1993 // Init web output instance
1994 $outputInstance = ObjectFactory::createObjectByConfiguredName('output_class', array($applicationInstance));
1997 $this->setWebOutputInstance($outputInstance);
2001 * Translates boolean true to 'Y' and false to 'N'
2003 * @param $boolean Boolean value
2004 * @return $translated Translated boolean value
2006 public static final function translateBooleanToYesNo (bool $boolean) {
2007 // Make sure it is really boolean
2008 assert(is_bool($boolean));
2011 $translated = ($boolean === true) ? 'Y' : 'N';
2013 // ... and return it
2018 * Creates a full-qualified file name (FQFN) for given file name by adding
2019 * a configured temporary file path to it.
2021 * @param $infoInstance An instance of a SplFileInfo class
2022 * @return $tempInstance An instance of a SplFileInfo class (temporary file)
2023 * @throw PathWriteProtectedException If the path in 'temp_file_path' is write-protected
2024 * @throws FileIoException If the file cannot be written
2026 protected static function createTempPathForFile (SplFileInfo $infoInstance) {
2028 $basePath = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('temp_file_path');
2030 // Is the path writeable?
2031 if (!is_writable($basePath)) {
2032 // Path is write-protected
2033 throw new PathWriteProtectedException($infoInstance, self::EXCEPTION_PATH_CANNOT_BE_WRITTEN);
2037 $tempInstance = new SplFileInfo($basePath . DIRECTORY_SEPARATOR . $infoInstance->getBasename());
2040 if (!FrameworkBootstrap::isReachableFilePath($tempInstance)) {
2042 throw new FileIoException($tempInstance, self::EXCEPTION_FILE_NOT_REACHABLE);
2046 return $tempInstance;
2050 * "Getter" for a printable state name
2052 * @return $stateName Name of the node's state in a printable format
2054 public final function getPrintableState () {
2055 // Default is 'null'
2056 $stateName = 'null';
2058 // Get the state instance
2059 $stateInstance = $this->getStateInstance();
2061 // Is it an instance of Stateable?
2062 if ($stateInstance instanceof Stateable) {
2063 // Then use that state name
2064 $stateName = $stateInstance->getStateName();