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;
89 private $realClass = 'BaseFrameworkSystem';
94 private $thousands = '.'; // German
99 private $decimals = ','; // German
101 /***********************
102 * Exception codes.... *
103 ***********************/
104 // @todo Try to clean these constants up
105 const EXCEPTION_IS_NULL_POINTER = 0x001;
106 const EXCEPTION_IS_NO_OBJECT = 0x002;
107 const EXCEPTION_IS_NO_ARRAY = 0x003;
108 const EXCEPTION_MISSING_METHOD = 0x004;
109 const EXCEPTION_CLASSES_NOT_MATCHING = 0x005;
110 const EXCEPTION_INDEX_OUT_OF_BOUNDS = 0x006;
111 const EXCEPTION_DIMENSION_ARRAY_INVALID = 0x007;
112 const EXCEPTION_ITEM_NOT_TRADEABLE = 0x008;
113 const EXCEPTION_ITEM_NOT_IN_PRICE_LIST = 0x009;
114 const EXCEPTION_GENDER_IS_WRONG = 0x00a;
115 const EXCEPTION_BIRTH_DATE_IS_INVALID = 0x00b;
116 const EXCEPTION_EMPTY_STRUCTURES_ARRAY = 0x00c;
117 const EXCEPTION_HAS_ALREADY_PERSONELL_LIST = 0x00d;
118 const EXCEPTION_NOT_ENOUGTH_UNEMPLOYEES = 0x00e;
119 const EXCEPTION_TOTAL_PRICE_NOT_CALCULATED = 0x00f;
120 const EXCEPTION_HARBOR_HAS_NO_SHIPYARDS = 0x010;
121 const EXCEPTION_CONTRACT_PARTNER_INVALID = 0x011;
122 const EXCEPTION_CONTRACT_PARTNER_MISMATCH = 0x012;
123 const EXCEPTION_CONTRACT_ALREADY_SIGNED = 0x013;
124 const EXCEPTION_UNEXPECTED_EMPTY_STRING = 0x014;
125 const EXCEPTION_PATH_NOT_FOUND = 0x015;
126 const EXCEPTION_INVALID_PATH_NAME = 0x016;
127 const EXCEPTION_READ_PROTECED_PATH = 0x017;
128 const EXCEPTION_WRITE_PROTECED_PATH = 0x018;
129 const EXCEPTION_DIR_POINTER_INVALID = 0x019;
130 const EXCEPTION_FILE_POINTER_INVALID = 0x01a;
131 const EXCEPTION_INVALID_RESOURCE = 0x01b;
132 const EXCEPTION_UNEXPECTED_OBJECT = 0x01c;
133 const EXCEPTION_LIMIT_ELEMENT_IS_UNSUPPORTED = 0x01d;
134 const EXCEPTION_GETTER_IS_MISSING = 0x01e;
135 const EXCEPTION_ARRAY_EXPECTED = 0x01f;
136 const EXCEPTION_ARRAY_HAS_INVALID_COUNT = 0x020;
137 const EXCEPTION_ID_IS_INVALID_FORMAT = 0x021;
138 const EXCEPTION_MD5_CHECKSUMS_MISMATCH = 0x022;
139 const EXCEPTION_UNEXPECTED_STRING_SIZE = 0x023;
140 const EXCEPTION_SIMULATOR_ID_INVALID = 0x024;
141 const EXCEPTION_MISMATCHING_COMPRESSORS = 0x025;
142 const EXCEPTION_CONTAINER_ITEM_IS_NULL = 0x026;
143 const EXCEPTION_ITEM_IS_NO_ARRAY = 0x027;
144 const EXCEPTION_CONTAINER_MAYBE_DAMAGED = 0x028;
145 const EXCEPTION_INVALID_STRING = 0x029;
146 const EXCEPTION_VARIABLE_NOT_SET = 0x02a;
147 const EXCEPTION_ATTRIBUTES_ARE_MISSING = 0x02b;
148 const EXCEPTION_ARRAY_ELEMENTS_MISSING = 0x02c;
149 const EXCEPTION_TEMPLATE_ENGINE_UNSUPPORTED = 0x02d;
150 const EXCEPTION_MISSING_LANGUAGE_HANDLER = 0x02e;
151 const EXCEPTION_MISSING_FILE_IO_HANDLER = 0x02f;
152 const EXCEPTION_MISSING_ELEMENT = 0x030;
153 const EXCEPTION_HEADERS_ALREADY_SENT = 0x031;
154 const EXCEPTION_DEFAULT_CONTROLLER_GONE = 0x032;
155 const EXCEPTION_CLASS_NOT_FOUND = 0x033;
156 const EXCEPTION_REQUIRED_INTERFACE_MISSING = 0x034;
157 const EXCEPTION_FATAL_ERROR = 0x035;
158 const EXCEPTION_FILE_NOT_FOUND = 0x036;
159 const EXCEPTION_ASSERTION_FAILED = 0x037;
160 const EXCEPTION_FILE_CANNOT_BE_READ = 0x038;
161 const EXCEPTION_DATABASE_UPDATED_NOT_ALLOWED = 0x039;
162 const EXCEPTION_FILTER_CHAIN_INTERCEPTED = 0x040;
165 * Protected super constructor
167 * @param $className Name of the class
170 protected function __construct ($className) {
172 $this->setRealClass($className);
174 // Set configuration instance if no registry
175 if (!$this instanceof Register) {
176 // Because registries doesn't need to be configured
177 $this->setConfigInstance(FrameworkConfiguration::getInstance());
182 * Destructor reached...
185 * @todo This is old code. Do we still need this old lost code?
187 public function __destruct() {
188 // Flush any updated entries to the database
189 $this->flushPendingUpdates();
191 // Is this object already destroyed?
192 if ($this->__toString() != 'DestructedObject') {
193 // Destroy all informations about this class but keep some text about it alive
194 $this->setRealClass('DestructedObject');
195 } elseif ((defined('DEBUG_DESTRUCTOR')) && (is_object($this->getDebugInstance()))) {
196 // Already destructed object
197 $this->debugOutput(sprintf("[%s:] The object <span class=\"object_name\">%s</span> is already destroyed.",
205 * The call method where all non-implemented methods end up
209 public final function __call ($methodName, $args) {
210 // Implode all given arguments
214 $argsString = 'NULL';
215 } elseif (is_array($args)) {
216 // Some arguments are there
217 foreach ($args as $arg) {
219 $argsString .= $arg . ' (' . gettype($arg);
221 // Add length if type is string
222 if (gettype($arg) == 'string') $argsString .= ', '.strlen($arg);
225 $argsString .= '), ';
229 if (substr($argsString, -2, 1) == ',') {
230 $argsString = substr($argsString, 0, -2);
233 // Invalid arguments!
234 $argsString = '!INVALID:' . gettype($args) . '!';
237 // Output stub message
238 $this->debugOutput(sprintf("[%s->%s] Stub! Args: %s",
249 * Setter for database result instance
251 * @param $resultInstance An instance of a database result class
253 * @todo SearchableResult and UpdateableResult shall have a super interface to use here
255 protected final function setResultInstance (SearchableResult $resultInstance) {
256 $this->resultInstance = $resultInstance;
260 * Getter for database result instance
262 * @return $resultInstance An instance of a database result class
264 public final function getResultInstance () {
265 return $this->resultInstance;
269 * Setter for template engine instances
271 * @param $templateInstance An instance of a template engine class
274 protected final function setTemplateInstance (CompileableTemplate $templateInstance) {
275 $this->templateInstance = $templateInstance;
279 * Getter for template engine instances
281 * @return $templateInstance An instance of a template engine class
283 protected final function getTemplateInstance () {
284 return $this->templateInstance;
288 * Setter for search instance
290 * @param $searchInstance Searchable criteria instance
293 public final function setSearchInstance (LocalSearchCriteria $searchInstance) {
294 $this->searchInstance = $searchInstance;
298 * Getter for search instance
300 * @return $searchInstance Searchable criteria instance
302 public final function getSearchInstance () {
303 return $this->searchInstance;
307 * Setter for update instance
309 * @param $updateInstance Searchable criteria instance
312 public final function setUpdateInstance (LocalUpdateCriteria $updateInstance) {
313 $this->updateInstance = $updateInstance;
317 * Getter for update instance
319 * @return $updateInstance Updateable criteria instance
321 public final function getUpdateInstance () {
322 return $this->updateInstance;
326 * Setter for resolver instance
328 * @param $resolverInstance Instance of a command resolver class
331 public final function setResolverInstance (Resolver $resolverInstance) {
332 $this->resolverInstance = $resolverInstance;
336 * Getter for resolver instance
338 * @return $resolverInstance Instance of a command resolver class
340 public final function getResolverInstance () {
341 return $this->resolverInstance;
345 * Setter for language instance
347 * @param $configInstance The configuration instance which shall
348 * be FrameworkConfiguration
351 public final function setConfigInstance (FrameworkConfiguration $configInstance) {
352 Registry::getRegistry()->addInstance('config', $configInstance);
356 * Getter for configuration instance
358 * @return $configInstance Configuration instance
360 public final function getConfigInstance () {
361 $configInstance = Registry::getRegistry()->getInstance('config');
362 return $configInstance;
366 * Setter for debug instance
368 * @param $debugInstance The instance for debug output class
371 public final function setDebugInstance (DebugMiddleware $debugInstance) {
372 Registry::getRegistry()->addInstance('debug', $debugInstance);
376 * Getter for debug instance
378 * @return $debugInstance Instance to class DebugConsoleOutput or DebugWebOutput
380 public final function getDebugInstance () {
381 // Get debug instance
382 $debugInstance = Registry::getRegistry()->getInstance('debug');
385 return $debugInstance;
389 * Setter for web output instance
391 * @param $webInstance The instance for web output class
394 public final function setWebOutputInstance (OutputStreamer $webInstance) {
395 Registry::getRegistry()->addInstance('web_output', $webInstance);
399 * Getter for web output instance
401 * @return $webOutputInstance - Instance to class WebOutput
403 public final function getWebOutputInstance () {
404 $webOutputInstance = Registry::getRegistry()->getInstance('web_output');
405 return $webOutputInstance;
409 * Setter for database instance
411 * @param $dbInstance The instance for the database connection
412 * (forced DatabaseConnection)
415 public final function setDatabaseInstance (DatabaseConnection $dbInstance) {
416 Registry::getRegistry()->addInstance('db_instance', $dbInstance);
420 * Getter for database layer
422 * @return $dbInstance The database layer instance
424 public final function getDatabaseInstance () {
426 $dbInstance = Registry::getRegistry()->getInstance('db_instance');
433 * Setter for compressor channel
435 * @param $compressorInstance An instance of CompressorChannel
438 public final function setCompressorChannel (CompressorChannel $compressorInstance) {
439 Registry::getRegistry()->addInstance('compressor', $compressorInstance);
443 * Getter for compressor channel
445 * @return $compressorInstance The compressor channel
447 public final function getCompressorChannel () {
448 $compressorInstance = Registry::getRegistry()->getInstance('compressor');
449 return $compressorInstance;
453 * Protected getter for a manageable application helper class
455 * @return $applicationInstance An instance of a manageable application helper class
457 protected final function getApplicationInstance () {
458 $applicationInstance = Registry::getRegistry()->getInstance('application');
459 return $applicationInstance;
463 * Setter for a manageable application helper class
465 * @param $applicationInstance An instance of a manageable application helper class
468 public final function setApplicationInstance (ManageableApplication $applicationInstance) {
469 Registry::getRegistry()->addInstance('application', $applicationInstance);
473 * Setter for request instance
475 * @param $requestInstance An instance of a Requestable class
478 public final function setRequestInstance (Requestable $requestInstance) {
479 $this->requestInstance = $requestInstance;
483 * Getter for request instance
485 * @return $requestInstance An instance of a Requestable class
487 public final function getRequestInstance () {
488 return $this->requestInstance;
492 * Setter for response instance
494 * @param $responseInstance An instance of a Responseable class
497 public final function setResponseInstance (Responseable $responseInstance) {
498 $this->responseInstance = $responseInstance;
502 * Getter for response instance
504 * @return $responseInstance An instance of a Responseable class
506 public final function getResponseInstance () {
507 return $this->responseInstance;
511 * Getter for $realClass
513 * @return $realClass The name of the real class (not BaseFrameworkSystem)
515 public final function __toString () {
516 return $this->realClass;
520 * Setter for the real class name
522 * @param $realClass Class name (string)
525 public final function setRealClass ($realClass) {
527 $realClass = (string) $realClass;
530 $this->realClass = $realClass;
534 * Checks wether an object equals this object. You should overwrite this
535 * method to implement own equality checks
537 * @param $objectInstance An instance of a FrameworkInterface object
538 * @return $equals Wether both objects equals
540 public function equals (FrameworkInterface $objectInstance) {
543 $this->__toString() == $objectInstance->__toString()
545 $this->hashCode() == $objectInstance->hashCode()
553 * Formats computer generated price values into human-understandable formats
554 * with thousand and decimal seperators.
556 * @param $value The in computer format value for a price
557 * @param $currency The currency symbol (use HTML-valid characters!)
558 * @param $decNum Number of decimals after commata
559 * @return $price The for the current language formated price string
560 * @throws MissingDecimalsThousandsSeperatorException If decimals or
561 * thousands seperator
564 public function formatCurrency ($value, $currency = '€', $decNum = 2) {
565 // Are all required attriutes set?
566 if ((!isset($this->decimals)) || (!isset($this->thousands))) {
567 // Throw an exception
568 throw new MissingDecimalsThousandsSeperatorException($this, self::EXCEPTION_ATTRIBUTES_ARE_MISSING);
572 $value = (float) $value;
574 // Reformat the US number
575 $price = number_format($value, $decNum, $this->decimals, $this->thousands) . $currency;
577 // Return as string...
582 * Private getter for language instance
584 * @return $langInstance An instance to the language sub-system
586 protected final function getLanguageInstance () {
587 $langInstance = Registry::getRegistry()->getInstance('language');
588 return $langInstance;
592 * Setter for language instance
594 * @param $langInstance An instance to the language sub-system
596 * @see LanguageSystem
598 public final function setLanguageInstance (ManageableLanguage $langInstance) {
599 Registry::getRegistry()->addInstance('language', $langInstance);
603 * Appends a trailing slash to a string
605 * @param $str A string (maybe) without trailing slash
606 * @return $str A string with an auto-appended trailing slash
608 public final function addMissingTrailingSlash ($str) {
609 // Is there a trailing slash?
610 if (substr($str, -1, 1) != '/') $str .= '/';
615 * Private getter for file IO instance
617 * @return $fileIoInstance An instance to the file I/O sub-system
619 protected final function getFileIoInstance () {
620 return $this->fileIoInstance;
624 * Setter for file I/O instance
626 * @param $fileIoInstance An instance to the file I/O sub-system
629 public final function setFileIoInstance (FileIoHandler $fileIoInstance) {
630 $this->fileIoInstance = $fileIoInstance;
634 * Prepare the template engine (WebTemplateEngine by default) for a given
635 * application helper instance (ApplicationHelper by default).
637 * @param $appInstance An application helper instance or
638 * null if we shall use the default
639 * @return $templateInstance The template engine instance
640 * @throws NullPointerException If the template engine could not
642 * @throws UnsupportedTemplateEngineException If $templateInstance is an
643 * unsupported template engine
644 * @throws MissingLanguageHandlerException If the language sub-system
645 * is not yet initialized
646 * @throws NullPointerException If the discovered application
647 * instance is still null
649 protected function prepareTemplateInstance (FrameworkInterface $appInstance=null) {
650 // Is the application instance set?
651 if (is_null($appInstance)) {
652 // Get the current instance
653 $appInstance = $this->getApplicationInstance();
656 if (is_null($appInstance)) {
657 // Thrown an exception
658 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
662 // Are both instances set?
663 if ($appInstance->getLanguageInstance() === null) {
664 // Invalid language instance
665 throw new MissingLanguageHandlerException($appInstance, self::EXCEPTION_MISSING_LANGUAGE_HANDLER);
666 } elseif ($appInstance->getFileIoInstance() === null) {
667 // Invalid language instance
668 throw new MissingFileIoHandlerException($appInstance, self::EXCEPTION_MISSING_FILE_IO_HANDLER);
671 // Initialize the template engine
672 $templateInstance = ObjectFactory::createObjectByConfiguredName('template_class', array($appInstance));
674 // Return the prepared instance
675 return $templateInstance;
679 * Debugs this instance by putting out it's full content
681 * @param $message Optional message to show in debug output
684 public final function debugInstance ($message = '') {
685 // Restore the error handler to avoid trouble with missing array elements or undeclared variables
686 restore_error_handler();
692 if (!empty($message)) {
694 $content = sprintf("<div class=\"debug_message\">Message: %s</div>\n", $message);
697 // Generate the output
698 $content .= sprintf("<pre>%s</pre>",
707 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>",
710 ClassLoader::getInstance()->getPrintableIncludeList()
715 * Output a partial stub message for the caller method
717 * @param $message An optional message to display
720 protected function partialStub ($message = '') {
722 $backtrace = debug_backtrace();
724 // Generate the class::method string
725 $methodName = 'UnknownClass->unknownMethod';
726 if ((isset($backtrace[1]['class'])) && (isset($backtrace[1]['function']))) {
727 $methodName = $backtrace[1]['class']."->".$backtrace[1]['function'];
730 // Construct the full message
731 $stubMessage = sprintf("[%s:] Partial stub!",
735 // Is the extra message given?
736 if (!empty($message)) {
737 // Then add it as well
738 $stubMessage .= sprintf(" Message: <span id=\"stub_message\">%s</span>", $message);
741 // Debug instance is there?
742 if (!is_null($this->getDebugInstance())) {
743 // Output stub message
744 $this->debugOutput($stubMessage);
747 trigger_error($stubMessage."<br />\n");
752 * Outputs a debug backtrace and stops further script execution
756 public function debugBackTrace () {
757 // Sorry, there is no other way getting this nice backtrace
759 debug_print_backtrace();
765 * Outputs a debug message wether to debug instance (should be set!) or dies with or pints the message
767 * @param $message Message we shall send out...
768 * @param $doPrint Wether we shall print or die here which first is the default
771 public function debugOutput ($message, $doPrint = true) {
772 // Get debug instance
773 $debugInstance = $this->getDebugInstance();
775 // Is the debug instance there?
776 if (is_object($debugInstance)) {
777 // Use debug output handler
778 $debugInstance->output($message);
779 if ($doPrint === false) die(); // Die here if not printed
782 if ($doPrint === true) {
785 // DO NOT REWRITE THIS TO app_die() !!!
792 * Converts e.g. a command from URL to a valid class by keeping out bad characters
794 * @param $str The string, what ever it is needs to be converted
795 * @return $className Generated class name
797 public function convertToClassName ($str) {
801 // Convert all dashes in underscores
802 $str = $this->convertDashesToUnderscores($str);
804 // Now use that underscores to get classname parts for hungarian style
805 foreach (explode('_', $str) as $strPart) {
806 // Make the class name part lower case and first upper case
807 $className .= ucfirst(strtolower($strPart));
815 * Converts dashes to underscores, e.g. useable for configuration entries
817 * @param $str The string with maybe dashes inside
818 * @return $str The converted string with no dashed, but underscores
820 public final function convertDashesToUnderscores ($str) {
822 $str = str_replace('-', '_', $str);
824 // Return converted string
829 * Marks up the code by adding e.g. line numbers
831 * @param $phpCode Unmarked PHP code
832 * @return $markedCode Marked PHP code
834 public function markupCode ($phpCode) {
839 $errorArray = error_get_last();
841 // Init the code with error message
842 if (is_array($errorArray)) {
844 $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>",
845 basename($errorArray['file']),
847 $errorArray['message'],
852 // Add line number to the code
853 foreach (explode("\n", $phpCode) as $lineNo => $code) {
855 $markedCode .= sprintf("<span id=\"code_line\">%s</span>: %s\n",
857 htmlentities($code, ENT_QUOTES)
866 * Filter a given GMT timestamp (non Uni* stamp!) to make it look more
867 * beatiful for web-based front-ends. If null is given a message id
868 * null_timestamp will be resolved and returned.
870 * @param $timestamp Timestamp to prepare (filter) for display
871 * @return $readable A readable timestamp
873 public function doFilterFormatTimestamp ($timestamp) {
874 // Default value to return
877 // Is the timestamp null?
878 if (is_null($timestamp)) {
879 // Get a message string
880 $readable = $this->getLanguageInstance()->getMessage('null_timestamp');
882 switch ($this->getLanguageInstance()->getLanguageCode()) {
883 case "de": // German format is a bit different to default
884 // Split the GMT stamp up
885 $dateTime = explode(' ', $timestamp );
886 $dateArray = explode('-', $dateTime[0]);
887 $timeArray = explode(':', $dateTime[1]);
889 // Construct the timestamp
890 $readable = sprintf($this->getConfigInstance()->getConfigEntry('german_date_time'),
900 default: // Default is pass-through
901 $readable = $timestamp;
911 * "Getter" for databse entry
913 * @return $entry An array with database entries
914 * @throws NullPointerException If the database result is not found
915 * @throws InvalidDatabaseResultException If the database result is invalid
917 protected final function getDatabaseEntry () {
918 // Is there an instance?
919 if (is_null($this->getResultInstance())) {
920 // Throw an exception here
921 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
925 $this->getResultInstance()->rewind();
927 // Do we have an entry?
928 if ($this->getResultInstance()->valid() === false) {
929 throw new InvalidDatabaseResultException(array($this, $this->getResultInstance()), DatabaseResult::EXCEPTION_INVALID_DATABASE_RESULT);
933 $this->getResultInstance()->next();
936 $entry = $this->getResultInstance()->current();
943 * Getter for field name
945 * @param $fieldName Field name which we shall get
946 * @return $fieldValue Field value from the user
947 * @throws NullPointerException If the result instance is null
949 public final function getField ($fieldName) {
950 // Default field value
953 // Get result instance
954 $resultInstance = $this->getResultInstance();
956 // Is this instance null?
957 if (is_null($resultInstance)) {
958 // Then the user instance is no longer valid (expired cookies?)
959 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
963 $fieldArray = $resultInstance->current();
965 // Does the field exist?
966 if (isset($fieldArray[$fieldName])) {
968 $fieldValue = $fieldArray[$fieldName];
976 * Protected setter for user instance
978 * @param $userInstance An instance of a user class
981 protected final function setUserInstance (ManageableAccount $userInstance) {
982 $this->userInstance = $userInstance;
986 * Getter for user instance
988 * @return $userInstance An instance of a user class
990 public final function getUserInstance () {
991 return $this->userInstance;
995 * Setter for controller instance (this surely breaks a bit the MVC patterm)
997 * @param $controllerInstance An instance of the controller
1000 public final function setControllerInstance (Controller $controllerInstance) {
1001 $this->controllerInstance = $controllerInstance;
1005 * Getter for controller instance (this surely breaks a bit the MVC patterm)
1007 * @return $controllerInstance An instance of the controller
1009 public final function getControllerInstance () {
1010 return $this->controllerInstance;
1014 * Flushs all pending updates to the database layer
1018 public function flushPendingUpdates () {
1019 // Get result instance
1020 $resultInstance = $this->getResultInstance();
1022 // Do we have data to update?
1023 if ((is_object($resultInstance)) && ($resultInstance->ifDataNeedsFlush())) {
1024 // Get wrapper class name config entry
1025 $configEntry = $resultInstance->getUpdateInstance()->getWrapperConfigEntry();
1027 // Create object instance
1028 $wrapperInstance = ObjectFactory::createObjectByConfiguredName($configEntry);
1030 // Yes, then send the whole result to the database layer
1031 $wrapperInstance->doUpdateByResult($this->getResultInstance());
1036 * Outputs a deprecation warning to the developer.
1038 * @param $message The message we shall output to the developer
1040 * @todo Write a logging mechanism for productive mode
1042 public function deprecationWarning ($message) {
1043 // Is developer mode active?
1044 if (defined('DEVELOPER')) {
1045 // Debug instance is there?
1046 if (!is_null($this->getDebugInstance())) {
1047 // Output stub message
1048 $this->debugOutput($message);
1051 trigger_error($message."<br />\n");
1054 // @TODO Finish this part!
1055 $this->partialStub('Developer mode inactive. Message:' . $message);
1060 * Generates a generic hash code of this class. You should really overwrite
1061 * this method with your own hash code generator code. But keep KISS in mind.
1063 * @return $hashCode A generic hash code respresenting this whole class
1065 public function hashCode () {
1067 return crc32($this->__toString());
1071 * Checks wether the given PHP extension is loaded
1073 * @param $phpExtension The PHP extension we shall check
1074 * @return $isLoaded Wether the PHP extension is loaded
1076 public final function isPhpExtensionLoaded ($phpExtension) {
1078 $isLoaded = in_array($phpExtension, get_loaded_extensions());
1085 * Setter for RNG instance
1087 * @param $rngInstance An instance of a random number generator (RNG)
1090 protected final function setRngInstance (RandomNumberGenerator $rngInstance) {
1091 $this->rngInstance = $rngInstance;
1095 * Getter for RNG instance
1097 * @return $rngInstance An instance of a random number generator (RNG)
1099 public final function getRngInstance () {
1100 return $this->rngInstance;
1104 * Setter for Iterator instance
1106 * @param $iteratorInstance An instance of an Iterator
1109 protected final function setIteratorInstance (Iterator $iteratorInstance) {
1110 $this->iteratorInstance = $iteratorInstance;
1114 * Getter for Iterator instance
1116 * @return $iteratorInstance An instance of an Iterator
1118 public final function getIteratorInstance () {
1119 return $this->iteratorInstance;
1123 * "Getter" as a time() replacement but with milliseconds. You should use this
1124 * method instead of the encapsulated getimeofday() function.
1126 * @return $milliTime Timestamp with milliseconds
1128 public function getMilliTime () {
1129 // Get the time of day as float
1130 $milliTime = gettimeofday(true);
1137 * Idles (sleeps) for given milliseconds
1139 * @return $hasSlept Wether it goes fine
1141 public function idle ($milliSeconds) {
1142 // Sleep is fine by default
1145 // Idle so long with found function
1146 if (function_exists('time_sleep_until')) {
1147 // Get current time and add idle time
1148 $sleepUntil = $this->getMilliTime() + $milliSeconds / 1000;
1150 // New PHP 5.1.0 function found
1151 $hasSlept = time_sleep_until($sleepUntil);
1153 // My Sun Station doesn't have that function even with latest PHP
1155 usleep($milliSeconds * 1000);