3 namespace Org\Mxchange\CoreFramework\Object;
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
7 use Org\Mxchange\CoreFramework\EntryPoint\ApplicationEntryPoint;
8 use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory;
9 use Org\Mxchange\CoreFramework\Filesystem\FileIoException;
10 use Org\Mxchange\CoreFramework\Filesystem\PathWriteProtectedException;
11 use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
12 use Org\Mxchange\CoreFramework\Generic\NullPointerException;
13 use Org\Mxchange\CoreFramework\Generic\UnsupportedOperationException;
14 use Org\Mxchange\CoreFramework\Helper\Application\ApplicationHelper;
15 use Org\Mxchange\CoreFramework\Loader\ClassLoader;
16 use Org\Mxchange\CoreFramework\Manager\ManageableApplication;
17 use Org\Mxchange\CoreFramework\Middleware\Debug\DebugMiddleware;
18 use Org\Mxchange\CoreFramework\Registry\GenericRegistry;
19 use Org\Mxchange\CoreFramework\Result\Database\CachedDatabaseResult;
20 use Org\Mxchange\CoreFramework\State\Stateable;
21 use Org\Mxchange\CoreFramework\Stream\Output\OutputStreamer;
22 use Org\Mxchange\CoreFramework\Utils\Strings\StringUtils;
25 use \BadMethodCallException;
26 use \InvalidArgumentException;
32 * The simulator system class is the super class of all other classes. This
33 * class handles saving of games etc.
35 * @author Roland Haeder <webmaster@shipsimu.org>
37 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2023 Core Developer Team
38 * @license GNU GPL 3.0 or any newer version
39 * @link http://www.shipsimu.org
41 * This program is free software: you can redistribute it and/or modify
42 * it under the terms of the GNU General Public License as published by
43 * the Free Software Foundation, either version 3 of the License, or
44 * (at your option) any later version.
46 * This program is distributed in the hope that it will be useful,
47 * but WITHOUT ANY WARRANTY; without even the implied warranty of
48 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
49 * GNU General Public License for more details.
51 * You should have received a copy of the GNU General Public License
52 * along with this program. If not, see <http://www.gnu.org/licenses/>.
54 abstract class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
56 * Self-referencing instance
58 private static $selfInstance = NULL;
63 private static $debugInstance = NULL;
68 private static $stubMethods = [
69 'partialStub' => true,
71 '__callStatic' => true,
77 private $realClass = __CLASS__;
82 private $callbackInstance = NULL;
87 private $genericArray = [];
89 /***********************
90 * Exception codes.... *
91 ***********************/
93 // @todo Try to clean these constants up
94 const EXCEPTION_IS_NULL_POINTER = 0x001;
95 const EXCEPTION_IS_NO_OBJECT = 0x002;
96 const EXCEPTION_IS_NO_ARRAY = 0x003;
97 const EXCEPTION_MISSING_METHOD = 0x004;
98 const EXCEPTION_CLASSES_NOT_MATCHING = 0x005;
99 const EXCEPTION_INDEX_OUT_OF_BOUNDS = 0x006;
100 const EXCEPTION_DIMENSION_ARRAY_INVALID = 0x007;
101 const EXCEPTION_ITEM_NOT_TRADEABLE = 0x008;
102 const EXCEPTION_ITEM_NOT_IN_PRICE_LIST = 0x009;
103 const EXCEPTION_GENDER_IS_WRONG = 0x00a;
104 const EXCEPTION_BIRTH_DATE_IS_INVALID = 0x00b;
105 const EXCEPTION_EMPTY_STRUCTURES_ARRAY = 0x00c;
106 const EXCEPTION_HAS_ALREADY_PERSONELL_LIST = 0x00d;
107 const EXCEPTION_NOT_ENOUGTH_UNEMPLOYEES = 0x00e;
108 const EXCEPTION_TOTAL_PRICE_NOT_CALCULATED = 0x00f;
109 const EXCEPTION_HARBOR_HAS_NO_SHIPYARDS = 0x010;
110 const EXCEPTION_CONTRACT_PARTNER_INVALID = 0x011;
111 const EXCEPTION_CONTRACT_PARTNER_MISMATCH = 0x012;
112 const EXCEPTION_CONTRACT_ALREADY_SIGNED = 0x013;
113 const EXCEPTION_UNEXPECTED_EMPTY_STRING = 0x014;
114 const EXCEPTION_PATH_NOT_FOUND = 0x015;
115 const EXCEPTION_INVALID_PATH_NAME = 0x016;
116 const EXCEPTION_READ_PROTECED_PATH = 0x017;
117 const EXCEPTION_WRITE_PROTECED_PATH = 0x018;
118 const EXCEPTION_DIR_POINTER_INVALID = 0x019;
119 const EXCEPTION_FILE_POINTER_INVALID = 0x01a;
120 const EXCEPTION_INVALID_RESOURCE = 0x01b;
121 const EXCEPTION_UNEXPECTED_OBJECT = 0x01c;
122 const EXCEPTION_LIMIT_ELEMENT_IS_UNSUPPORTED = 0x01d;
123 const EXCEPTION_GETTER_IS_MISSING = 0x01e;
124 const EXCEPTION_ARRAY_EXPECTED = 0x01f;
125 const EXCEPTION_ARRAY_HAS_INVALID_COUNT = 0x020;
126 const EXCEPTION_ID_IS_INVALID_FORMAT = 0x021;
127 const EXCEPTION_MD5_CHECKSUMS_MISMATCH = 0x022;
128 const EXCEPTION_UNEXPECTED_STRING_SIZE = 0x023;
129 const EXCEPTION_SIMULATOR_ID_INVALID = 0x024;
130 const EXCEPTION_MISMATCHING_COMPRESSORS = 0x025;
131 const EXCEPTION_CONTAINER_ITEM_IS_NULL = 0x026;
132 const EXCEPTION_ITEM_IS_NO_ARRAY = 0x027;
133 const EXCEPTION_CONTAINER_MAYBE_DAMAGED = 0x028;
134 const EXCEPTION_INVALID_STRING = 0x029;
135 const EXCEPTION_VARIABLE_NOT_SET = 0x02a;
136 const EXCEPTION_ATTRIBUTES_ARE_MISSING = 0x02b;
137 const EXCEPTION_ARRAY_ELEMENTS_MISSING = 0x02c;
138 const EXCEPTION_TEMPLATE_ENGINE_UNSUPPORTED = 0x02d;
139 const EXCEPTION_FACTORY_REQUIRE_PARAMETER = 0x02e;
140 const EXCEPTION_MISSING_ELEMENT = 0x02f;
141 const EXCEPTION_HEADERS_ALREADY_SENT = 0x030;
142 const EXCEPTION_DEFAULT_CONTROLLER_GONE = 0x031;
143 const EXCEPTION_CLASS_NOT_FOUND = 0x032;
144 const EXCEPTION_REQUIRED_INTERFACE_MISSING = 0x033;
145 const EXCEPTION_FATAL_ERROR = 0x034;
146 const EXCEPTION_FILE_NOT_FOUND = 0x035;
147 const EXCEPTION_ASSERTION_FAILED = 0x036;
148 const EXCEPTION_FILE_NOT_REACHABLE = 0x037;
149 const EXCEPTION_FILE_CANNOT_BE_READ = 0x038;
150 const EXCEPTION_FILE_CANNOT_BE_WRITTEN = 0x039;
151 const EXCEPTION_PATH_CANNOT_BE_WRITTEN = 0x03a;
152 const EXCEPTION_DATABASE_UPDATED_NOT_ALLOWED = 0x03b;
153 const EXCEPTION_FILTER_CHAIN_INTERCEPTED = 0x03c;
154 const EXCEPTION_INVALID_SOCKET = 0x03d;
155 const EXCEPTION_SELF_INSTANCE = 0x03e;
158 * Startup time in miliseconds
160 private static $startupTime = 0;
163 * Protected super constructor
165 * @param $className Name of the class
168 protected function __construct (string $className) {
170 $this->setRealClass($className);
172 // Is the startup time set? (0 cannot be true anymore)
173 if (self::$startupTime == 0) {
175 self::$startupTime = microtime(true);
180 * Destructor for all classes. You should not call this method on your own.
184 public function __destruct () {
185 // Is this object already destroyed?
186 if ($this->__toString() != 'DestructedObject') {
187 // Destroy all informations about this class but keep some text about it alive
188 $this->setRealClass('DestructedObject');
189 } elseif ((defined('DEBUG_DESTRUCTOR')) && (is_object($this->getDebugInstance()))) {
190 // Already destructed object
191 self::createDebugInstance(__CLASS__, __LINE__)->warningMessage(sprintf('The object <span class="object_name">%s</span> is already destroyed.',
195 // Do not call this twice
196 trigger_error(__METHOD__ . ': Called twice.');
202 * The __call() method where all non-implemented methods end up
204 * @param $methodName Name of the missing method
205 * @args $args Arguments passed to the method
208 public final function __call (string $methodName, array $args = NULL) {
210 self::$selfInstance = $this;
212 // Call static method
213 self::__callStatic($methodName, $args);
215 // Clear self-instance
216 self::$selfInstance = NULL;
220 * The __callStatic() method where all non-implemented static methods end up
222 * @param $methodName Name of the missing method
223 * @param $args Arguments passed to the method
225 * @throws InvalidArgumentException If self::$selfInstance is not a framework's own object
227 public static final function __callStatic (string $methodName, array $args = NULL) {
228 // Init argument string and class name
229 //* PRINT-DEBUG: */ printf('[%s:%d]: methodName=%s,args[]=%s - CALLED!' . PHP_EOL, __METHOD__, __LINE__, $methodName, gettype($args));
231 $className = 'unknown';
233 // Is self-instance set?
234 if (self::$selfInstance instanceof FrameworkInterface) {
235 // Framework's own instance
236 $className = self::$selfInstance->__toString();
237 } elseif (!is_null(self::$selfInstance)) {
239 throw new InvalidArgumentException(sprintf('self::instance[%s] is not expected.', gettype(self::$selfInstance)), self::EXCEPTION_SELF_INSTANCE);
242 // Is it NULL, empty or an array?
243 if (is_null($args)) {
245 $argsString = 'NULL';
246 } elseif (is_array($args)) {
250 // Some arguments are there
251 foreach ($args as $arg) {
252 // Add data about the argument
253 $argsString .= gettype($arg) . ':';
256 // Found a NULL argument
257 $argsString .= 'NULL';
258 } elseif (is_string($arg)) {
259 // Add length for strings
260 $argsString .= strlen($arg);
261 } elseif ((is_int($arg)) || (is_float($arg))) {
264 } elseif (is_array($arg)) {
265 // .. or size if array
266 $argsString .= count($arg);
267 } elseif (is_object($arg)) {
269 $reflection = new ReflectionClass($arg);
271 // Is an other object, maybe no __toString() available
272 $argsString .= $reflection->getName();
273 } elseif ($arg === true) {
274 // ... is boolean 'true'
275 $argsString .= 'true';
276 } elseif ($arg === false) {
277 // ... is boolean 'false'
278 $argsString .= 'false';
281 // Comma for next one
286 if (substr($argsString, -2, 1) == ',') {
288 $argsString = substr($argsString, 0, -2);
295 // Output stub message
296 // @TODO __CLASS__ does always return BaseFrameworkSystem but not the extending (=child) class
297 self::createDebugInstance(__CLASS__, __LINE__)->warningMessage(sprintf('[%s::%s]: Stub! Args: %s',
308 * Getter for $realClass
310 * @return $realClass The name of the real class (not BaseFrameworkSystem)
312 public function __toString () {
313 return $this->realClass;
317 * Magic method to catch setting of missing but set class fields/attributes
319 * @param $name Name of the field/attribute
320 * @param $value Value to store
323 public final function __set (string $name, $value) {
324 $this->debugBackTrace(sprintf('Tried to set a missing field. name=%s, value[%s]=%s',
327 print_r($value, true)
332 * Magic method to catch getting of missing fields/attributes
334 * @param $name Name of the field/attribute
337 public final function __get (string $name) {
338 $this->debugBackTrace(sprintf('Tried to get a missing field. name=%s',
344 * Magic method to catch unsetting of missing fields/attributes
346 * @param $name Name of the field/attribute
349 public final function __unset (string $name) {
350 $this->debugBackTrace(sprintf('Tried to unset a missing field. name=%s',
356 * Magic method to catch object serialization
358 * @return $unsupported Unsupported method
359 * @throws UnsupportedOperationException Objects of this framework cannot be serialized
361 public final function __sleep () {
362 throw new UnsupportedOperationException([$this, __FUNCTION__], FrameworkInterface::EXCEPTION_UNSPPORTED_OPERATION);
366 * Magic method to catch object deserialization
368 * @return $unsupported Unsupported method
369 * @throws UnsupportedOperationException Objects of this framework cannot be serialized
371 public final function __wakeup () {
372 throw new UnsupportedOperationException([$this, __FUNCTION__], FrameworkInterface::EXCEPTION_UNSPPORTED_OPERATION);
376 * Magic method to catch calls when an object instance is called
378 * @return $unsupported Unsupported method
379 * @throws UnsupportedOperationException Objects of this framework cannot be serialized
381 public final function __invoke () {
382 throw new UnsupportedOperationException([$this, __FUNCTION__], FrameworkInterface::EXCEPTION_UNSPPORTED_OPERATION);
386 * Setter for the real class name
388 * @param $realClass Class name (string)
391 public final function setRealClass (string $realClass) {
393 $this->realClass = $realClass;
397 * Setter for debug instance
399 * @param $debugInstance The instance for debug output class
402 public final function setDebugInstance (DebugMiddleware $debugInstance) {
403 self::$debugInstance = $debugInstance;
407 * Getter for debug instance
409 * @return $debugInstance Instance to class DebugConsoleOutput or DebugWebOutput
411 public final function getDebugInstance () {
412 return self::$debugInstance;
416 * Setter for web output instance
418 * @param $webInstance The instance for web output class
421 public final function setWebOutputInstance (OutputStreamer $webInstance) {
422 GenericRegistry::getRegistry()->addInstance('web_output', $webInstance);
426 * Getter for web output instance
428 * @return $webOutputInstance - Instance to class WebOutput
430 public final function getWebOutputInstance () {
431 return GenericRegistry::getRegistry()->getInstance('web_output');
435 * Setter for call-back instance
437 * @param $callbackInstance An instance of a FrameworkInterface class
440 public final function setCallbackInstance (FrameworkInterface $callbackInstance) {
441 $this->callbackInstance = $callbackInstance;
445 * Getter for call-back instance
447 * @return $callbackInstance An instance of a FrameworkInterface class
449 protected final function getCallbackInstance () {
450 return $this->callbackInstance;
454 * Checks whether an object equals this object. You should overwrite this
455 * method to implement own equality checks
457 * @param $objectInstance An instance of a FrameworkInterface object
458 * @return $equals Whether both objects equals
460 public function equals (FrameworkInterface $objectInstance) {
463 $this->__toString() == $objectInstance->__toString()
465 $this->hashCode() == $objectInstance->hashCode()
473 * Generates a generic hash code of this class. You should really overwrite
474 * this method with your own hash code generator code. But keep KISS in mind.
476 * @return $hashCode A generic hash code respresenting this whole class
478 public function hashCode () {
480 return crc32($this->__toString());
484 * Appends a trailing slash to a string
486 * @param $str A string (maybe) without trailing slash
487 * @return $str A string with an auto-appended trailing slash
489 public final function addMissingTrailingSlash (string $str) {
490 // Is there a trailing slash?
491 if (substr($str, -1, 1) != '/') {
495 // Return string with trailing slash
500 * Debugs this instance by putting out it's full content
502 * @param $message Optional message to show in debug output
505 public final function debugInstance (string $message = '') {
506 // Restore the error handler to avoid trouble with missing array elements or undeclared variables
507 restore_error_handler();
513 if (!empty($message)) {
515 $content = sprintf('<div class="debug_message">
517 </div>' . PHP_EOL, $message);
520 // Generate the output
521 $content .= sprintf('<pre>%s</pre>',
530 ApplicationEntryPoint::exitApplication(sprintf('<div class="debug_header">
533 <div class="debug_content">
537 <div class="debug_include_list">
542 ClassLoader::getSelfInstance()->getPrintableIncludeList()
547 * Outputs a debug backtrace and stops further script execution
549 * @param $message An optional message to output
550 * @param $doExit Whether exit the program (true is default)
553 public function debugBackTrace (string $message = '', bool $doExit = true) {
554 // Sorry, there is no other way getting this nice backtrace
555 if (!empty($message)) {
557 printf('Message: %s<br />' . PHP_EOL, $message);
561 debug_print_backtrace();
565 if ($doExit === true) {
571 * Creates an instance of a debugger instance
573 * @param $className Name of the class (currently unsupported)
574 * @param $lineNumber Line number where the call was made
575 * @return $debugInstance An instance of a debugger class
576 * @throws InvalidArgumentException If a parameter has an invalid value
577 * @deprecated Not fully, as the new Logger facilities are not finished yet.
579 public final static function createDebugInstance (string $className, int $lineNumber = NULL) {
580 // Validate parameter
581 //* NOISY-DEBUG: */ printf('[%s:%d]: className=%s,lineNumber[%s]=%d - CALLED!' . PHP_EOL, __METHOD__, __LINE__, $className, gettype($lineNumber), $lineNumber);
582 if (empty($className)) {
584 throw new InvalidArgumentException('Parameter "className" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
587 // Is the debug instance set?
588 //* NOISY-DEBUG: */ printf('[%s:%d]: self::debugInstance[]=%s' . PHP_EOL, __METHOD__, __LINE__, gettype(self::$debugInstance));
589 if (is_null(self::$debugInstance)) {
590 // Init debug instance
591 self::$debugInstance = NULL;
595 // Get a debugger instance
596 //* NOISY-DEBUG: */ printf('[%s:%d]: className=%s' . PHP_EOL, __METHOD__, __LINE__, $className);
597 self::$debugInstance = DebugMiddleware::createDebugMiddleware(FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('debug_' . FrameworkBootstrap::getRequestTypeFromSystem() . '_class'), $className);
598 } catch (NullPointerException $e) {
599 // Didn't work, no instance there
600 exit(sprintf('[%s:%d]: Cannot create debugInstance! Exception=%s,message=%s,className=%s,lineNumber=%d' . PHP_EOL, __METHOD__, __LINE__, $e->__toString(), $e->getMessage(), $className, $lineNumber));
605 //* NOISY-DEBUG: */ printf('[%s:%d]: self::debugInstance=%s - EXIT!' . PHP_EOL, __METHOD__, __LINE__, self::$debugInstance->__toString());
606 return self::$debugInstance;
610 * Simple output of a message with line-break
612 * @param $message Message to output
615 public function outputLine (string $message) {
617 print($message . PHP_EOL);
621 * Marks up the code by adding e.g. line numbers
623 * @param $phpCode Unmarked PHP code
624 * @return $markedCode Marked PHP code
626 public function markupCode (string $phpCode) {
631 $errorArray = error_get_last();
633 // Init the code with error message
634 if (is_array($errorArray)) {
636 $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>',
637 basename($errorArray['file']),
639 $errorArray['message'],
644 // Add line number to the code
645 foreach (explode(chr(10), $phpCode) as $lineNo => $code) {
647 $markedCode .= sprintf('<span id="code_line">%s</span>: %s' . PHP_EOL,
649 htmlentities($code, ENT_QUOTES)
658 * "Getter" for databse entry
660 * @return $entry An array with database entries
661 * @throws NullPointerException If the database result is not found
662 * @throws InvalidDatabaseResultException If the database result is invalid
663 * @deprecated Monolithic method, should be moved to proper classes
665 protected final function getDatabaseEntry () {
666 // This method is deprecated
667 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-FRAMEWORK-SYSTEM: CALLED!');
668 $this->deprecationWarning('Monolithic method, should be moved to proper classes');
670 // Is there an instance?
671 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-FRAMEWORK-SYSTEM: this->resultInstance[]=%s', gettype($this->getResultInstance())));
672 if (!$this->getResultInstance() instanceof SearchableResult) {
673 // Throw an exception here
674 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
678 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-FRAMEWORK-SYSTEM: Invoking this->resultInstance->rewind() ...');
679 $this->getResultInstance()->rewind();
681 // Do we have an entry?
682 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-FRAMEWORK-SYSTEM: this->resultInstance->isValid()=%d', intval($this->getResultInstance()->isValid())));
683 if ($this->getResultInstance()->valid() === false) {
684 // @TODO Move the constant to e.g. BaseDatabaseResult when there is a non-cached database result available
685 throw new InvalidDatabaseResultException(array($this, $this->getResultInstance()), CachedDatabaseResult::EXCEPTION_INVALID_DATABASE_RESULT);
689 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-FRAMEWORK-SYSTEM: Invoking this->resultInstance->next() ...');
690 $this->getResultInstance()->next();
693 $entry = $this->getResultInstance()->current();
696 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: entry[]=%s - EXIT!', gettype($entry)));
701 * Getter for field name
703 * @param $fieldName Field name which we shall get
704 * @return $fieldValue Field value from the user
705 * @throws NullPointerException If the result instance is null
706 * @throws InvalidArgumentException If a parameter is not valid
707 * @deprecated Monolithic method, should be moved to proper classes
709 public final function getField (string $fieldName) {
711 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: fieldName=%s - CALLED!', $fieldName));
712 if (empty($fieldName)) {
714 throw new InvalidArgumentException('Parameter "fieldName" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
717 // This method is deprecated
718 $this->deprecationWarning('Monolithic method, should be moved to proper classes');
720 // Default field value
723 // Get result instance
724 $resultInstance = $this->getResultInstance();
726 // Is this instance null?
727 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-FRAMEWORK-SYSTEM: resultInstance[]=%s', gettype($resultInstance)));
728 if (is_null($resultInstance)) {
729 // Then the user instance is no longer valid (expired cookies?)
730 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
734 $fieldArray = $resultInstance->current();
736 // Convert dashes to underscore
737 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-FRAMEWORK-SYSTEM: fieldArray()=%d', count($fieldArray)));
738 $fieldName2 = StringUtils::convertDashesToUnderscores($fieldName);
740 // Does the field exist?
741 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-FRAMEWORK-SYSTEM: fieldName2=%s', $fieldName2));
742 if ($this->isFieldSet($fieldName)) {
744 $fieldValue = $fieldArray[$fieldName2];
745 } elseif (FrameworkBootstrap::getConfigurationInstance()->isEnabled('developer_mode')) {
746 // Missing field entry, may require debugging
747 self::createDebugInstance(__CLASS__, __LINE__)->warningMessage('BASE-FRAMEWORK-SYSTEM: fieldArray<pre>=' . print_r($fieldArray, true) . '</pre>,fieldName=' . $fieldName . ' not found!');
749 // Missing field entry, may require debugging
750 self::createDebugInstance(__CLASS__, __LINE__)->warningMessage('BASE-FRAMEWORK-SYSTEM: fieldName=' . $fieldName . ' not found!');
754 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: fieldValue[]=%s - EXIT!', gettype($fieldValue)));
759 * Checks if given field is set
761 * @param $fieldName Field name to check
762 * @return $isSet Whether the given field name is set
763 * @throws NullPointerException If the result instance is null
764 * @throws InvalidArgumentException If a parameter is not valid
766 public function isFieldSet (string $fieldName) {
768 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: fieldName=%s - CALLED!', $fieldName));
769 if (empty($fieldName)) {
771 throw new InvalidArgumentException('Parameter "fieldName" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
774 // Get result instance
775 $resultInstance = $this->getResultInstance();
777 // Is this instance null?
778 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-FRAMEWORK-SYSTEM: resultInstance[]=%s', gettype($resultInstance)));
779 if (is_null($resultInstance)) {
780 // Then the user instance is no longer valid (expired cookies?)
781 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
785 $fieldArray = $resultInstance->current();
787 // Convert dashes to underscore
788 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-FRAMEWORK-SYSTEM: fieldArray()=%d,fieldName=%s - BEFORE!', count($fieldArray), $fieldName));
789 $fieldName = StringUtils::convertDashesToUnderscores($fieldName);
792 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-FRAMEWORK-SYSTEM: fieldName=%s - AFTER!', $fieldName));
793 $isset = isset($fieldArray[$fieldName]);
796 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: isset=%d - EXIT!', intval($isset)));
801 * Outputs a deprecation warning to the developer.
803 * @param $message The message we shall output to the developer
805 * @todo Write a logging mechanism for productive mode
807 public function deprecationWarning (string $message) {
808 // Is developer mode active?
809 if (FrameworkBootstrap::getConfigurationInstance()->isEnabled('developer_mode')) {
810 // Debug instance is there?
811 if (!is_null($this->getDebugInstance())) {
812 // Output stub message
813 self::createDebugInstance(__CLASS__, __LINE__)->warningMessage($message);
816 trigger_error($message . "<br />\n");
820 // @TODO Finish this part!
821 DebugMiddleware::getSelfInstance()->partialStub('Developer mode inactive. Message:' . $message);
826 * Checks whether the given PHP extension is loaded
828 * @param $phpExtension The PHP extension we shall check
829 * @return $isLoaded Whether the PHP extension is loaded
830 * @throws InvalidArgumentException If a parameter is not valid
832 public final function isPhpExtensionLoaded (string $phpExtension) {
834 if (empty($phpExtension)) {
836 throw new InvalidArgumentException('Parameter "phpExtension" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
840 $isLoaded = in_array($phpExtension, get_loaded_extensions());
847 * "Getter" as a time() replacement but with milliseconds. You should use this
848 * method instead of the encapsulated getimeofday() function.
850 * @return $milliTime Timestamp with milliseconds
852 public function getMilliTime () {
853 // Get the time of day as float
854 $milliTime = gettimeofday(true);
861 * Idles (sleeps) for given milliseconds
863 * @return $hasSlept Whether it goes fine
864 * @throws InvalidArgumentException If a parameter is not valid
866 public function idle (int $milliSeconds) {
868 if ($milliSeconds < 1) {
870 throw new InvalidArgumentException(sprintf('milliSeconds=%d are not a reasonable value to idle', $milliSeconds));
873 // Sleep is fine by default
876 // Idle so long with found function
877 if (function_exists('time_sleep_until')) {
878 // Get current time and add idle time
879 $sleepUntil = $this->getMilliTime() + abs($milliSeconds) / 1000;
881 // New PHP 5.1.0 function found, ignore errors
882 $hasSlept = @time_sleep_until($sleepUntil);
885 * My Sun station doesn't have that function even with latest PHP
888 usleep($milliSeconds * 1000);
896 * Checks whether the given encoded data was encoded with Base64
898 * @param $encodedData Encoded data we shall check
899 * @return $isBase64 Whether the encoded data is Base64
900 * @throws InvalidArgumentException If a parameter is not valid
902 protected function isBase64Encoded (string $encodedData) {
904 if (empty($encodedData)) {
906 throw new InvalidArgumentException('Parameter "encodedData" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
910 $isBase64 = (@base64_decode($encodedData, true) !== false);
917 * Getter for startup time in miliseconds
919 * @return $startupTime Startup time in miliseconds
921 protected function getStartupTime () {
922 return self::$startupTime;
926 * "Getter" for a printable currently execution time in nice braces
928 * @return $executionTime Current execution time in nice braces
930 protected function getPrintableExecutionTime () {
931 // Calculate execution time and pack it in nice braces
932 $executionTime = sprintf('[ %01.5f ] ', (microtime(true) - $this->getStartupTime()));
935 return $executionTime;
939 * Determines if an element is set in the generic array
941 * @param $keyGroup Main group for the key
942 * @param $subGroup Sub group for the key
943 * @param $key Key to check
944 * @param $element Element to check
945 * @return $isset Whether the given key is set
946 * @throws InvalidArgumentException If a parameter is not valid
948 protected final function isGenericArrayElementSet (string $keyGroup, string $subGroup, string $key, string $element) {
950 if (empty($keyGroup)) {
952 throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
953 } elseif (empty($subGroup)) {
955 throw new InvalidArgumentException('Parameter "subGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
956 } elseif (empty($key)) {
958 throw new InvalidArgumentException('Parameter "key" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
959 } elseif ($element === '') {
961 throw new InvalidArgumentException('Parameter "element" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
965 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element);
966 $isset = isset($this->genericArray[$keyGroup][$subGroup][$key][$element]);
972 * Determines if a key is set in the generic array
974 * @param $keyGroup Main group for the key
975 * @param $subGroup Sub group for the key
976 * @param $key Key to check
977 * @return $isset Whether the given key is set
978 * @throws InvalidArgumentException If a parameter is not valid
980 protected final function isGenericArrayKeySet (string $keyGroup, string $subGroup, string $key) {
982 if (empty($keyGroup)) {
984 throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
985 } elseif (empty($subGroup)) {
987 throw new InvalidArgumentException('Parameter "subGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
988 } elseif (empty($key)) {
990 throw new InvalidArgumentException('Parameter "key" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
994 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
995 $isset = isset($this->genericArray[$keyGroup][$subGroup][$key]);
1002 * Determines if a group is set in the generic array
1004 * @param $keyGroup Main group
1005 * @param $subGroup Sub group
1006 * @return $isset Whether the given group is set
1007 * @throws InvalidArgumentException If a parameter is not valid
1009 protected final function isGenericArrayGroupSet (string $keyGroup, string $subGroup) {
1011 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup);
1012 if (empty($keyGroup)) {
1014 throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1015 } elseif (empty($subGroup)) {
1017 throw new InvalidArgumentException('Parameter "subGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1021 $isset = isset($this->genericArray[$keyGroup][$subGroup]);
1028 * Getter for sub key group
1030 * @param $keyGroup Main key group
1031 * @param $subGroup Sub key group
1032 * @return $array An array with all array elements
1033 * @throws InvalidArgumentException If a parameter is not valid
1034 * @throws BadMethodCallException If key/sub group isn't there but this method is invoked
1036 protected final function getGenericSubArray (string $keyGroup, string $subGroup) {
1038 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',value=' . print_r($this->genericArray[$keyGroup][$subGroup], true));
1039 if (empty($keyGroup)) {
1041 throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1042 } elseif (empty($subGroup)) {
1044 throw new InvalidArgumentException('Parameter "subGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1045 } elseif (!$this->isGenericArrayGroupSet($keyGroup, $subGroup)) {
1046 // No, then abort here
1047 throw new BadMethodCallException(sprintf('keyGroup=%s,subGroup=%s not found.', $keyGroup, $subGroup), FrameworkInterface::EXCEPTION_BAD_METHOD_CALL);
1051 return $this->genericArray[$keyGroup][$subGroup];
1055 * Unsets a given key in generic array
1057 * @param $keyGroup Main group for the key
1058 * @param $subGroup Sub group for the key
1059 * @param $key Key to unset
1061 * @throws InvalidArgumentException If a parameter is not valid
1063 protected final function unsetGenericArrayKey (string $keyGroup, string $subGroup, string $key) {
1065 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1066 if (empty($keyGroup)) {
1068 throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1069 } elseif (empty($subGroup)) {
1071 throw new InvalidArgumentException('Parameter "subGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1072 } elseif (empty($key)) {
1074 throw new InvalidArgumentException('Parameter "key" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1078 unset($this->genericArray[$keyGroup][$subGroup][$key]);
1082 * Unsets a given element in generic array
1084 * @param $keyGroup Main group for the key
1085 * @param $subGroup Sub group for the key
1086 * @param $key Key to unset
1087 * @param $element Element to unset
1089 * @throws InvalidArgumentException If a parameter is not valid
1091 protected final function unsetGenericArrayElement (string $keyGroup, string $subGroup, string $key, string $element) {
1093 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element);
1094 if (empty($keyGroup)) {
1096 throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1097 } elseif (empty($subGroup)) {
1099 throw new InvalidArgumentException('Parameter "subGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1100 } elseif (empty($key)) {
1102 throw new InvalidArgumentException('Parameter "key" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1103 } elseif ($element === '') {
1105 throw new InvalidArgumentException('Parameter "element" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1109 unset($this->genericArray[$keyGroup][$subGroup][$key][$element]);
1113 * Append a string to a given generic array key
1115 * @param $keyGroup Main group for the key
1116 * @param $subGroup Sub group for the key
1117 * @param $key Key to unset
1118 * @param $value Value to add/append
1120 * @throws InvalidArgumentException If a parameter is not valid
1122 protected final function appendStringToGenericArrayKey (string $keyGroup, string $subGroup, $key, string $value, string $appendGlue = '') {
1124 //* 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);
1125 if (empty($keyGroup)) {
1127 throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1128 } elseif (empty($subGroup)) {
1130 throw new InvalidArgumentException('Parameter "subGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1131 } elseif (empty($key)) {
1133 throw new InvalidArgumentException('Parameter "key" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1136 // Is it already there?
1137 if ($this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
1139 $this->genericArray[$keyGroup][$subGroup][$key] .= $appendGlue . $value;
1142 $this->genericArray[$keyGroup][$subGroup][$key] = $value;
1147 * Append a string to a given generic array element
1149 * @param $keyGroup Main group for the key
1150 * @param $subGroup Sub group for the key
1151 * @param $key Key to unset
1152 * @param $element Element to check
1153 * @param $value Value to add/append
1155 * @throws InvalidArgumentException If a parameter is not valid
1157 protected final function appendStringToGenericArrayElement (string $keyGroup, string $subGroup, string $key, string $element, string $value, string $appendGlue = '') {
1159 //* NOISY-DEBUG: */ if (!is_object($value)) $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element . ',value[' . gettype($value) . ']=' . print_r($value, true) . ',appendGlue=' . $appendGlue);
1160 if (empty($keyGroup)) {
1162 throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1163 } elseif (empty($subGroup)) {
1165 throw new InvalidArgumentException('Parameter "subGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1166 } elseif (empty($key)) {
1168 throw new InvalidArgumentException('Parameter "key" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1169 } elseif ($element === '') {
1171 throw new InvalidArgumentException('Parameter "element" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1174 // Is it already there?
1175 if ($this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element)) {
1177 $this->genericArray[$keyGroup][$subGroup][$key][$element] .= $appendGlue . $value;
1180 $this->setGenericArrayElement($keyGroup, $subGroup, $key, $element, $value);
1185 * Initializes given generic array group
1187 * @param $keyGroup Main group for the key
1188 * @param $subGroup Sub group for the key
1189 * @param $key Key to use
1190 * @param $forceInit Optionally force initialization
1192 * @throws InvalidArgumentException If a parameter is not valid
1193 * @throws BadMethodCallException If key/sub group has already been initialized
1195 protected final function initGenericArrayGroup (string $keyGroup, string $subGroup, bool $forceInit = false) {
1197 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',forceInit=' . intval($forceInit));
1198 if (empty($keyGroup)) {
1200 throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1201 } elseif (empty($subGroup)) {
1203 throw new InvalidArgumentException('Parameter "subGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1204 } elseif (($forceInit === false) && ($this->isGenericArrayGroupSet($keyGroup, $subGroup))) {
1205 // Already initialized
1206 throw new BadMethodCallException(sprintf('keyGroup=%s,subGroup=%s already initialized.', $keyGroup, $subGroup), FrameworkInterface::EXCEPTION_BAD_METHOD_CALL);
1210 $this->genericArray[$keyGroup][$subGroup] = [];
1214 * Initializes given generic array key
1216 * @param $keyGroup Main group for the key
1217 * @param $subGroup Sub group for the key
1218 * @param $key Key to use
1219 * @param $forceInit Optionally force initialization
1221 * @throws InvalidArgumentException If a parameter is not valid
1222 * @throws BadMethodCallException If key/sub group has already been initialized
1224 protected final function initGenericArrayKey (string $keyGroup, string $subGroup, $key, bool $forceInit = false) {
1226 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',forceInit=' . intval($forceInit));
1227 if (empty($keyGroup)) {
1229 throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1230 } elseif (empty($subGroup)) {
1232 throw new InvalidArgumentException('Parameter "subGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1233 } elseif (empty($key)) {
1235 throw new InvalidArgumentException('Parameter "key" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1236 } elseif (($forceInit === false) && ($this->isGenericArrayKeySet($keyGroup, $subGroup, $key))) {
1237 // Already initialized
1238 throw new BadMethodCallException(sprintf('keyGroup=%s,subGroup=%s,key[%s]=%s already initialized.', $keyGroup, $subGroup, gettype($key), $key), FrameworkInterface::EXCEPTION_BAD_METHOD_CALL);
1242 $this->genericArray[$keyGroup][$subGroup][$key] = [];
1246 * Initializes given generic array element
1248 * @param $keyGroup Main group for the key
1249 * @param $subGroup Sub group for the key
1250 * @param $key Key to use
1251 * @param $element Element to use
1252 * @param $forceInit Optionally force initialization
1254 * @throws InvalidArgumentException If a parameter is not valid
1255 * @throws BadMethodCallException If key/sub group isn't there but this method is invoked
1257 protected final function initGenericArrayElement (string $keyGroup, string $subGroup, string $key, string $element, bool $forceInit = false) {
1259 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element . ',forceInit=' . intval($forceInit));
1260 if (empty($keyGroup)) {
1262 throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1263 } elseif (empty($subGroup)) {
1265 throw new InvalidArgumentException('Parameter "subGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1266 } elseif (empty($key)) {
1268 throw new InvalidArgumentException('Parameter "key" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1269 } elseif ($element === '') {
1271 throw new InvalidArgumentException('Parameter "element" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1272 } elseif (($forceInit === false) && ($this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element))) {
1273 // Already initialized
1274 throw new BadMethodCallException(sprintf('keyGroup=%s,subGroup=%s,key[%s]=%s,element[%s]=%s already initialized.', $keyGroup, $subGroup, gettype($key), $key, gettype($element), $element), FrameworkInterface::EXCEPTION_BAD_METHOD_CALL);
1278 $this->genericArray[$keyGroup][$subGroup][$key][$element] = [];
1282 * Pushes an element to a generic key. If the key isn't found, it will be initialized.
1284 * @param $keyGroup Main group for the key
1285 * @param $subGroup Sub group for the key
1286 * @param $key Key to use
1287 * @param $value Value to add/append
1288 * @return $count Number of array elements
1289 * @throws InvalidArgumentException If a parameter is not valid
1291 protected final function pushValueToGenericArrayKey (string $keyGroup, string $subGroup, string $key, $value) {
1293 //* NOISY-DEBUG: */ if (!is_object($value)) $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',value[' . gettype($value) . ']=' . print_r($value, true));
1294 if (empty($keyGroup)) {
1296 throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1297 } elseif (empty($subGroup)) {
1299 throw new InvalidArgumentException('Parameter "subGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1300 } elseif (empty($key)) {
1302 throw new InvalidArgumentException('Parameter "key" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1303 } elseif (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
1305 $this->initGenericArrayKey($keyGroup, $subGroup, $key);
1309 $count = array_push($this->genericArray[$keyGroup][$subGroup][$key], $value);
1312 //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], true));
1313 //* DEBUG: */ print(__METHOD__ . ': count=' . $count . PHP_EOL);
1318 * Pushes an element to a generic array element. If the key isn't found, it will be initialized.
1320 * @param $keyGroup Main group for the key
1321 * @param $subGroup Sub group for the key
1322 * @param $key Key to use
1323 * @param $element Element to check
1324 * @param $value Value to add/append
1325 * @return $count Number of array elements
1326 * @throws InvalidArgumentException If a parameter is not valid
1328 protected final function pushValueToGenericArrayElement (string $keyGroup, string $subGroup, string $key, string $element, $value) {
1330 //* 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));
1331 if (empty($keyGroup)) {
1333 throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1334 } elseif (empty($subGroup)) {
1336 throw new InvalidArgumentException('Parameter "subGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1337 } elseif (empty($key)) {
1339 throw new InvalidArgumentException('Parameter "key" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1340 } elseif ($element === '') {
1342 throw new InvalidArgumentException('Parameter "element" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1343 } elseif (!$this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element)) {
1345 $this->initGenericArrayElement($keyGroup, $subGroup, $key, $element);
1349 $count = array_push($this->genericArray[$keyGroup][$subGroup][$key][$element], $value);
1352 //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], true));
1353 //* DEBUG: */ print(__METHOD__ . ': count=' . $count . PHP_EOL);
1358 * Pops an element from a generic group
1360 * @param $keyGroup Main group for the key
1361 * @param $subGroup Sub group for the key
1362 * @param $key Key to unset
1363 * @return $value Last "popped" value
1364 * @throws InvalidArgumentException If a parameter is not valid
1365 * @throws BadMethodCallException If key/sub group isn't there but this method is invoked
1367 protected final function popGenericArrayElement (string $keyGroup, string $subGroup, string $key) {
1369 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1370 if (empty($keyGroup)) {
1372 throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1373 } elseif (empty($subGroup)) {
1375 throw new InvalidArgumentException('Parameter "subGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1376 } elseif (empty($key)) {
1378 throw new InvalidArgumentException('Parameter "key" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1379 } elseif (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
1381 throw new BadMethodCallException(sprintf('keyGroup=%s,subGroup=%s,key[%s]=%s not found.', $keyGroup, $subGroup, gettype($key), $key), FrameworkInterface::EXCEPTION_BAD_METHOD_CALL);
1385 $value = array_pop($this->genericArray[$keyGroup][$subGroup][$key]);
1388 //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], true));
1389 //* DEBUG: */ print(__METHOD__ . ': value[' . gettype($value) . ']=' . print_r($value, true) . PHP_EOL);
1394 * Shifts an element from a generic group
1396 * @param $keyGroup Main group for the key
1397 * @param $subGroup Sub group for the key
1398 * @param $key Key to unset
1399 * @return $value Last "shifted" value
1400 * @throws InvalidArgumentException If a parameter is not valid
1401 * @throws BadMethodCallException If key/sub group isn't there but this method is invoked
1403 protected final function shiftGenericArrayElement (string $keyGroup, string $subGroup, string $key) {
1405 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1406 if (empty($keyGroup)) {
1408 throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1409 } elseif (empty($subGroup)) {
1411 throw new InvalidArgumentException('Parameter "subGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1412 } elseif (empty($key)) {
1414 throw new InvalidArgumentException('Parameter "key" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1415 } elseif (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
1417 throw new BadMethodCallException(sprintf('keyGroup=%s,subGroup=%s,key[%s]=%s not found.', $keyGroup, $subGroup, gettype($key), $key), FrameworkInterface::EXCEPTION_BAD_METHOD_CALL);
1421 $value = array_shift($this->genericArray[$keyGroup][$subGroup][$key]);
1424 //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], true));
1425 //* DEBUG: */ print(__METHOD__ . ': value[' . gettype($value) . ']=' . print_r($value, true) . PHP_EOL);
1430 * Count generic array group
1432 * @param $keyGroup Main group for the key
1433 * @return $count Count of given group
1434 * @throws InvalidArgumentException If a parameter is not valid
1435 * @throws BadMethodCallException If key group isn't there but this method is invoked
1437 protected final function countGenericArray (string $keyGroup) {
1439 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup);
1440 if (empty($keyGroup)) {
1442 throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1443 } elseif (!isset($this->genericArray[$keyGroup])) {
1445 throw new BadMethodCallException(sprintf('keyGroup=%s not found.', $keyGroup), FrameworkInterface::EXCEPTION_BAD_METHOD_CALL);
1449 $count = count($this->genericArray[$keyGroup]);
1452 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',count=' . $count);
1457 * Count generic array sub group
1459 * @param $keyGroup Main group for the key
1460 * @param $subGroup Sub group for the key
1461 * @return $count Count of given group
1462 * @throws InvalidArgumentException If a parameter is not valid
1463 * @throws BadMethodCallException If key/sub group isn't there but this method is invoked
1465 protected final function countGenericArrayGroup (string $keyGroup, string $subGroup) {
1467 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup);
1468 if (empty($keyGroup)) {
1470 throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1471 } elseif (empty($subGroup)) {
1473 throw new InvalidArgumentException('Parameter "subGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1474 } elseif (!$this->isGenericArrayGroupSet($keyGroup, $subGroup)) {
1476 throw new BadMethodCallException(sprintf('keyGroup=%s,subGroup=%s not found.', $keyGroup, $subGroup), FrameworkInterface::EXCEPTION_BAD_METHOD_CALL);
1480 $count = count($this->genericArray[$keyGroup][$subGroup]);
1483 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',count=' . $count);
1488 * Count generic array elements
1490 * @param $keyGroup Main group for the key
1491 * @param $subGroup Sub group for the key
1492 * @param $key Key to count
1493 * @return $count Count of given key
1494 * @throws InvalidArgumentException If a parameter is not valid
1495 * @throws BadMethodCallException If key/sub group isn't there but this method is invoked
1497 protected final function countGenericArrayElements (string $keyGroup, string $subGroup, string $key) {
1499 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1500 if (empty($keyGroup)) {
1502 throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1503 } elseif (empty($subGroup)) {
1505 throw new InvalidArgumentException('Parameter "subGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1506 } elseif (empty($key)) {
1508 throw new InvalidArgumentException('Parameter "key" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1509 } elseif (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
1511 throw new BadMethodCallException(sprintf('keyGroup=%s,subGroup=%s,key[%s]=%s not found.', $keyGroup, $subGroup, gettype($key), $key), FrameworkInterface::EXCEPTION_BAD_METHOD_CALL);
1512 } elseif (!$this->isValidGenericArrayGroup($keyGroup, $subGroup)) {
1514 throw new BadMethodCallException(sprintf('keyGroup=%s,subGroup=%s is not a valid key/sub group.', $keyGroup, $subGroup), FrameworkInterface::EXCEPTION_BAD_METHOD_CALL);
1518 $count = count($this->genericArray[$keyGroup][$subGroup][$key]);
1521 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',count=' . $count);
1526 * Getter for whole generic group array
1528 * @param $keyGroup Key group to get
1529 * @return $array Whole generic array group
1530 * @throws InvalidArgumentException If a parameter is not valid
1531 * @throws BadMethodCallException If key/sub group isn't there but this method is invoked
1533 protected final function getGenericArray (string $keyGroup) {
1535 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup);
1536 if (empty($keyGroup)) {
1538 throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1539 } elseif (!isset($this->genericArray[$keyGroup])) {
1541 throw new BadMethodCallException(sprintf('keyGroup=%s not found', $keyGroup), FrameworkInterface::EXCEPTION_BAD_METHOD_CALL);
1545 return $this->genericArray[$keyGroup];
1549 * Setter for generic array key
1551 * @param $keyGroup Key group to get
1552 * @param $subGroup Sub group for the key
1553 * @param $key Key to unset
1554 * @param $value Mixed value from generic array element
1556 * @throws InvalidArgumentException If a parameter is not valid
1557 * @throws BadMethodCallException If key/sub group isn't there but this method is invoked
1559 protected final function setGenericArrayKey (string $keyGroup, string $subGroup, string $key, $value) {
1561 //* NOISY-DEBUG: */ if (!is_object($value)) $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',value[' . gettype($value) . ']=' . print_r($value, true));
1562 if (empty($keyGroup)) {
1564 throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1565 } elseif (empty($subGroup)) {
1567 throw new InvalidArgumentException('Parameter "subGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1568 } elseif (empty($key)) {
1570 throw new InvalidArgumentException('Parameter "key" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1571 } elseif (!$this->isValidGenericArrayGroup($keyGroup, $subGroup)) {
1573 throw new BadMethodCallException(sprintf('keyGroup=%s,subGroup=%s not found', $keyGroup), FrameworkInterface::EXCEPTION_BAD_METHOD_CALL);
1577 $this->genericArray[$keyGroup][$subGroup][$key] = $value;
1581 * Getter for generic array key
1583 * @param $keyGroup Key group to get
1584 * @param $subGroup Sub group for the key
1585 * @param $key Key to unset
1586 * @return $value Mixed value from generic array element
1587 * @throws InvalidArgumentException If a parameter is not valid
1588 * @throws BadMethodCallException If key/sub group isn't there but this method is invoked
1590 protected final function getGenericArrayKey (string $keyGroup, string $subGroup, string $key) {
1592 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1593 if (empty($keyGroup)) {
1595 throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1596 } elseif (empty($subGroup)) {
1598 throw new InvalidArgumentException('Parameter "subGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1599 } elseif (empty($key)) {
1601 throw new InvalidArgumentException('Parameter "key" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1602 } elseif (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
1604 throw new BadMethodCallException(sprintf('keyGroup=%s,subGroup=%s,key[%s]=%s not found.', $keyGroup, $subGroup, gettype($key), $key), FrameworkInterface::EXCEPTION_BAD_METHOD_CALL);
1608 return $this->genericArray[$keyGroup][$subGroup][$key];
1612 * Sets a value in given generic array key/element
1614 * @param $keyGroup Main group for the key
1615 * @param $subGroup Sub group for the key
1616 * @param $key Key to set
1617 * @param $element Element to set
1618 * @param $value Value to set
1620 * @throws InvalidArgumentException If a parameter is not valid
1622 protected final function setGenericArrayElement (string $keyGroup, string $subGroup, string $key, string $element, $value) {
1624 //* 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));
1625 if (empty($keyGroup)) {
1627 throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1628 } elseif (empty($subGroup)) {
1630 throw new InvalidArgumentException('Parameter "subGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1631 } elseif (empty($key)) {
1633 throw new InvalidArgumentException('Parameter "key" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1634 } elseif ($element === '') {
1636 throw new InvalidArgumentException('Parameter "element" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1637 } elseif (!$this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element)) {
1639 $this->initGenericArrayElement($keyGroup, $subGroup, $key, $element);
1643 $this->genericArray[$keyGroup][$subGroup][$key][$element] = $value;
1647 * Getter for generic array element
1649 * @param $keyGroup Key group to get
1650 * @param $subGroup Sub group for the key
1651 * @param $key Key to look for
1652 * @param $element Element to look for
1653 * @return $value Mixed value from generic array element
1654 * @throws InvalidArgumentException If a parameter is not valid
1655 * @throws BadMethodCallException If key/sub group isn't there but this method is invoked
1657 protected final function getGenericArrayElement (string $keyGroup, string $subGroup, string $key, string $element) {
1659 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element);
1660 if (empty($keyGroup)) {
1662 throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1663 } elseif (empty($subGroup)) {
1665 throw new InvalidArgumentException('Parameter "subGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1666 } elseif (empty($key)) {
1668 throw new InvalidArgumentException('Parameter "key" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1669 } elseif ($element === '') {
1671 throw new InvalidArgumentException('Parameter "element" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1672 } elseif (!$this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element)) {
1674 throw new BadMethodCallException(sprintf('keyGroup=%s,subGroup=%s,key[%s]=%s,element[%s]=%s not found.', $keyGroup, $subGroup, gettype($key), $key, gettype($element), $element), FrameworkInterface::EXCEPTION_BAD_METHOD_CALL);
1678 return $this->genericArray[$keyGroup][$subGroup][$key][$element];
1682 * Checks if a given sub group is valid (array)
1684 * @param $keyGroup Key group to get
1685 * @param $subGroup Sub group for the key
1686 * @return $isValid Whether given sub group is valid
1687 * @throws InvalidArgumentException If a parameter is not valid
1689 protected final function isValidGenericArrayGroup (string $keyGroup, string $subGroup) {
1691 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup);
1692 if (empty($keyGroup)) {
1694 throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1695 } elseif (empty($subGroup)) {
1697 throw new InvalidArgumentException('Parameter "subGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1701 $isValid = (($this->isGenericArrayGroupSet($keyGroup, $subGroup)) && (is_array($this->getGenericSubArray($keyGroup, $subGroup))));
1708 * Checks if a given key is valid (array)
1710 * @param $keyGroup Key group to get
1711 * @param $subGroup Sub group for the key
1712 * @param $key Key to check
1713 * @return $isValid Whether given sub group is valid
1715 protected final function isValidGenericArrayKey (string $keyGroup, string $subGroup, string $key) {
1717 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1718 if (empty($keyGroup)) {
1720 throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1721 } elseif (empty($subGroup)) {
1723 throw new InvalidArgumentException('Parameter "subGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1724 } elseif (empty($key)) {
1726 throw new InvalidArgumentException('Parameter "key" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1730 $isValid = (($this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) && (is_array($this->getGenericArrayKey($keyGroup, $subGroup, $key))));
1737 * Initializes the web output instance
1741 protected function initWebOutputInstance () {
1742 // Init web output instance
1743 $outputInstance = ObjectFactory::createObjectByConfiguredName('output_class');
1746 $this->setWebOutputInstance($outputInstance);
1750 * Translates boolean true to 'Y' and false to 'N'
1752 * @param $boolean Boolean value
1753 * @return $translated Translated boolean value
1755 public static final function translateBooleanToYesNo (bool $boolean) {
1757 $translated = ($boolean === true) ? 'Y' : 'N';
1759 // ... and return it
1764 * Creates a full-qualified file name (FQFN) for given file name by adding
1765 * a configured temporary file path to it.
1767 * @param $infoInstance An instance of a SplFileInfo class
1768 * @return $tempInstance An instance of a SplFileInfo class (temporary file)
1769 * @throw PathWriteProtectedException If the path in 'temp_file_path' is write-protected
1770 * @throws FileIoException If the file cannot be written
1772 protected static function createTempPathForFile (SplFileInfo $infoInstance) {
1774 $basePath = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('temp_file_path');
1776 // Is the path writeable?
1777 if (!is_writable($basePath)) {
1778 // Path is write-protected
1779 throw new PathWriteProtectedException($infoInstance, self::EXCEPTION_PATH_CANNOT_BE_WRITTEN);
1783 $tempInstance = new SplFileInfo($basePath . DIRECTORY_SEPARATOR . $infoInstance->getBasename());
1786 if (!FrameworkBootstrap::isReachableFilePath($tempInstance)) {
1788 throw new FileIoException($tempInstance, self::EXCEPTION_FILE_NOT_REACHABLE);
1792 return $tempInstance;
1796 * "Getter" for a printable state name
1798 * @return $stateName Name of the node's state in a printable format
1799 * @todo Move this class away from this monolithic place (not whole class is monolithic)
1801 public final function getPrintableState () {
1802 // Default is 'null'
1803 $stateName = 'null';
1805 // Get the state instance
1806 $stateInstance = $this->getStateInstance();
1808 // Is it an instance of Stateable?
1809 if ($stateInstance instanceof Stateable) {
1810 // Then use that state name
1811 $stateName = $stateInstance->getStateName();