3 * The simulator system class is the super class of all other classes. This
4 * class handles saving of games etc.
6 * @author Roland Haeder <webmaster@ship-simu.org>
8 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team
9 * @license GNU GPL 3.0 or any newer version
10 * @link http://www.ship-simu.org
12 * This program is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation, either version 3 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
27 * Instance of a request class
29 private $requestInstance = null;
32 * Instance of a response class
34 private $responseInstance = null;
37 * Search criteria instance
39 private $searchInstance = null;
42 * Update criteria instance
44 private $updateInstance = null;
47 * The file I/O instance for the template loader
49 private $fileIoInstance = null;
54 private $resolverInstance = null;
57 * Template engine instance
59 private $templateInstance = null;
62 * Database result instance
64 private $resultInstance = null;
67 * Instance for user class
69 private $userInstance = null;
72 * A controller instance
74 private $controllerInstance = null;
79 private $rngInstance = null;
82 * Instance of an Iterator class
84 private $iteratorInstance = null;
87 * Instance of the list
89 private $listInstance = null;
94 private $menuInstance = null;
99 private $realClass = 'BaseFrameworkSystem';
102 * Thousands seperator
104 private $thousands = '.'; // German
109 private $decimals = ','; // German
111 /***********************
112 * Exception codes.... *
113 ***********************/
114 // @todo Try to clean these constants up
115 const EXCEPTION_IS_NULL_POINTER = 0x001;
116 const EXCEPTION_IS_NO_OBJECT = 0x002;
117 const EXCEPTION_IS_NO_ARRAY = 0x003;
118 const EXCEPTION_MISSING_METHOD = 0x004;
119 const EXCEPTION_CLASSES_NOT_MATCHING = 0x005;
120 const EXCEPTION_INDEX_OUT_OF_BOUNDS = 0x006;
121 const EXCEPTION_DIMENSION_ARRAY_INVALID = 0x007;
122 const EXCEPTION_ITEM_NOT_TRADEABLE = 0x008;
123 const EXCEPTION_ITEM_NOT_IN_PRICE_LIST = 0x009;
124 const EXCEPTION_GENDER_IS_WRONG = 0x00a;
125 const EXCEPTION_BIRTH_DATE_IS_INVALID = 0x00b;
126 const EXCEPTION_EMPTY_STRUCTURES_ARRAY = 0x00c;
127 const EXCEPTION_HAS_ALREADY_PERSONELL_LIST = 0x00d;
128 const EXCEPTION_NOT_ENOUGTH_UNEMPLOYEES = 0x00e;
129 const EXCEPTION_TOTAL_PRICE_NOT_CALCULATED = 0x00f;
130 const EXCEPTION_HARBOR_HAS_NO_SHIPYARDS = 0x010;
131 const EXCEPTION_CONTRACT_PARTNER_INVALID = 0x011;
132 const EXCEPTION_CONTRACT_PARTNER_MISMATCH = 0x012;
133 const EXCEPTION_CONTRACT_ALREADY_SIGNED = 0x013;
134 const EXCEPTION_UNEXPECTED_EMPTY_STRING = 0x014;
135 const EXCEPTION_PATH_NOT_FOUND = 0x015;
136 const EXCEPTION_INVALID_PATH_NAME = 0x016;
137 const EXCEPTION_READ_PROTECED_PATH = 0x017;
138 const EXCEPTION_WRITE_PROTECED_PATH = 0x018;
139 const EXCEPTION_DIR_POINTER_INVALID = 0x019;
140 const EXCEPTION_FILE_POINTER_INVALID = 0x01a;
141 const EXCEPTION_INVALID_RESOURCE = 0x01b;
142 const EXCEPTION_UNEXPECTED_OBJECT = 0x01c;
143 const EXCEPTION_LIMIT_ELEMENT_IS_UNSUPPORTED = 0x01d;
144 const EXCEPTION_GETTER_IS_MISSING = 0x01e;
145 const EXCEPTION_ARRAY_EXPECTED = 0x01f;
146 const EXCEPTION_ARRAY_HAS_INVALID_COUNT = 0x020;
147 const EXCEPTION_ID_IS_INVALID_FORMAT = 0x021;
148 const EXCEPTION_MD5_CHECKSUMS_MISMATCH = 0x022;
149 const EXCEPTION_UNEXPECTED_STRING_SIZE = 0x023;
150 const EXCEPTION_SIMULATOR_ID_INVALID = 0x024;
151 const EXCEPTION_MISMATCHING_COMPRESSORS = 0x025;
152 const EXCEPTION_CONTAINER_ITEM_IS_NULL = 0x026;
153 const EXCEPTION_ITEM_IS_NO_ARRAY = 0x027;
154 const EXCEPTION_CONTAINER_MAYBE_DAMAGED = 0x028;
155 const EXCEPTION_INVALID_STRING = 0x029;
156 const EXCEPTION_VARIABLE_NOT_SET = 0x02a;
157 const EXCEPTION_ATTRIBUTES_ARE_MISSING = 0x02b;
158 const EXCEPTION_ARRAY_ELEMENTS_MISSING = 0x02c;
159 const EXCEPTION_TEMPLATE_ENGINE_UNSUPPORTED = 0x02d;
160 const EXCEPTION_MISSING_LANGUAGE_HANDLER = 0x02e;
161 const EXCEPTION_MISSING_FILE_IO_HANDLER = 0x02f;
162 const EXCEPTION_MISSING_ELEMENT = 0x030;
163 const EXCEPTION_HEADERS_ALREADY_SENT = 0x031;
164 const EXCEPTION_DEFAULT_CONTROLLER_GONE = 0x032;
165 const EXCEPTION_CLASS_NOT_FOUND = 0x033;
166 const EXCEPTION_REQUIRED_INTERFACE_MISSING = 0x034;
167 const EXCEPTION_FATAL_ERROR = 0x035;
168 const EXCEPTION_FILE_NOT_FOUND = 0x036;
169 const EXCEPTION_ASSERTION_FAILED = 0x037;
170 const EXCEPTION_FILE_CANNOT_BE_READ = 0x038;
171 const EXCEPTION_DATABASE_UPDATED_NOT_ALLOWED = 0x039;
172 const EXCEPTION_FILTER_CHAIN_INTERCEPTED = 0x040;
175 * Protected super constructor
177 * @param $className Name of the class
180 protected function __construct ($className) {
182 $this->setRealClass($className);
184 // Set configuration instance if no registry
185 if (!$this instanceof Register) {
186 // Because registries doesn't need to be configured
187 $this->setConfigInstance(FrameworkConfiguration::getInstance());
192 * Destructor reached...
195 * @todo This is old code. Do we still need this old lost code?
197 public function __destruct() {
198 // Flush any updated entries to the database
199 $this->flushPendingUpdates();
201 // Is this object already destroyed?
202 if ($this->__toString() != 'DestructedObject') {
203 // Destroy all informations about this class but keep some text about it alive
204 $this->setRealClass('DestructedObject');
205 } elseif ((defined('DEBUG_DESTRUCTOR')) && (is_object($this->getDebugInstance()))) {
206 // Already destructed object
207 $this->debugOutput(sprintf("[%s:] The object <span class=\"object_name\">%s</span> is already destroyed.",
215 * The call method where all non-implemented methods end up
219 public final function __call ($methodName, $args) {
220 // Implode all given arguments
224 $argsString = 'NULL';
225 } elseif (is_array($args)) {
226 // Some arguments are there
227 foreach ($args as $arg) {
229 $argsString .= $arg . ' (' . gettype($arg);
231 // Add length if type is string
232 if (gettype($arg) == 'string') $argsString .= ', '.strlen($arg);
235 $argsString .= '), ';
239 if (substr($argsString, -2, 1) == ',') {
240 $argsString = substr($argsString, 0, -2);
243 // Invalid arguments!
244 $argsString = '!INVALID:' . gettype($args) . '!';
247 // Output stub message
248 $this->debugOutput(sprintf("[%s->%s] Stub! Args: %s",
259 * Setter for database result instance
261 * @param $resultInstance An instance of a database result class
263 * @todo SearchableResult and UpdateableResult shall have a super interface to use here
265 protected final function setResultInstance (SearchableResult $resultInstance) {
266 $this->resultInstance = $resultInstance;
270 * Getter for database result instance
272 * @return $resultInstance An instance of a database result class
274 public final function getResultInstance () {
275 return $this->resultInstance;
279 * Setter for template engine instances
281 * @param $templateInstance An instance of a template engine class
284 protected final function setTemplateInstance (CompileableTemplate $templateInstance) {
285 $this->templateInstance = $templateInstance;
289 * Getter for template engine instances
291 * @return $templateInstance An instance of a template engine class
293 protected final function getTemplateInstance () {
294 return $this->templateInstance;
298 * Setter for search instance
300 * @param $searchInstance Searchable criteria instance
303 public final function setSearchInstance (LocalSearchCriteria $searchInstance) {
304 $this->searchInstance = $searchInstance;
308 * Getter for search instance
310 * @return $searchInstance Searchable criteria instance
312 public final function getSearchInstance () {
313 return $this->searchInstance;
317 * Setter for update instance
319 * @param $updateInstance Searchable criteria instance
322 public final function setUpdateInstance (LocalUpdateCriteria $updateInstance) {
323 $this->updateInstance = $updateInstance;
327 * Getter for update instance
329 * @return $updateInstance Updateable criteria instance
331 public final function getUpdateInstance () {
332 return $this->updateInstance;
336 * Setter for resolver instance
338 * @param $resolverInstance Instance of a command resolver class
341 public final function setResolverInstance (Resolver $resolverInstance) {
342 $this->resolverInstance = $resolverInstance;
346 * Getter for resolver instance
348 * @return $resolverInstance Instance of a command resolver class
350 public final function getResolverInstance () {
351 return $this->resolverInstance;
355 * Setter for language instance
357 * @param $configInstance The configuration instance which shall
358 * be FrameworkConfiguration
361 public final function setConfigInstance (FrameworkConfiguration $configInstance) {
362 Registry::getRegistry()->addInstance('config', $configInstance);
366 * Getter for configuration instance
368 * @return $configInstance Configuration instance
370 public final function getConfigInstance () {
371 $configInstance = Registry::getRegistry()->getInstance('config');
372 return $configInstance;
376 * Setter for debug instance
378 * @param $debugInstance The instance for debug output class
381 public final function setDebugInstance (DebugMiddleware $debugInstance) {
382 Registry::getRegistry()->addInstance('debug', $debugInstance);
386 * Getter for debug instance
388 * @return $debugInstance Instance to class DebugConsoleOutput or DebugWebOutput
390 public final function getDebugInstance () {
391 // Get debug instance
392 $debugInstance = Registry::getRegistry()->getInstance('debug');
395 return $debugInstance;
399 * Setter for web output instance
401 * @param $webInstance The instance for web output class
404 public final function setWebOutputInstance (OutputStreamer $webInstance) {
405 Registry::getRegistry()->addInstance('web_output', $webInstance);
409 * Getter for web output instance
411 * @return $webOutputInstance - Instance to class WebOutput
413 public final function getWebOutputInstance () {
414 $webOutputInstance = Registry::getRegistry()->getInstance('web_output');
415 return $webOutputInstance;
419 * Setter for database instance
421 * @param $dbInstance The instance for the database connection
422 * (forced DatabaseConnection)
425 public final function setDatabaseInstance (DatabaseConnection $dbInstance) {
426 Registry::getRegistry()->addInstance('db_instance', $dbInstance);
430 * Getter for database layer
432 * @return $dbInstance The database layer instance
434 public final function getDatabaseInstance () {
436 $dbInstance = Registry::getRegistry()->getInstance('db_instance');
443 * Setter for compressor channel
445 * @param $compressorInstance An instance of CompressorChannel
448 public final function setCompressorChannel (CompressorChannel $compressorInstance) {
449 Registry::getRegistry()->addInstance('compressor', $compressorInstance);
453 * Getter for compressor channel
455 * @return $compressorInstance The compressor channel
457 public final function getCompressorChannel () {
458 $compressorInstance = Registry::getRegistry()->getInstance('compressor');
459 return $compressorInstance;
463 * Protected getter for a manageable application helper class
465 * @return $applicationInstance An instance of a manageable application helper class
467 protected final function getApplicationInstance () {
468 $applicationInstance = Registry::getRegistry()->getInstance('application');
469 return $applicationInstance;
473 * Setter for a manageable application helper class
475 * @param $applicationInstance An instance of a manageable application helper class
478 public final function setApplicationInstance (ManageableApplication $applicationInstance) {
479 Registry::getRegistry()->addInstance('application', $applicationInstance);
483 * Setter for request instance
485 * @param $requestInstance An instance of a Requestable class
488 public final function setRequestInstance (Requestable $requestInstance) {
489 $this->requestInstance = $requestInstance;
493 * Getter for request instance
495 * @return $requestInstance An instance of a Requestable class
497 public final function getRequestInstance () {
498 return $this->requestInstance;
502 * Setter for response instance
504 * @param $responseInstance An instance of a Responseable class
507 public final function setResponseInstance (Responseable $responseInstance) {
508 $this->responseInstance = $responseInstance;
512 * Getter for response instance
514 * @return $responseInstance An instance of a Responseable class
516 public final function getResponseInstance () {
517 return $this->responseInstance;
521 * Getter for $realClass
523 * @return $realClass The name of the real class (not BaseFrameworkSystem)
525 public final function __toString () {
526 return $this->realClass;
530 * Setter for the real class name
532 * @param $realClass Class name (string)
535 public final function setRealClass ($realClass) {
537 $realClass = (string) $realClass;
540 $this->realClass = $realClass;
544 * Checks wether an object equals this object. You should overwrite this
545 * method to implement own equality checks
547 * @param $objectInstance An instance of a FrameworkInterface object
548 * @return $equals Wether both objects equals
550 public function equals (FrameworkInterface $objectInstance) {
553 $this->__toString() == $objectInstance->__toString()
555 $this->hashCode() == $objectInstance->hashCode()
563 * Formats computer generated price values into human-understandable formats
564 * with thousand and decimal seperators.
566 * @param $value The in computer format value for a price
567 * @param $currency The currency symbol (use HTML-valid characters!)
568 * @param $decNum Number of decimals after commata
569 * @return $price The for the current language formated price string
570 * @throws MissingDecimalsThousandsSeperatorException If decimals or
571 * thousands seperator
574 public function formatCurrency ($value, $currency = '€', $decNum = 2) {
575 // Are all required attriutes set?
576 if ((!isset($this->decimals)) || (!isset($this->thousands))) {
577 // Throw an exception
578 throw new MissingDecimalsThousandsSeperatorException($this, self::EXCEPTION_ATTRIBUTES_ARE_MISSING);
582 $value = (float) $value;
584 // Reformat the US number
585 $price = number_format($value, $decNum, $this->decimals, $this->thousands) . $currency;
587 // Return as string...
592 * Private getter for language instance
594 * @return $langInstance An instance to the language sub-system
596 protected final function getLanguageInstance () {
597 $langInstance = Registry::getRegistry()->getInstance('language');
598 return $langInstance;
602 * Setter for language instance
604 * @param $langInstance An instance to the language sub-system
606 * @see LanguageSystem
608 public final function setLanguageInstance (ManageableLanguage $langInstance) {
609 Registry::getRegistry()->addInstance('language', $langInstance);
613 * Appends a trailing slash to a string
615 * @param $str A string (maybe) without trailing slash
616 * @return $str A string with an auto-appended trailing slash
618 public final function addMissingTrailingSlash ($str) {
619 // Is there a trailing slash?
620 if (substr($str, -1, 1) != '/') $str .= '/';
625 * Private getter for file IO instance
627 * @return $fileIoInstance An instance to the file I/O sub-system
629 protected final function getFileIoInstance () {
630 return $this->fileIoInstance;
634 * Setter for file I/O instance
636 * @param $fileIoInstance An instance to the file I/O sub-system
639 public final function setFileIoInstance (FileIoHandler $fileIoInstance) {
640 $this->fileIoInstance = $fileIoInstance;
644 * Prepare the template engine (WebTemplateEngine by default) for a given
645 * application helper instance (ApplicationHelper by default).
647 * @param $appInstance An application helper instance or
648 * null if we shall use the default
649 * @return $templateInstance The template engine instance
650 * @throws NullPointerException If the template engine could not
652 * @throws UnsupportedTemplateEngineException If $templateInstance is an
653 * unsupported template engine
654 * @throws MissingLanguageHandlerException If the language sub-system
655 * is not yet initialized
656 * @throws NullPointerException If the discovered application
657 * instance is still null
659 protected function prepareTemplateInstance (FrameworkInterface $appInstance=null) {
660 // Is the application instance set?
661 if (is_null($appInstance)) {
662 // Get the current instance
663 $appInstance = $this->getApplicationInstance();
666 if (is_null($appInstance)) {
667 // Thrown an exception
668 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
672 // Are both instances set?
673 if ($appInstance->getLanguageInstance() === null) {
674 // Invalid language instance
675 throw new MissingLanguageHandlerException($appInstance, self::EXCEPTION_MISSING_LANGUAGE_HANDLER);
676 } elseif ($appInstance->getFileIoInstance() === null) {
677 // Invalid language instance
678 throw new MissingFileIoHandlerException($appInstance, self::EXCEPTION_MISSING_FILE_IO_HANDLER);
681 // Initialize the template engine
682 $templateInstance = ObjectFactory::createObjectByConfiguredName('template_class', array($appInstance));
684 // Return the prepared instance
685 return $templateInstance;
689 * Debugs this instance by putting out it's full content
691 * @param $message Optional message to show in debug output
694 public final function debugInstance ($message = '') {
695 // Restore the error handler to avoid trouble with missing array elements or undeclared variables
696 restore_error_handler();
702 if (!empty($message)) {
704 $content = sprintf("<div class=\"debug_message\">Message: %s</div>\n", $message);
707 // Generate the output
708 $content .= sprintf("<pre>%s</pre>",
717 ApplicationEntryPoint::app_die(sprintf("<div class=\"debug_header\">%s debug output:</div><div class=\"debug_content\">%s</div>\nLoaded includes: <div class=\"debug_include_list\">%s</div>",
720 ClassLoader::getInstance()->getPrintableIncludeList()
725 * Output a partial stub message for the caller method
727 * @param $message An optional message to display
730 protected function partialStub ($message = '') {
732 $backtrace = debug_backtrace();
734 // Generate the class::method string
735 $methodName = 'UnknownClass->unknownMethod';
736 if ((isset($backtrace[1]['class'])) && (isset($backtrace[1]['function']))) {
737 $methodName = $backtrace[1]['class']."->".$backtrace[1]['function'];
740 // Construct the full message
741 $stubMessage = sprintf("[%s:] Partial stub!",
745 // Is the extra message given?
746 if (!empty($message)) {
747 // Then add it as well
748 $stubMessage .= sprintf(" Message: <span id=\"stub_message\">%s</span>", $message);
751 // Debug instance is there?
752 if (!is_null($this->getDebugInstance())) {
753 // Output stub message
754 $this->debugOutput($stubMessage);
757 trigger_error($stubMessage."<br />\n");
762 * Outputs a debug backtrace and stops further script execution
766 public function debugBackTrace () {
767 // Sorry, there is no other way getting this nice backtrace
769 debug_print_backtrace();
775 * Outputs a debug message wether to debug instance (should be set!) or dies with or pints the message
777 * @param $message Message we shall send out...
778 * @param $doPrint Wether we shall print or die here which first is the default
781 public function debugOutput ($message, $doPrint = true) {
782 // Get debug instance
783 $debugInstance = $this->getDebugInstance();
785 // Is the debug instance there?
786 if (is_object($debugInstance)) {
787 // Use debug output handler
788 $debugInstance->output($message);
789 if ($doPrint === false) die(); // Die here if not printed
792 if ($doPrint === true) {
795 // DO NOT REWRITE THIS TO app_die() !!!
802 * Converts e.g. a command from URL to a valid class by keeping out bad characters
804 * @param $str The string, what ever it is needs to be converted
805 * @return $className Generated class name
807 public function convertToClassName ($str) {
811 // Convert all dashes in underscores
812 $str = $this->convertDashesToUnderscores($str);
814 // Now use that underscores to get classname parts for hungarian style
815 foreach (explode('_', $str) as $strPart) {
816 // Make the class name part lower case and first upper case
817 $className .= ucfirst(strtolower($strPart));
825 * Converts dashes to underscores, e.g. useable for configuration entries
827 * @param $str The string with maybe dashes inside
828 * @return $str The converted string with no dashed, but underscores
830 public final function convertDashesToUnderscores ($str) {
832 $str = str_replace('-', '_', $str);
834 // Return converted string
839 * Marks up the code by adding e.g. line numbers
841 * @param $phpCode Unmarked PHP code
842 * @return $markedCode Marked PHP code
844 public function markupCode ($phpCode) {
849 $errorArray = error_get_last();
851 // Init the code with error message
852 if (is_array($errorArray)) {
854 $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>",
855 basename($errorArray['file']),
857 $errorArray['message'],
862 // Add line number to the code
863 foreach (explode("\n", $phpCode) as $lineNo => $code) {
865 $markedCode .= sprintf("<span id=\"code_line\">%s</span>: %s\n",
867 htmlentities($code, ENT_QUOTES)
876 * Filter a given GMT timestamp (non Uni* stamp!) to make it look more
877 * beatiful for web-based front-ends. If null is given a message id
878 * null_timestamp will be resolved and returned.
880 * @param $timestamp Timestamp to prepare (filter) for display
881 * @return $readable A readable timestamp
883 public function doFilterFormatTimestamp ($timestamp) {
884 // Default value to return
887 // Is the timestamp null?
888 if (is_null($timestamp)) {
889 // Get a message string
890 $readable = $this->getLanguageInstance()->getMessage('null_timestamp');
892 switch ($this->getLanguageInstance()->getLanguageCode()) {
893 case 'de': // German format is a bit different to default
894 // Split the GMT stamp up
895 $dateTime = explode(' ', $timestamp );
896 $dateArray = explode('-', $dateTime[0]);
897 $timeArray = explode(':', $dateTime[1]);
899 // Construct the timestamp
900 $readable = sprintf($this->getConfigInstance()->getConfigEntry('german_date_time'),
910 default: // Default is pass-through
911 $readable = $timestamp;
921 * Filter a given number into a localized number
923 * @param $value The raw value from e.g. database
924 * @return $localized Localized value
926 public function doFilterFormatNumber ($value) {
927 // Generate it from config and localize depencies
928 switch ($this->getLanguageInstance()->getLanguageCode()) {
929 case 'de': // German format is a bit different to default
930 $localized = number_format($value, $this->getConfigInstance()->getConfigEntry('decimals'), ',', '.');
934 $localized = number_format($value, $this->getConfigInstance()->getConfigEntry('decimals'), '.', ',');
943 * "Getter" for databse entry
945 * @return $entry An array with database entries
946 * @throws NullPointerException If the database result is not found
947 * @throws InvalidDatabaseResultException If the database result is invalid
949 protected final function getDatabaseEntry () {
950 // Is there an instance?
951 if (is_null($this->getResultInstance())) {
952 // Throw an exception here
953 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
957 $this->getResultInstance()->rewind();
959 // Do we have an entry?
960 if ($this->getResultInstance()->valid() === false) {
961 throw new InvalidDatabaseResultException(array($this, $this->getResultInstance()), DatabaseResult::EXCEPTION_INVALID_DATABASE_RESULT);
965 $this->getResultInstance()->next();
968 $entry = $this->getResultInstance()->current();
975 * Getter for field name
977 * @param $fieldName Field name which we shall get
978 * @return $fieldValue Field value from the user
979 * @throws NullPointerException If the result instance is null
981 public final function getField ($fieldName) {
982 // Default field value
985 // Get result instance
986 $resultInstance = $this->getResultInstance();
988 // Is this instance null?
989 if (is_null($resultInstance)) {
990 // Then the user instance is no longer valid (expired cookies?)
991 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
995 $fieldArray = $resultInstance->current();
996 //* DEBUG: */ $this->debugOutput($fieldName.':<pre>'.print_r($fieldArray, true).'</pre>');
998 // Does the field exist?
999 if (isset($fieldArray[$fieldName])) {
1001 $fieldValue = $fieldArray[$fieldName];
1009 * Protected setter for user instance
1011 * @param $userInstance An instance of a user class
1014 protected final function setUserInstance (ManageableAccount $userInstance) {
1015 $this->userInstance = $userInstance;
1019 * Getter for user instance
1021 * @return $userInstance An instance of a user class
1023 public final function getUserInstance () {
1024 return $this->userInstance;
1028 * Setter for controller instance (this surely breaks a bit the MVC patterm)
1030 * @param $controllerInstance An instance of the controller
1033 public final function setControllerInstance (Controller $controllerInstance) {
1034 $this->controllerInstance = $controllerInstance;
1038 * Getter for controller instance (this surely breaks a bit the MVC patterm)
1040 * @return $controllerInstance An instance of the controller
1042 public final function getControllerInstance () {
1043 return $this->controllerInstance;
1047 * Flushs all pending updates to the database layer
1051 public function flushPendingUpdates () {
1052 // Get result instance
1053 $resultInstance = $this->getResultInstance();
1055 // Do we have data to update?
1056 if ((is_object($resultInstance)) && ($resultInstance->ifDataNeedsFlush())) {
1057 // Get wrapper class name config entry
1058 $configEntry = $resultInstance->getUpdateInstance()->getWrapperConfigEntry();
1060 // Create object instance
1061 $wrapperInstance = ObjectFactory::createObjectByConfiguredName($configEntry);
1063 // Yes, then send the whole result to the database layer
1064 $wrapperInstance->doUpdateByResult($this->getResultInstance());
1069 * Outputs a deprecation warning to the developer.
1071 * @param $message The message we shall output to the developer
1073 * @todo Write a logging mechanism for productive mode
1075 public function deprecationWarning ($message) {
1076 // Is developer mode active?
1077 if (defined('DEVELOPER')) {
1078 // Debug instance is there?
1079 if (!is_null($this->getDebugInstance())) {
1080 // Output stub message
1081 $this->debugOutput($message);
1084 trigger_error($message."<br />\n");
1087 // @TODO Finish this part!
1088 $this->partialStub('Developer mode inactive. Message:' . $message);
1093 * Generates a generic hash code of this class. You should really overwrite
1094 * this method with your own hash code generator code. But keep KISS in mind.
1096 * @return $hashCode A generic hash code respresenting this whole class
1098 public function hashCode () {
1100 return crc32($this->__toString());
1104 * Checks wether the given PHP extension is loaded
1106 * @param $phpExtension The PHP extension we shall check
1107 * @return $isLoaded Wether the PHP extension is loaded
1109 public final function isPhpExtensionLoaded ($phpExtension) {
1111 $isLoaded = in_array($phpExtension, get_loaded_extensions());
1118 * Setter for RNG instance
1120 * @param $rngInstance An instance of a random number generator (RNG)
1123 protected final function setRngInstance (RandomNumberGenerator $rngInstance) {
1124 $this->rngInstance = $rngInstance;
1128 * Getter for RNG instance
1130 * @return $rngInstance An instance of a random number generator (RNG)
1132 public final function getRngInstance () {
1133 return $this->rngInstance;
1137 * Setter for Iterator instance
1139 * @param $iteratorInstance An instance of an Iterator
1142 protected final function setIteratorInstance (Iterator $iteratorInstance) {
1143 $this->iteratorInstance = $iteratorInstance;
1147 * Getter for Iterator instance
1149 * @return $iteratorInstance An instance of an Iterator
1151 public final function getIteratorInstance () {
1152 return $this->iteratorInstance;
1156 * "Getter" as a time() replacement but with milliseconds. You should use this
1157 * method instead of the encapsulated getimeofday() function.
1159 * @return $milliTime Timestamp with milliseconds
1161 public function getMilliTime () {
1162 // Get the time of day as float
1163 $milliTime = gettimeofday(true);
1170 * Idles (sleeps) for given milliseconds
1172 * @return $hasSlept Wether it goes fine
1174 public function idle ($milliSeconds) {
1175 // Sleep is fine by default
1178 // Idle so long with found function
1179 if (function_exists('time_sleep_until')) {
1180 // Get current time and add idle time
1181 $sleepUntil = $this->getMilliTime() + abs($milliSeconds) / 1000;
1183 // New PHP 5.1.0 function found
1184 $hasSlept = time_sleep_until($sleepUntil);
1186 // My Sun Station doesn't have that function even with latest PHP
1188 usleep($milliSeconds * 1000);
1196 * Setter for the list instance
1198 * @param $listInstance A list of Listable
1201 protected final function setListInstance (Listable $listInstance) {
1202 $this->listInstance = $listInstance;
1206 * Getter for the list instance
1208 * @return $listInstance A list of Listable
1210 protected final function getListInstance () {
1211 return $this->listInstance;
1215 * Setter for the menu instance
1217 * @param $menuInstance A RenderableMenu instance
1220 protected final function setMenuInstance (RenderableMenu $menuInstance) {
1221 $this->menuInstance = $menuInstance;
1225 * Getter for the menu instance
1227 * @return $menuInstance A RenderableMenu instance
1229 protected final function getMenuInstance () {
1230 return $this->menuInstance;