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 GenericRegistry::getRegistry()->addInstance('debug', $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 * Output a partial stub message for the caller method
549 * @param $message An optional message to display
552 protected function partialStub (string $message = '') {
554 $stubMessage = 'Partial stub!';
556 // Is an extra message given?
557 if (!empty($message)) {
558 // Then add it as well
559 $stubMessage .= ' Message: ' . $message;
562 // Debug instance is there?
563 if (!is_null($this->getDebugInstance())) {
564 // Output stub message
565 self::createDebugInstance(__CLASS__, __LINE__)->warningMessage($stubMessage);
568 trigger_error($stubMessage);
574 * Outputs a debug backtrace and stops further script execution
576 * @param $message An optional message to output
577 * @param $doExit Whether exit the program (true is default)
580 public function debugBackTrace (string $message = '', bool $doExit = true) {
581 // Sorry, there is no other way getting this nice backtrace
582 if (!empty($message)) {
584 printf('Message: %s<br />' . PHP_EOL, $message);
588 debug_print_backtrace();
592 if ($doExit === true) {
598 * Creates an instance of a debugger instance
600 * @param $className Name of the class (currently unsupported)
601 * @param $lineNumber Line number where the call was made
602 * @return $debugInstance An instance of a debugger class
603 * @throws InvalidArgumentException If a parameter has an invalid value
604 * @deprecated Not fully, as the new Logger facilities are not finished yet.
606 public final static function createDebugInstance (string $className, int $lineNumber = NULL) {
607 // Validate parameter
608 //* NOISY-DEBUG: */ printf('[%s:%d]: className=%s,lineNumber[%s]=%d - CALLED!' . PHP_EOL, __METHOD__, __LINE__, $className, gettype($lineNumber), $lineNumber);
609 if (empty($className)) {
611 throw new InvalidArgumentException('Parameter "className" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
614 // Is the debug instance set?
615 //* NOISY-DEBUG: */ printf('[%s:%d]: self::debugInstance[]=%s' . PHP_EOL, __METHOD__, __LINE__, gettype(self::$debugInstance));
616 if (is_null(self::$debugInstance)) {
617 // Init debug instance
618 self::$debugInstance = NULL;
622 // Get a debugger instance
623 self::$debugInstance = DebugMiddleware::createDebugMiddleware(FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('debug_' . FrameworkBootstrap::getRequestTypeFromSystem() . '_class'), $className);
624 } catch (NullPointerException $e) {
625 // Didn't work, no instance there
626 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));
629 // Empty string should be ignored and used for testing the middleware
630 //* NOISY-DEBUG: */ printf('[%s:%d]: Invoking DebugMiddleware->selfInstance->output() ...' . PHP_EOL, __METHOD__, __LINE__);
631 DebugMiddleware::getSelfInstance()->output('');
635 //* NOISY-DEBUG: */ printf('[%s:%d]: self::debugInstance=%s - EXIT!' . PHP_EOL, __METHOD__, __LINE__, self::$debugInstance->__toString());
636 return self::$debugInstance;
640 * Simple output of a message with line-break
642 * @param $message Message to output
645 public function outputLine (string $message) {
647 print($message . PHP_EOL);
651 * Marks up the code by adding e.g. line numbers
653 * @param $phpCode Unmarked PHP code
654 * @return $markedCode Marked PHP code
656 public function markupCode (string $phpCode) {
661 $errorArray = error_get_last();
663 // Init the code with error message
664 if (is_array($errorArray)) {
666 $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>',
667 basename($errorArray['file']),
669 $errorArray['message'],
674 // Add line number to the code
675 foreach (explode(chr(10), $phpCode) as $lineNo => $code) {
677 $markedCode .= sprintf('<span id="code_line">%s</span>: %s' . PHP_EOL,
679 htmlentities($code, ENT_QUOTES)
688 * "Getter" for databse entry
690 * @return $entry An array with database entries
691 * @throws NullPointerException If the database result is not found
692 * @throws InvalidDatabaseResultException If the database result is invalid
693 * @deprecated Monolithic method, should be moved to proper classes
695 protected final function getDatabaseEntry () {
696 // This method is deprecated
697 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-FRAMEWORK-SYSTEM: CALLED!');
698 $this->deprecationWarning('Monolithic method, should be moved to proper classes');
700 // Is there an instance?
701 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-FRAMEWORK-SYSTEM: this->resultInstance[]=%s', gettype($this->getResultInstance())));
702 if (!$this->getResultInstance() instanceof SearchableResult) {
703 // Throw an exception here
704 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
708 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-FRAMEWORK-SYSTEM: Invoking this->resultInstance->rewind() ...');
709 $this->getResultInstance()->rewind();
711 // Do we have an entry?
712 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-FRAMEWORK-SYSTEM: this->resultInstance->isValid()=%d', intval($this->getResultInstance()->isValid())));
713 if ($this->getResultInstance()->valid() === false) {
714 // @TODO Move the constant to e.g. BaseDatabaseResult when there is a non-cached database result available
715 throw new InvalidDatabaseResultException(array($this, $this->getResultInstance()), CachedDatabaseResult::EXCEPTION_INVALID_DATABASE_RESULT);
719 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-FRAMEWORK-SYSTEM: Invoking this->resultInstance->next() ...');
720 $this->getResultInstance()->next();
723 $entry = $this->getResultInstance()->current();
726 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: entry[]=%s - EXIT!', gettype($entry)));
731 * Getter for field name
733 * @param $fieldName Field name which we shall get
734 * @return $fieldValue Field value from the user
735 * @throws NullPointerException If the result instance is null
736 * @throws InvalidArgumentException If a parameter is not valid
737 * @deprecated Monolithic method, should be moved to proper classes
739 public final function getField (string $fieldName) {
741 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: fieldName=%s - CALLED!', $fieldName));
742 if (empty($fieldName)) {
744 throw new InvalidArgumentException('Parameter "fieldName" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
747 // This method is deprecated
748 $this->deprecationWarning('Monolithic method, should be moved to proper classes');
750 // Default field value
753 // Get result instance
754 $resultInstance = $this->getResultInstance();
756 // Is this instance null?
757 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-FRAMEWORK-SYSTEM: resultInstance[]=%s', gettype($resultInstance)));
758 if (is_null($resultInstance)) {
759 // Then the user instance is no longer valid (expired cookies?)
760 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
764 $fieldArray = $resultInstance->current();
766 // Convert dashes to underscore
767 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-FRAMEWORK-SYSTEM: fieldArray()=%d', count($fieldArray)));
768 $fieldName2 = StringUtils::convertDashesToUnderscores($fieldName);
770 // Does the field exist?
771 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-FRAMEWORK-SYSTEM: fieldName2=%s', $fieldName2));
772 if ($this->isFieldSet($fieldName)) {
774 $fieldValue = $fieldArray[$fieldName2];
775 } elseif (FrameworkBootstrap::getConfigurationInstance()->isEnabled('developer_mode')) {
776 // Missing field entry, may require debugging
777 self::createDebugInstance(__CLASS__, __LINE__)->warningMessage('BASE-FRAMEWORK-SYSTEM: fieldArray<pre>=' . print_r($fieldArray, true) . '</pre>,fieldName=' . $fieldName . ' not found!');
779 // Missing field entry, may require debugging
780 self::createDebugInstance(__CLASS__, __LINE__)->warningMessage('BASE-FRAMEWORK-SYSTEM: fieldName=' . $fieldName . ' not found!');
784 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: fieldValue[]=%s - EXIT!', gettype($fieldValue)));
789 * Checks if given field is set
791 * @param $fieldName Field name to check
792 * @return $isSet Whether the given field name is set
793 * @throws NullPointerException If the result instance is null
794 * @throws InvalidArgumentException If a parameter is not valid
796 public function isFieldSet (string $fieldName) {
798 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: fieldName=%s - CALLED!', $fieldName));
799 if (empty($fieldName)) {
801 throw new InvalidArgumentException('Parameter "fieldName" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
804 // Get result instance
805 $resultInstance = $this->getResultInstance();
807 // Is this instance null?
808 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-FRAMEWORK-SYSTEM: resultInstance[]=%s', gettype($resultInstance)));
809 if (is_null($resultInstance)) {
810 // Then the user instance is no longer valid (expired cookies?)
811 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
815 $fieldArray = $resultInstance->current();
817 // Convert dashes to underscore
818 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-FRAMEWORK-SYSTEM: fieldArray()=%d,fieldName=%s - BEFORE!', count($fieldArray), $fieldName));
819 $fieldName = StringUtils::convertDashesToUnderscores($fieldName);
822 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-FRAMEWORK-SYSTEM: fieldName=%s - AFTER!', $fieldName));
823 $isset = isset($fieldArray[$fieldName]);
826 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: isset=%d - EXIT!', intval($isset)));
831 * Outputs a deprecation warning to the developer.
833 * @param $message The message we shall output to the developer
835 * @todo Write a logging mechanism for productive mode
837 public function deprecationWarning (string $message) {
838 // Is developer mode active?
839 if (FrameworkBootstrap::getConfigurationInstance()->isEnabled('developer_mode')) {
840 // Debug instance is there?
841 if (!is_null($this->getDebugInstance())) {
842 // Output stub message
843 self::createDebugInstance(__CLASS__, __LINE__)->warningMessage($message);
846 trigger_error($message . "<br />\n");
850 // @TODO Finish this part!
851 $this->partialStub('Developer mode inactive. Message:' . $message);
856 * Checks whether the given PHP extension is loaded
858 * @param $phpExtension The PHP extension we shall check
859 * @return $isLoaded Whether the PHP extension is loaded
860 * @throws InvalidArgumentException If a parameter is not valid
862 public final function isPhpExtensionLoaded (string $phpExtension) {
864 if (empty($phpExtension)) {
866 throw new InvalidArgumentException('Parameter "phpExtension" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
870 $isLoaded = in_array($phpExtension, get_loaded_extensions());
877 * "Getter" as a time() replacement but with milliseconds. You should use this
878 * method instead of the encapsulated getimeofday() function.
880 * @return $milliTime Timestamp with milliseconds
882 public function getMilliTime () {
883 // Get the time of day as float
884 $milliTime = gettimeofday(true);
891 * Idles (sleeps) for given milliseconds
893 * @return $hasSlept Whether it goes fine
894 * @throws InvalidArgumentException If a parameter is not valid
896 public function idle (int $milliSeconds) {
898 if ($milliSeconds < 1) {
900 throw new InvalidArgumentException(sprintf('milliSeconds=%d are not a reasonable value to idle', $milliSeconds));
903 // Sleep is fine by default
906 // Idle so long with found function
907 if (function_exists('time_sleep_until')) {
908 // Get current time and add idle time
909 $sleepUntil = $this->getMilliTime() + abs($milliSeconds) / 1000;
911 // New PHP 5.1.0 function found, ignore errors
912 $hasSlept = @time_sleep_until($sleepUntil);
915 * My Sun station doesn't have that function even with latest PHP
918 usleep($milliSeconds * 1000);
926 * Checks whether the given encoded data was encoded with Base64
928 * @param $encodedData Encoded data we shall check
929 * @return $isBase64 Whether the encoded data is Base64
930 * @throws InvalidArgumentException If a parameter is not valid
932 protected function isBase64Encoded (string $encodedData) {
934 if (empty($encodedData)) {
936 throw new InvalidArgumentException('Parameter "encodedData" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
940 $isBase64 = (@base64_decode($encodedData, true) !== false);
947 * Getter for startup time in miliseconds
949 * @return $startupTime Startup time in miliseconds
951 protected function getStartupTime () {
952 return self::$startupTime;
956 * "Getter" for a printable currently execution time in nice braces
958 * @return $executionTime Current execution time in nice braces
960 protected function getPrintableExecutionTime () {
961 // Calculate execution time and pack it in nice braces
962 $executionTime = sprintf('[ %01.5f ] ', (microtime(true) - $this->getStartupTime()));
965 return $executionTime;
969 * Determines if an element is set in the generic array
971 * @param $keyGroup Main group for the key
972 * @param $subGroup Sub group for the key
973 * @param $key Key to check
974 * @param $element Element to check
975 * @return $isset Whether the given key is set
976 * @throws InvalidArgumentException If a parameter is not valid
978 protected final function isGenericArrayElementSet (string $keyGroup, string $subGroup, string $key, string $element) {
980 if (empty($keyGroup)) {
982 throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
983 } elseif (empty($subGroup)) {
985 throw new InvalidArgumentException('Parameter "subGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
986 } elseif (empty($key)) {
988 throw new InvalidArgumentException('Parameter "key" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
989 } elseif ($element === '') {
991 throw new InvalidArgumentException('Parameter "element" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
995 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element);
996 $isset = isset($this->genericArray[$keyGroup][$subGroup][$key][$element]);
1002 * Determines if a key is set in the generic array
1004 * @param $keyGroup Main group for the key
1005 * @param $subGroup Sub group for the key
1006 * @param $key Key to check
1007 * @return $isset Whether the given key is set
1008 * @throws InvalidArgumentException If a parameter is not valid
1010 protected final function isGenericArrayKeySet (string $keyGroup, string $subGroup, string $key) {
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);
1018 } elseif (empty($key)) {
1020 throw new InvalidArgumentException('Parameter "key" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1024 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1025 $isset = isset($this->genericArray[$keyGroup][$subGroup][$key]);
1032 * Determines if a group is set in the generic array
1034 * @param $keyGroup Main group
1035 * @param $subGroup Sub group
1036 * @return $isset Whether the given group is set
1037 * @throws InvalidArgumentException If a parameter is not valid
1039 protected final function isGenericArrayGroupSet (string $keyGroup, string $subGroup) {
1041 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup);
1042 if (empty($keyGroup)) {
1044 throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1045 } elseif (empty($subGroup)) {
1047 throw new InvalidArgumentException('Parameter "subGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1051 $isset = isset($this->genericArray[$keyGroup][$subGroup]);
1058 * Getter for sub key group
1060 * @param $keyGroup Main key group
1061 * @param $subGroup Sub key group
1062 * @return $array An array with all array elements
1063 * @throws InvalidArgumentException If a parameter is not valid
1064 * @throws BadMethodCallException If key/sub group isn't there but this method is invoked
1066 protected final function getGenericSubArray (string $keyGroup, string $subGroup) {
1068 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',value=' . print_r($this->genericArray[$keyGroup][$subGroup], true));
1069 if (empty($keyGroup)) {
1071 throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1072 } elseif (empty($subGroup)) {
1074 throw new InvalidArgumentException('Parameter "subGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1075 } elseif (!$this->isGenericArrayGroupSet($keyGroup, $subGroup)) {
1076 // No, then abort here
1077 throw new BadMethodCallException(sprintf('keyGroup=%s,subGroup=%s not found.', $keyGroup, $subGroup), FrameworkInterface::EXCEPTION_BAD_METHOD_CALL);
1081 return $this->genericArray[$keyGroup][$subGroup];
1085 * Unsets a given key in generic array
1087 * @param $keyGroup Main group for the key
1088 * @param $subGroup Sub group for the key
1089 * @param $key Key to unset
1091 * @throws InvalidArgumentException If a parameter is not valid
1093 protected final function unsetGenericArrayKey (string $keyGroup, string $subGroup, string $key) {
1095 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1096 if (empty($keyGroup)) {
1098 throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1099 } elseif (empty($subGroup)) {
1101 throw new InvalidArgumentException('Parameter "subGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1102 } elseif (empty($key)) {
1104 throw new InvalidArgumentException('Parameter "key" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1108 unset($this->genericArray[$keyGroup][$subGroup][$key]);
1112 * Unsets a given element in generic array
1114 * @param $keyGroup Main group for the key
1115 * @param $subGroup Sub group for the key
1116 * @param $key Key to unset
1117 * @param $element Element to unset
1119 * @throws InvalidArgumentException If a parameter is not valid
1121 protected final function unsetGenericArrayElement (string $keyGroup, string $subGroup, string $key, string $element) {
1123 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element);
1124 if (empty($keyGroup)) {
1126 throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1127 } elseif (empty($subGroup)) {
1129 throw new InvalidArgumentException('Parameter "subGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1130 } elseif (empty($key)) {
1132 throw new InvalidArgumentException('Parameter "key" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1133 } elseif ($element === '') {
1135 throw new InvalidArgumentException('Parameter "element" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1139 unset($this->genericArray[$keyGroup][$subGroup][$key][$element]);
1143 * Append a string to a given generic array key
1145 * @param $keyGroup Main group for the key
1146 * @param $subGroup Sub group for the key
1147 * @param $key Key to unset
1148 * @param $value Value to add/append
1150 * @throws InvalidArgumentException If a parameter is not valid
1152 protected final function appendStringToGenericArrayKey (string $keyGroup, string $subGroup, $key, string $value, string $appendGlue = '') {
1154 //* 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);
1155 if (empty($keyGroup)) {
1157 throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1158 } elseif (empty($subGroup)) {
1160 throw new InvalidArgumentException('Parameter "subGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1161 } elseif (empty($key)) {
1163 throw new InvalidArgumentException('Parameter "key" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1166 // Is it already there?
1167 if ($this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
1169 $this->genericArray[$keyGroup][$subGroup][$key] .= $appendGlue . $value;
1172 $this->genericArray[$keyGroup][$subGroup][$key] = $value;
1177 * Append a string to a given generic array element
1179 * @param $keyGroup Main group for the key
1180 * @param $subGroup Sub group for the key
1181 * @param $key Key to unset
1182 * @param $element Element to check
1183 * @param $value Value to add/append
1185 * @throws InvalidArgumentException If a parameter is not valid
1187 protected final function appendStringToGenericArrayElement (string $keyGroup, string $subGroup, string $key, string $element, string $value, string $appendGlue = '') {
1189 //* 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);
1190 if (empty($keyGroup)) {
1192 throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1193 } elseif (empty($subGroup)) {
1195 throw new InvalidArgumentException('Parameter "subGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1196 } elseif (empty($key)) {
1198 throw new InvalidArgumentException('Parameter "key" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1199 } elseif ($element === '') {
1201 throw new InvalidArgumentException('Parameter "element" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1204 // Is it already there?
1205 if ($this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element)) {
1207 $this->genericArray[$keyGroup][$subGroup][$key][$element] .= $appendGlue . $value;
1210 $this->setGenericArrayElement($keyGroup, $subGroup, $key, $element, $value);
1215 * Initializes given generic array group
1217 * @param $keyGroup Main group for the key
1218 * @param $subGroup Sub group for the key
1219 * @param $key Key to use
1220 * @param $forceInit Optionally force initialization
1222 * @throws InvalidArgumentException If a parameter is not valid
1223 * @throws BadMethodCallException If key/sub group has already been initialized
1225 protected final function initGenericArrayGroup (string $keyGroup, string $subGroup, bool $forceInit = false) {
1227 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',forceInit=' . intval($forceInit));
1228 if (empty($keyGroup)) {
1230 throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1231 } elseif (empty($subGroup)) {
1233 throw new InvalidArgumentException('Parameter "subGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1234 } elseif (($forceInit === false) && ($this->isGenericArrayGroupSet($keyGroup, $subGroup))) {
1235 // Already initialized
1236 throw new BadMethodCallException(sprintf('keyGroup=%s,subGroup=%s already initialized.', $keyGroup, $subGroup), FrameworkInterface::EXCEPTION_BAD_METHOD_CALL);
1240 $this->genericArray[$keyGroup][$subGroup] = [];
1244 * Initializes given generic array key
1246 * @param $keyGroup Main group for the key
1247 * @param $subGroup Sub group for the key
1248 * @param $key Key to use
1249 * @param $forceInit Optionally force initialization
1251 * @throws InvalidArgumentException If a parameter is not valid
1252 * @throws BadMethodCallException If key/sub group has already been initialized
1254 protected final function initGenericArrayKey (string $keyGroup, string $subGroup, $key, bool $forceInit = false) {
1256 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',forceInit=' . intval($forceInit));
1257 if (empty($keyGroup)) {
1259 throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1260 } elseif (empty($subGroup)) {
1262 throw new InvalidArgumentException('Parameter "subGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1263 } elseif (empty($key)) {
1265 throw new InvalidArgumentException('Parameter "key" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1266 } elseif (($forceInit === false) && ($this->isGenericArrayKeySet($keyGroup, $subGroup, $key))) {
1267 // Already initialized
1268 throw new BadMethodCallException(sprintf('keyGroup=%s,subGroup=%s,key[%s]=%s already initialized.', $keyGroup, $subGroup, gettype($key), $key), FrameworkInterface::EXCEPTION_BAD_METHOD_CALL);
1272 $this->genericArray[$keyGroup][$subGroup][$key] = [];
1276 * Initializes given generic array element
1278 * @param $keyGroup Main group for the key
1279 * @param $subGroup Sub group for the key
1280 * @param $key Key to use
1281 * @param $element Element to use
1282 * @param $forceInit Optionally force initialization
1284 * @throws InvalidArgumentException If a parameter is not valid
1285 * @throws BadMethodCallException If key/sub group isn't there but this method is invoked
1287 protected final function initGenericArrayElement (string $keyGroup, string $subGroup, string $key, string $element, bool $forceInit = false) {
1289 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element . ',forceInit=' . intval($forceInit));
1290 if (empty($keyGroup)) {
1292 throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1293 } elseif (empty($subGroup)) {
1295 throw new InvalidArgumentException('Parameter "subGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1296 } elseif (empty($key)) {
1298 throw new InvalidArgumentException('Parameter "key" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1299 } elseif ($element === '') {
1301 throw new InvalidArgumentException('Parameter "element" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1302 } elseif (($forceInit === false) && ($this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element))) {
1303 // Already initialized
1304 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);
1308 $this->genericArray[$keyGroup][$subGroup][$key][$element] = [];
1312 * Pushes an element to a generic key. If the key isn't found, it will be initialized.
1314 * @param $keyGroup Main group for the key
1315 * @param $subGroup Sub group for the key
1316 * @param $key Key to use
1317 * @param $value Value to add/append
1318 * @return $count Number of array elements
1319 * @throws InvalidArgumentException If a parameter is not valid
1321 protected final function pushValueToGenericArrayKey (string $keyGroup, string $subGroup, string $key, $value) {
1323 //* NOISY-DEBUG: */ if (!is_object($value)) $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',value[' . gettype($value) . ']=' . print_r($value, true));
1324 if (empty($keyGroup)) {
1326 throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1327 } elseif (empty($subGroup)) {
1329 throw new InvalidArgumentException('Parameter "subGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1330 } elseif (empty($key)) {
1332 throw new InvalidArgumentException('Parameter "key" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1333 } elseif (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
1335 $this->initGenericArrayKey($keyGroup, $subGroup, $key);
1339 $count = array_push($this->genericArray[$keyGroup][$subGroup][$key], $value);
1342 //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], true));
1343 //* DEBUG: */ print(__METHOD__ . ': count=' . $count . PHP_EOL);
1348 * Pushes an element to a generic array element. If the key isn't found, it will be initialized.
1350 * @param $keyGroup Main group for the key
1351 * @param $subGroup Sub group for the key
1352 * @param $key Key to use
1353 * @param $element Element to check
1354 * @param $value Value to add/append
1355 * @return $count Number of array elements
1356 * @throws InvalidArgumentException If a parameter is not valid
1358 protected final function pushValueToGenericArrayElement (string $keyGroup, string $subGroup, string $key, string $element, $value) {
1360 //* 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));
1361 if (empty($keyGroup)) {
1363 throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1364 } elseif (empty($subGroup)) {
1366 throw new InvalidArgumentException('Parameter "subGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1367 } elseif (empty($key)) {
1369 throw new InvalidArgumentException('Parameter "key" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1370 } elseif ($element === '') {
1372 throw new InvalidArgumentException('Parameter "element" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1373 } elseif (!$this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element)) {
1375 $this->initGenericArrayElement($keyGroup, $subGroup, $key, $element);
1379 $count = array_push($this->genericArray[$keyGroup][$subGroup][$key][$element], $value);
1382 //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], true));
1383 //* DEBUG: */ print(__METHOD__ . ': count=' . $count . PHP_EOL);
1388 * Pops an element from a generic group
1390 * @param $keyGroup Main group for the key
1391 * @param $subGroup Sub group for the key
1392 * @param $key Key to unset
1393 * @return $value Last "popped" value
1394 * @throws InvalidArgumentException If a parameter is not valid
1395 * @throws BadMethodCallException If key/sub group isn't there but this method is invoked
1397 protected final function popGenericArrayElement (string $keyGroup, string $subGroup, string $key) {
1399 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1400 if (empty($keyGroup)) {
1402 throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1403 } elseif (empty($subGroup)) {
1405 throw new InvalidArgumentException('Parameter "subGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1406 } elseif (empty($key)) {
1408 throw new InvalidArgumentException('Parameter "key" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1409 } elseif (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
1411 throw new BadMethodCallException(sprintf('keyGroup=%s,subGroup=%s,key[%s]=%s not found.', $keyGroup, $subGroup, gettype($key), $key), FrameworkInterface::EXCEPTION_BAD_METHOD_CALL);
1415 $value = array_pop($this->genericArray[$keyGroup][$subGroup][$key]);
1418 //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], true));
1419 //* DEBUG: */ print(__METHOD__ . ': value[' . gettype($value) . ']=' . print_r($value, true) . PHP_EOL);
1424 * Shifts an element from a generic group
1426 * @param $keyGroup Main group for the key
1427 * @param $subGroup Sub group for the key
1428 * @param $key Key to unset
1429 * @return $value Last "shifted" value
1430 * @throws InvalidArgumentException If a parameter is not valid
1431 * @throws BadMethodCallException If key/sub group isn't there but this method is invoked
1433 protected final function shiftGenericArrayElement (string $keyGroup, string $subGroup, string $key) {
1435 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1436 if (empty($keyGroup)) {
1438 throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1439 } elseif (empty($subGroup)) {
1441 throw new InvalidArgumentException('Parameter "subGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1442 } elseif (empty($key)) {
1444 throw new InvalidArgumentException('Parameter "key" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1445 } elseif (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
1447 throw new BadMethodCallException(sprintf('keyGroup=%s,subGroup=%s,key[%s]=%s not found.', $keyGroup, $subGroup, gettype($key), $key), FrameworkInterface::EXCEPTION_BAD_METHOD_CALL);
1451 $value = array_shift($this->genericArray[$keyGroup][$subGroup][$key]);
1454 //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], true));
1455 //* DEBUG: */ print(__METHOD__ . ': value[' . gettype($value) . ']=' . print_r($value, true) . PHP_EOL);
1460 * Count generic array group
1462 * @param $keyGroup Main group for the key
1463 * @return $count Count of given group
1464 * @throws InvalidArgumentException If a parameter is not valid
1465 * @throws BadMethodCallException If key group isn't there but this method is invoked
1467 protected final function countGenericArray (string $keyGroup) {
1469 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup);
1470 if (empty($keyGroup)) {
1472 throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1473 } elseif (!isset($this->genericArray[$keyGroup])) {
1475 throw new BadMethodCallException(sprintf('keyGroup=%s not found.', $keyGroup), FrameworkInterface::EXCEPTION_BAD_METHOD_CALL);
1479 $count = count($this->genericArray[$keyGroup]);
1482 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',count=' . $count);
1487 * Count generic array sub group
1489 * @param $keyGroup Main group for the key
1490 * @param $subGroup Sub group for the key
1491 * @return $count Count of given group
1492 * @throws InvalidArgumentException If a parameter is not valid
1493 * @throws BadMethodCallException If key/sub group isn't there but this method is invoked
1495 protected final function countGenericArrayGroup (string $keyGroup, string $subGroup) {
1497 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup);
1498 if (empty($keyGroup)) {
1500 throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1501 } elseif (empty($subGroup)) {
1503 throw new InvalidArgumentException('Parameter "subGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1504 } elseif (!$this->isGenericArrayGroupSet($keyGroup, $subGroup)) {
1506 throw new BadMethodCallException(sprintf('keyGroup=%s,subGroup=%s not found.', $keyGroup, $subGroup), FrameworkInterface::EXCEPTION_BAD_METHOD_CALL);
1510 $count = count($this->genericArray[$keyGroup][$subGroup]);
1513 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',count=' . $count);
1518 * Count generic array elements
1520 * @param $keyGroup Main group for the key
1521 * @param $subGroup Sub group for the key
1522 * @param $key Key to count
1523 * @return $count Count of given key
1524 * @throws InvalidArgumentException If a parameter is not valid
1525 * @throws BadMethodCallException If key/sub group isn't there but this method is invoked
1527 protected final function countGenericArrayElements (string $keyGroup, string $subGroup, string $key) {
1529 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1530 if (empty($keyGroup)) {
1532 throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1533 } elseif (empty($subGroup)) {
1535 throw new InvalidArgumentException('Parameter "subGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1536 } elseif (empty($key)) {
1538 throw new InvalidArgumentException('Parameter "key" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1539 } elseif (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
1541 throw new BadMethodCallException(sprintf('keyGroup=%s,subGroup=%s,key[%s]=%s not found.', $keyGroup, $subGroup, gettype($key), $key), FrameworkInterface::EXCEPTION_BAD_METHOD_CALL);
1542 } elseif (!$this->isValidGenericArrayGroup($keyGroup, $subGroup)) {
1544 throw new BadMethodCallException(sprintf('keyGroup=%s,subGroup=%s is not a valid key/sub group.', $keyGroup, $subGroup), FrameworkInterface::EXCEPTION_BAD_METHOD_CALL);
1548 $count = count($this->genericArray[$keyGroup][$subGroup][$key]);
1551 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',count=' . $count);
1556 * Getter for whole generic group array
1558 * @param $keyGroup Key group to get
1559 * @return $array Whole generic array group
1560 * @throws InvalidArgumentException If a parameter is not valid
1561 * @throws BadMethodCallException If key/sub group isn't there but this method is invoked
1563 protected final function getGenericArray (string $keyGroup) {
1565 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup);
1566 if (empty($keyGroup)) {
1568 throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1569 } elseif (!isset($this->genericArray[$keyGroup])) {
1571 throw new BadMethodCallException(sprintf('keyGroup=%s not found', $keyGroup), FrameworkInterface::EXCEPTION_BAD_METHOD_CALL);
1575 return $this->genericArray[$keyGroup];
1579 * Setter for generic array key
1581 * @param $keyGroup Key group to get
1582 * @param $subGroup Sub group for the key
1583 * @param $key Key to unset
1584 * @param $value Mixed value from generic array element
1586 * @throws InvalidArgumentException If a parameter is not valid
1587 * @throws BadMethodCallException If key/sub group isn't there but this method is invoked
1589 protected final function setGenericArrayKey (string $keyGroup, string $subGroup, string $key, $value) {
1591 //* NOISY-DEBUG: */ if (!is_object($value)) $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',value[' . gettype($value) . ']=' . print_r($value, true));
1592 if (empty($keyGroup)) {
1594 throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1595 } elseif (empty($subGroup)) {
1597 throw new InvalidArgumentException('Parameter "subGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1598 } elseif (empty($key)) {
1600 throw new InvalidArgumentException('Parameter "key" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1601 } elseif (!$this->isValidGenericArrayGroup($keyGroup, $subGroup)) {
1603 throw new BadMethodCallException(sprintf('keyGroup=%s,subGroup=%s not found', $keyGroup), FrameworkInterface::EXCEPTION_BAD_METHOD_CALL);
1607 $this->genericArray[$keyGroup][$subGroup][$key] = $value;
1611 * Getter for generic array key
1613 * @param $keyGroup Key group to get
1614 * @param $subGroup Sub group for the key
1615 * @param $key Key to unset
1616 * @return $value Mixed value from generic array element
1617 * @throws InvalidArgumentException If a parameter is not valid
1618 * @throws BadMethodCallException If key/sub group isn't there but this method is invoked
1620 protected final function getGenericArrayKey (string $keyGroup, string $subGroup, string $key) {
1622 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1623 if (empty($keyGroup)) {
1625 throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1626 } elseif (empty($subGroup)) {
1628 throw new InvalidArgumentException('Parameter "subGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1629 } elseif (empty($key)) {
1631 throw new InvalidArgumentException('Parameter "key" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1632 } elseif (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
1634 throw new BadMethodCallException(sprintf('keyGroup=%s,subGroup=%s,key[%s]=%s not found.', $keyGroup, $subGroup, gettype($key), $key), FrameworkInterface::EXCEPTION_BAD_METHOD_CALL);
1638 return $this->genericArray[$keyGroup][$subGroup][$key];
1642 * Sets a value in given generic array key/element
1644 * @param $keyGroup Main group for the key
1645 * @param $subGroup Sub group for the key
1646 * @param $key Key to set
1647 * @param $element Element to set
1648 * @param $value Value to set
1650 * @throws InvalidArgumentException If a parameter is not valid
1652 protected final function setGenericArrayElement (string $keyGroup, string $subGroup, string $key, string $element, $value) {
1654 //* 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));
1655 if (empty($keyGroup)) {
1657 throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1658 } elseif (empty($subGroup)) {
1660 throw new InvalidArgumentException('Parameter "subGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1661 } elseif (empty($key)) {
1663 throw new InvalidArgumentException('Parameter "key" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1664 } elseif ($element === '') {
1666 throw new InvalidArgumentException('Parameter "element" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1667 } elseif (!$this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element)) {
1669 $this->initGenericArrayElement($keyGroup, $subGroup, $key, $element);
1673 $this->genericArray[$keyGroup][$subGroup][$key][$element] = $value;
1677 * Getter for generic array element
1679 * @param $keyGroup Key group to get
1680 * @param $subGroup Sub group for the key
1681 * @param $key Key to look for
1682 * @param $element Element to look for
1683 * @return $value Mixed value from generic array element
1684 * @throws InvalidArgumentException If a parameter is not valid
1685 * @throws BadMethodCallException If key/sub group isn't there but this method is invoked
1687 protected final function getGenericArrayElement (string $keyGroup, string $subGroup, string $key, string $element) {
1689 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element);
1690 if (empty($keyGroup)) {
1692 throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1693 } elseif (empty($subGroup)) {
1695 throw new InvalidArgumentException('Parameter "subGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1696 } elseif (empty($key)) {
1698 throw new InvalidArgumentException('Parameter "key" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1699 } elseif ($element === '') {
1701 throw new InvalidArgumentException('Parameter "element" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1702 } elseif (!$this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element)) {
1704 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);
1708 return $this->genericArray[$keyGroup][$subGroup][$key][$element];
1712 * Checks if a given sub group is valid (array)
1714 * @param $keyGroup Key group to get
1715 * @param $subGroup Sub group for the key
1716 * @return $isValid Whether given sub group is valid
1717 * @throws InvalidArgumentException If a parameter is not valid
1719 protected final function isValidGenericArrayGroup (string $keyGroup, string $subGroup) {
1721 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup);
1722 if (empty($keyGroup)) {
1724 throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1725 } elseif (empty($subGroup)) {
1727 throw new InvalidArgumentException('Parameter "subGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1731 $isValid = (($this->isGenericArrayGroupSet($keyGroup, $subGroup)) && (is_array($this->getGenericSubArray($keyGroup, $subGroup))));
1738 * Checks if a given key is valid (array)
1740 * @param $keyGroup Key group to get
1741 * @param $subGroup Sub group for the key
1742 * @param $key Key to check
1743 * @return $isValid Whether given sub group is valid
1745 protected final function isValidGenericArrayKey (string $keyGroup, string $subGroup, string $key) {
1747 //* NOISY-DEBUG: */ $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key);
1748 if (empty($keyGroup)) {
1750 throw new InvalidArgumentException('Parameter "keyGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1751 } elseif (empty($subGroup)) {
1753 throw new InvalidArgumentException('Parameter "subGroup" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1754 } elseif (empty($key)) {
1756 throw new InvalidArgumentException('Parameter "key" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
1760 $isValid = (($this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) && (is_array($this->getGenericArrayKey($keyGroup, $subGroup, $key))));
1767 * Initializes the web output instance
1771 protected function initWebOutputInstance () {
1772 // Init web output instance
1773 $outputInstance = ObjectFactory::createObjectByConfiguredName('output_class');
1776 $this->setWebOutputInstance($outputInstance);
1780 * Translates boolean true to 'Y' and false to 'N'
1782 * @param $boolean Boolean value
1783 * @return $translated Translated boolean value
1785 public static final function translateBooleanToYesNo (bool $boolean) {
1787 $translated = ($boolean === true) ? 'Y' : 'N';
1789 // ... and return it
1794 * Creates a full-qualified file name (FQFN) for given file name by adding
1795 * a configured temporary file path to it.
1797 * @param $infoInstance An instance of a SplFileInfo class
1798 * @return $tempInstance An instance of a SplFileInfo class (temporary file)
1799 * @throw PathWriteProtectedException If the path in 'temp_file_path' is write-protected
1800 * @throws FileIoException If the file cannot be written
1802 protected static function createTempPathForFile (SplFileInfo $infoInstance) {
1804 $basePath = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('temp_file_path');
1806 // Is the path writeable?
1807 if (!is_writable($basePath)) {
1808 // Path is write-protected
1809 throw new PathWriteProtectedException($infoInstance, self::EXCEPTION_PATH_CANNOT_BE_WRITTEN);
1813 $tempInstance = new SplFileInfo($basePath . DIRECTORY_SEPARATOR . $infoInstance->getBasename());
1816 if (!FrameworkBootstrap::isReachableFilePath($tempInstance)) {
1818 throw new FileIoException($tempInstance, self::EXCEPTION_FILE_NOT_REACHABLE);
1822 return $tempInstance;
1826 * "Getter" for a printable state name
1828 * @return $stateName Name of the node's state in a printable format
1829 * @todo Move this class away from this monolithic place (not whole class is monolithic)
1831 public final function getPrintableState () {
1832 // Default is 'null'
1833 $stateName = 'null';
1835 // Get the state instance
1836 $stateInstance = $this->getStateInstance();
1838 // Is it an instance of Stateable?
1839 if ($stateInstance instanceof Stateable) {
1840 // Then use that state name
1841 $stateName = $stateInstance->getStateName();