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 - 2011 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;
97 * Instance of the image
99 private $imageInstance = null;
102 * Instance of the stacker
104 private $stackerInstance = null;
107 * A Compressor instance
109 private $compressorInstance = null;
112 * A Parseable instance
114 private $parserInstance = null;
117 * A ProtocolHandler instance
119 private $protocolInstance = null;
122 * A database wrapper instance
124 private $databaseInstance = null;
127 * The real class name
129 private $realClass = 'BaseFrameworkSystem';
132 * Thousands seperator
134 private $thousands = '.'; // German
139 private $decimals = ','; // German
144 private $socketResource = false;
149 private $packageData = array();
151 /***********************
152 * Exception codes.... *
153 ***********************/
154 // @todo Try to clean these constants up
155 const EXCEPTION_IS_NULL_POINTER = 0x001;
156 const EXCEPTION_IS_NO_OBJECT = 0x002;
157 const EXCEPTION_IS_NO_ARRAY = 0x003;
158 const EXCEPTION_MISSING_METHOD = 0x004;
159 const EXCEPTION_CLASSES_NOT_MATCHING = 0x005;
160 const EXCEPTION_INDEX_OUT_OF_BOUNDS = 0x006;
161 const EXCEPTION_DIMENSION_ARRAY_INVALID = 0x007;
162 const EXCEPTION_ITEM_NOT_TRADEABLE = 0x008;
163 const EXCEPTION_ITEM_NOT_IN_PRICE_LIST = 0x009;
164 const EXCEPTION_GENDER_IS_WRONG = 0x00a;
165 const EXCEPTION_BIRTH_DATE_IS_INVALID = 0x00b;
166 const EXCEPTION_EMPTY_STRUCTURES_ARRAY = 0x00c;
167 const EXCEPTION_HAS_ALREADY_PERSONELL_LIST = 0x00d;
168 const EXCEPTION_NOT_ENOUGTH_UNEMPLOYEES = 0x00e;
169 const EXCEPTION_TOTAL_PRICE_NOT_CALCULATED = 0x00f;
170 const EXCEPTION_HARBOR_HAS_NO_SHIPYARDS = 0x010;
171 const EXCEPTION_CONTRACT_PARTNER_INVALID = 0x011;
172 const EXCEPTION_CONTRACT_PARTNER_MISMATCH = 0x012;
173 const EXCEPTION_CONTRACT_ALREADY_SIGNED = 0x013;
174 const EXCEPTION_UNEXPECTED_EMPTY_STRING = 0x014;
175 const EXCEPTION_PATH_NOT_FOUND = 0x015;
176 const EXCEPTION_INVALID_PATH_NAME = 0x016;
177 const EXCEPTION_READ_PROTECED_PATH = 0x017;
178 const EXCEPTION_WRITE_PROTECED_PATH = 0x018;
179 const EXCEPTION_DIR_POINTER_INVALID = 0x019;
180 const EXCEPTION_FILE_POINTER_INVALID = 0x01a;
181 const EXCEPTION_INVALID_RESOURCE = 0x01b;
182 const EXCEPTION_UNEXPECTED_OBJECT = 0x01c;
183 const EXCEPTION_LIMIT_ELEMENT_IS_UNSUPPORTED = 0x01d;
184 const EXCEPTION_GETTER_IS_MISSING = 0x01e;
185 const EXCEPTION_ARRAY_EXPECTED = 0x01f;
186 const EXCEPTION_ARRAY_HAS_INVALID_COUNT = 0x020;
187 const EXCEPTION_ID_IS_INVALID_FORMAT = 0x021;
188 const EXCEPTION_MD5_CHECKSUMS_MISMATCH = 0x022;
189 const EXCEPTION_UNEXPECTED_STRING_SIZE = 0x023;
190 const EXCEPTION_SIMULATOR_ID_INVALID = 0x024;
191 const EXCEPTION_MISMATCHING_COMPRESSORS = 0x025;
192 const EXCEPTION_CONTAINER_ITEM_IS_NULL = 0x026;
193 const EXCEPTION_ITEM_IS_NO_ARRAY = 0x027;
194 const EXCEPTION_CONTAINER_MAYBE_DAMAGED = 0x028;
195 const EXCEPTION_INVALID_STRING = 0x029;
196 const EXCEPTION_VARIABLE_NOT_SET = 0x02a;
197 const EXCEPTION_ATTRIBUTES_ARE_MISSING = 0x02b;
198 const EXCEPTION_ARRAY_ELEMENTS_MISSING = 0x02c;
199 const EXCEPTION_TEMPLATE_ENGINE_UNSUPPORTED = 0x02d;
200 const EXCEPTION_MISSING_ELEMENT = 0x030;
201 const EXCEPTION_HEADERS_ALREADY_SENT = 0x031;
202 const EXCEPTION_DEFAULT_CONTROLLER_GONE = 0x032;
203 const EXCEPTION_CLASS_NOT_FOUND = 0x033;
204 const EXCEPTION_REQUIRED_INTERFACE_MISSING = 0x034;
205 const EXCEPTION_FATAL_ERROR = 0x035;
206 const EXCEPTION_FILE_NOT_FOUND = 0x036;
207 const EXCEPTION_ASSERTION_FAILED = 0x037;
208 const EXCEPTION_FILE_CANNOT_BE_READ = 0x038;
209 const EXCEPTION_DATABASE_UPDATED_NOT_ALLOWED = 0x039;
210 const EXCEPTION_FILTER_CHAIN_INTERCEPTED = 0x040;
213 * Protected super constructor
215 * @param $className Name of the class
218 protected function __construct ($className) {
220 $this->setRealClass($className);
222 // Set configuration instance if no registry
223 if (!$this instanceof Register) {
224 // Because registries doesn't need to be configured
225 $this->setConfigInstance(FrameworkConfiguration::getInstance());
230 * Destructor reached...
233 * @todo This is old code. Do we still need this old lost code?
235 public function __destruct() {
236 // Flush any updated entries to the database
237 $this->flushPendingUpdates();
239 // Is this object already destroyed?
240 if ($this->__toString() != 'DestructedObject') {
241 // Destroy all informations about this class but keep some text about it alive
242 $this->setRealClass('DestructedObject');
243 } elseif ((defined('DEBUG_DESTRUCTOR')) && (is_object($this->getDebugInstance()))) {
244 // Already destructed object
245 $this->debugOutput(sprintf("[%s:] The object <span class=\"object_name\">%s</span> is already destroyed.",
253 * The call method where all non-implemented methods end up
257 public final function __call ($methodName, $args) {
258 // Implode all given arguments
262 $argsString = 'NULL';
263 } elseif (is_array($args)) {
264 // Some arguments are there
265 foreach ($args as $arg) {
267 $argsString .= $this->replaceControlCharacters($arg) . ' (' . gettype($arg);
269 // Add length if type is string
270 if (gettype($arg) == 'string') $argsString .= ', '.strlen($arg);
273 $argsString .= '), ';
277 if (substr($argsString, -2, 1) == ',') {
278 $argsString = substr($argsString, 0, -2);
281 // Invalid arguments!
282 $argsString = '!INVALID:' . gettype($args) . '!';
285 // Output stub message
286 $this->debugOutput(sprintf("[%s->%s] Stub! Args: %s",
297 * Setter for database result instance
299 * @param $resultInstance An instance of a database result class
301 * @todo SearchableResult and UpdateableResult shall have a super interface to use here
303 protected final function setResultInstance (SearchableResult $resultInstance) {
304 $this->resultInstance = $resultInstance;
308 * Getter for database result instance
310 * @return $resultInstance An instance of a database result class
312 public final function getResultInstance () {
313 return $this->resultInstance;
317 * Setter for template engine instances
319 * @param $templateInstance An instance of a template engine class
322 protected final function setTemplateInstance (CompileableTemplate $templateInstance) {
323 $this->templateInstance = $templateInstance;
327 * Getter for template engine instances
329 * @return $templateInstance An instance of a template engine class
331 protected final function getTemplateInstance () {
332 return $this->templateInstance;
336 * Setter for search instance
338 * @param $searchInstance Searchable criteria instance
341 public final function setSearchInstance (LocalSearchCriteria $searchInstance) {
342 $this->searchInstance = $searchInstance;
346 * Getter for search instance
348 * @return $searchInstance Searchable criteria instance
350 public final function getSearchInstance () {
351 return $this->searchInstance;
355 * Setter for update instance
357 * @param $updateInstance Searchable criteria instance
360 public final function setUpdateInstance (LocalUpdateCriteria $updateInstance) {
361 $this->updateInstance = $updateInstance;
365 * Getter for update instance
367 * @return $updateInstance Updateable criteria instance
369 public final function getUpdateInstance () {
370 return $this->updateInstance;
374 * Setter for resolver instance
376 * @param $resolverInstance Instance of a command resolver class
379 public final function setResolverInstance (Resolver $resolverInstance) {
380 $this->resolverInstance = $resolverInstance;
384 * Getter for resolver instance
386 * @return $resolverInstance Instance of a command resolver class
388 public final function getResolverInstance () {
389 return $this->resolverInstance;
393 * Setter for language instance
395 * @param $configInstance The configuration instance which shall
396 * be FrameworkConfiguration
399 public final function setConfigInstance (FrameworkConfiguration $configInstance) {
400 Registry::getRegistry()->addInstance('config', $configInstance);
404 * Getter for configuration instance
406 * @return $configInstance Configuration instance
408 public final function getConfigInstance () {
409 $configInstance = Registry::getRegistry()->getInstance('config');
410 return $configInstance;
414 * Setter for debug instance
416 * @param $debugInstance The instance for debug output class
419 public final function setDebugInstance (DebugMiddleware $debugInstance) {
420 Registry::getRegistry()->addInstance('debug', $debugInstance);
424 * Getter for debug instance
426 * @return $debugInstance Instance to class DebugConsoleOutput or DebugWebOutput
428 public final function getDebugInstance () {
429 // Get debug instance
430 $debugInstance = Registry::getRegistry()->getInstance('debug');
433 return $debugInstance;
437 * Setter for web output instance
439 * @param $webInstance The instance for web output class
442 public final function setWebOutputInstance (OutputStreamer $webInstance) {
443 Registry::getRegistry()->addInstance('web_output', $webInstance);
447 * Getter for web output instance
449 * @return $webOutputInstance - Instance to class WebOutput
451 public final function getWebOutputInstance () {
452 $webOutputInstance = Registry::getRegistry()->getInstance('web_output');
453 return $webOutputInstance;
457 * Setter for database instance
459 * @param $dbInstance The instance for the database connection (forced DatabaseConnection)
462 public final function setDatabaseInstance (DatabaseConnection $dbInstance) {
463 Registry::getRegistry()->addInstance('db_instance', $dbInstance);
467 * Getter for database layer
469 * @return $dbInstance The database layer instance
471 public final function getDatabaseInstance () {
473 $dbInstance = Registry::getRegistry()->getInstance('db_instance');
480 * Setter for compressor channel
482 * @param $compressorInstance An instance of CompressorChannel
485 public final function setCompressorChannel (CompressorChannel $compressorInstance) {
486 Registry::getRegistry()->addInstance('compressor', $compressorInstance);
490 * Getter for compressor channel
492 * @return $compressorInstance The compressor channel
494 public final function getCompressorChannel () {
495 $compressorInstance = Registry::getRegistry()->getInstance('compressor');
496 return $compressorInstance;
500 * Protected getter for a manageable application helper class
502 * @return $applicationInstance An instance of a manageable application helper class
504 protected final function getApplicationInstance () {
505 $applicationInstance = Registry::getRegistry()->getInstance('application');
506 return $applicationInstance;
510 * Setter for a manageable application helper class
512 * @param $applicationInstance An instance of a manageable application helper class
515 public final function setApplicationInstance (ManageableApplication $applicationInstance) {
516 Registry::getRegistry()->addInstance('application', $applicationInstance);
520 * Setter for request instance
522 * @param $requestInstance An instance of a Requestable class
525 public final function setRequestInstance (Requestable $requestInstance) {
526 $this->requestInstance = $requestInstance;
530 * Getter for request instance
532 * @return $requestInstance An instance of a Requestable class
534 public final function getRequestInstance () {
535 return $this->requestInstance;
539 * Setter for response instance
541 * @param $responseInstance An instance of a Responseable class
544 public final function setResponseInstance (Responseable $responseInstance) {
545 $this->responseInstance = $responseInstance;
549 * Getter for response instance
551 * @return $responseInstance An instance of a Responseable class
553 public final function getResponseInstance () {
554 return $this->responseInstance;
558 * Getter for $realClass
560 * @return $realClass The name of the real class (not BaseFrameworkSystem)
562 public function __toString () {
563 return $this->realClass;
567 * Setter for the real class name
569 * @param $realClass Class name (string)
572 public final function setRealClass ($realClass) {
574 $realClass = (string) $realClass;
577 $this->realClass = $realClass;
581 * Checks wether an object equals this object. You should overwrite this
582 * method to implement own equality checks
584 * @param $objectInstance An instance of a FrameworkInterface object
585 * @return $equals Wether both objects equals
587 public function equals (FrameworkInterface $objectInstance) {
590 $this->__toString() == $objectInstance->__toString()
592 $this->hashCode() == $objectInstance->hashCode()
600 * Generates a generic hash code of this class. You should really overwrite
601 * this method with your own hash code generator code. But keep KISS in mind.
603 * @return $hashCode A generic hash code respresenting this whole class
605 public function hashCode () {
607 return crc32($this->__toString());
611 * Formats computer generated price values into human-understandable formats
612 * with thousand and decimal seperators.
614 * @param $value The in computer format value for a price
615 * @param $currency The currency symbol (use HTML-valid characters!)
616 * @param $decNum Number of decimals after commata
617 * @return $price The for the current language formated price string
618 * @throws MissingDecimalsThousandsSeperatorException If decimals or
619 * thousands seperator
622 public function formatCurrency ($value, $currency = '€', $decNum = 2) {
623 // Are all required attriutes set?
624 if ((!isset($this->decimals)) || (!isset($this->thousands))) {
625 // Throw an exception
626 throw new MissingDecimalsThousandsSeperatorException($this, self::EXCEPTION_ATTRIBUTES_ARE_MISSING);
630 $value = (float) $value;
632 // Reformat the US number
633 $price = number_format($value, $decNum, $this->decimals, $this->thousands) . $currency;
635 // Return as string...
640 * Private getter for language instance
642 * @return $langInstance An instance to the language sub-system
644 protected final function getLanguageInstance () {
645 $langInstance = Registry::getRegistry()->getInstance('language');
646 return $langInstance;
650 * Setter for language instance
652 * @param $langInstance An instance to the language sub-system
654 * @see LanguageSystem
656 public final function setLanguageInstance (ManageableLanguage $langInstance) {
657 Registry::getRegistry()->addInstance('language', $langInstance);
661 * Appends a trailing slash to a string
663 * @param $str A string (maybe) without trailing slash
664 * @return $str A string with an auto-appended trailing slash
666 public final function addMissingTrailingSlash ($str) {
667 // Is there a trailing slash?
668 if (substr($str, -1, 1) != '/') {
672 // Return string with trailing slash
677 * Private getter for file IO instance
679 * @return $fileIoInstance An instance to the file I/O sub-system
681 protected final function getFileIoInstance () {
682 return $this->fileIoInstance;
686 * Setter for file I/O instance
688 * @param $fileIoInstance An instance to the file I/O sub-system
691 public final function setFileIoInstance (FileIoHandler $fileIoInstance) {
692 $this->fileIoInstance = $fileIoInstance;
696 * Prepare the template engine (WebTemplateEngine by default) for a given
697 * application helper instance (ApplicationHelper by default).
699 * @param $applicationInstance An application helper instance or
700 * null if we shall use the default
701 * @return $templateInstance The template engine instance
702 * @throws NullPointerException If the discovered application
703 * instance is still null
705 protected function prepareTemplateInstance (ManageableApplication $applicationInstance = null) {
706 // Is the application instance set?
707 if (is_null($applicationInstance)) {
708 // Get the current instance
709 $applicationInstance = $this->getApplicationInstance();
712 if (is_null($applicationInstance)) {
713 // Thrown an exception
714 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
718 // Initialize the template engine
719 $templateInstance = ObjectFactory::createObjectByConfiguredName('web_template_class');
721 // Return the prepared instance
722 return $templateInstance;
726 * Debugs this instance by putting out it's full content
728 * @param $message Optional message to show in debug output
731 public final function debugInstance ($message = '') {
732 // Restore the error handler to avoid trouble with missing array elements or undeclared variables
733 restore_error_handler();
739 if (!empty($message)) {
741 $content = sprintf("<div class=\"debug_message\">Message: %s</div>\n", $message);
744 // Generate the output
745 $content .= sprintf("<pre>%s</pre>",
754 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>",
757 ClassLoader::getInstance()->getPrintableIncludeList()
762 * Replaces control characters with printable output
764 * @param $str String with control characters
765 * @return $str Replaced string
767 protected function replaceControlCharacters ($str) {
770 "\r", '[r]', str_replace(
771 "\n", '[n]', str_replace(
781 * Output a partial stub message for the caller method
783 * @param $message An optional message to display
786 protected function partialStub ($message = '') {
788 $backtrace = debug_backtrace();
790 // Generate the class::method string
791 $methodName = 'UnknownClass->unknownMethod';
792 if ((isset($backtrace[1]['class'])) && (isset($backtrace[1]['function']))) {
793 $methodName = $backtrace[1]['class'] . '->' . $backtrace[1]['function'];
796 // Construct the full message
797 $stubMessage = sprintf("[%s:] Partial stub!",
801 // Is the extra message given?
802 if (!empty($message)) {
803 // Then add it as well
804 $stubMessage .= sprintf(" Message: <span id=\"stub_message\">%s</span>", $message);
807 // Debug instance is there?
808 if (!is_null($this->getDebugInstance())) {
809 // Output stub message
810 $this->debugOutput($stubMessage);
813 trigger_error($stubMessage . "<br />\n");
818 * Outputs a debug backtrace and stops further script execution
822 public function debugBackTrace () {
823 // Sorry, there is no other way getting this nice backtrace
825 debug_print_backtrace();
831 * Outputs a debug message wether to debug instance (should be set!) or dies with or pints the message
833 * @param $message Message we shall send out...
834 * @param $doPrint Wether we shall print or die here which first is the default
837 public function debugOutput ($message, $doPrint = true) {
838 // Get debug instance
839 $debugInstance = $this->getDebugInstance();
841 // Is the debug instance there?
842 if (is_object($debugInstance)) {
843 // Use debug output handler
844 $debugInstance->output($message);
846 if ($doPrint === false) {
847 // Die here if not printed
852 if ($doPrint === true) {
855 // DO NOT REWRITE THIS TO app_die() !!!
862 * Converts e.g. a command from URL to a valid class by keeping out bad characters
864 * @param $str The string, what ever it is needs to be converted
865 * @return $className Generated class name
867 public function convertToClassName ($str) {
871 // Convert all dashes in underscores
872 $str = $this->convertDashesToUnderscores($str);
874 // Now use that underscores to get classname parts for hungarian style
875 foreach (explode('_', $str) as $strPart) {
876 // Make the class name part lower case and first upper case
877 $className .= ucfirst(strtolower($strPart));
885 * Converts dashes to underscores, e.g. useable for configuration entries
887 * @param $str The string with maybe dashes inside
888 * @return $str The converted string with no dashed, but underscores
890 public final function convertDashesToUnderscores ($str) {
892 $str = str_replace('-', '_', $str);
894 // Return converted string
899 * Marks up the code by adding e.g. line numbers
901 * @param $phpCode Unmarked PHP code
902 * @return $markedCode Marked PHP code
904 public function markupCode ($phpCode) {
909 $errorArray = error_get_last();
911 // Init the code with error message
912 if (is_array($errorArray)) {
914 $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>",
915 basename($errorArray['file']),
917 $errorArray['message'],
922 // Add line number to the code
923 foreach (explode("\n", $phpCode) as $lineNo => $code) {
925 $markedCode .= sprintf("<span id=\"code_line\">%s</span>: %s\n",
927 htmlentities($code, ENT_QUOTES)
936 * Filter a given GMT timestamp (non Uni* stamp!) to make it look more
937 * beatiful for web-based front-ends. If null is given a message id
938 * null_timestamp will be resolved and returned.
940 * @param $timestamp Timestamp to prepare (filter) for display
941 * @return $readable A readable timestamp
943 public function doFilterFormatTimestamp ($timestamp) {
944 // Default value to return
947 // Is the timestamp null?
948 if (is_null($timestamp)) {
949 // Get a message string
950 $readable = $this->getLanguageInstance()->getMessage('null_timestamp');
952 switch ($this->getLanguageInstance()->getLanguageCode()) {
953 case 'de': // German format is a bit different to default
954 // Split the GMT stamp up
955 $dateTime = explode(' ', $timestamp );
956 $dateArray = explode('-', $dateTime[0]);
957 $timeArray = explode(':', $dateTime[1]);
959 // Construct the timestamp
960 $readable = sprintf($this->getConfigInstance()->getConfigEntry('german_date_time'),
970 default: // Default is pass-through
971 $readable = $timestamp;
981 * Filter a given number into a localized number
983 * @param $value The raw value from e.g. database
984 * @return $localized Localized value
986 public function doFilterFormatNumber ($value) {
987 // Generate it from config and localize dependencies
988 switch ($this->getLanguageInstance()->getLanguageCode()) {
989 case 'de': // German format is a bit different to default
990 $localized = number_format($value, $this->getConfigInstance()->getConfigEntry('decimals'), ',', '.');
994 $localized = number_format($value, $this->getConfigInstance()->getConfigEntry('decimals'), '.', ',');
1003 * "Getter" for databse entry
1005 * @return $entry An array with database entries
1006 * @throws NullPointerException If the database result is not found
1007 * @throws InvalidDatabaseResultException If the database result is invalid
1009 protected final function getDatabaseEntry () {
1010 // Is there an instance?
1011 if (is_null($this->getResultInstance())) {
1012 // Throw an exception here
1013 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
1017 $this->getResultInstance()->rewind();
1019 // Do we have an entry?
1020 if ($this->getResultInstance()->valid() === false) {
1021 throw new InvalidDatabaseResultException(array($this, $this->getResultInstance()), DatabaseResult::EXCEPTION_INVALID_DATABASE_RESULT);
1025 $this->getResultInstance()->next();
1028 $entry = $this->getResultInstance()->current();
1035 * Getter for field name
1037 * @param $fieldName Field name which we shall get
1038 * @return $fieldValue Field value from the user
1039 * @throws NullPointerException If the result instance is null
1041 public final function getField ($fieldName) {
1042 // Default field value
1045 // Get result instance
1046 $resultInstance = $this->getResultInstance();
1048 // Is this instance null?
1049 if (is_null($resultInstance)) {
1050 // Then the user instance is no longer valid (expired cookies?)
1051 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
1054 // Get current array
1055 $fieldArray = $resultInstance->current();
1056 //* DEBUG: */ $this->debugOutput($fieldName.':<pre>'.print_r($fieldArray, true).'</pre>');
1058 // Does the field exist?
1059 if (isset($fieldArray[$fieldName])) {
1061 $fieldValue = $fieldArray[$fieldName];
1069 * Protected setter for user instance
1071 * @param $userInstance An instance of a user class
1074 protected final function setUserInstance (ManageableAccount $userInstance) {
1075 $this->userInstance = $userInstance;
1079 * Getter for user instance
1081 * @return $userInstance An instance of a user class
1083 public final function getUserInstance () {
1084 return $this->userInstance;
1088 * Setter for controller instance (this surely breaks a bit the MVC patterm)
1090 * @param $controllerInstance An instance of the controller
1093 public final function setControllerInstance (Controller $controllerInstance) {
1094 $this->controllerInstance = $controllerInstance;
1098 * Getter for controller instance (this surely breaks a bit the MVC patterm)
1100 * @return $controllerInstance An instance of the controller
1102 public final function getControllerInstance () {
1103 return $this->controllerInstance;
1107 * Flushs all pending updates to the database layer
1111 public function flushPendingUpdates () {
1112 // Get result instance
1113 $resultInstance = $this->getResultInstance();
1115 // Do we have data to update?
1116 if ((is_object($resultInstance)) && ($resultInstance->ifDataNeedsFlush())) {
1117 // Get wrapper class name config entry
1118 $configEntry = $resultInstance->getUpdateInstance()->getWrapperConfigEntry();
1120 // Create object instance
1121 $wrapperInstance = ObjectFactory::createObjectByConfiguredName($configEntry);
1123 // Yes, then send the whole result to the database layer
1124 $wrapperInstance->doUpdateByResult($this->getResultInstance());
1129 * Outputs a deprecation warning to the developer.
1131 * @param $message The message we shall output to the developer
1133 * @todo Write a logging mechanism for productive mode
1135 public function deprecationWarning ($message) {
1136 // Is developer mode active?
1137 if (defined('DEVELOPER')) {
1138 // Debug instance is there?
1139 if (!is_null($this->getDebugInstance())) {
1140 // Output stub message
1141 $this->debugOutput($message);
1144 trigger_error($message . "<br />\n");
1147 // @TODO Finish this part!
1148 $this->partialStub('Developer mode inactive. Message:' . $message);
1153 * Checks wether the given PHP extension is loaded
1155 * @param $phpExtension The PHP extension we shall check
1156 * @return $isLoaded Wether the PHP extension is loaded
1158 public final function isPhpExtensionLoaded ($phpExtension) {
1160 $isLoaded = in_array($phpExtension, get_loaded_extensions());
1167 * Setter for RNG instance
1169 * @param $rngInstance An instance of a random number generator (RNG)
1172 protected final function setRngInstance (RandomNumberGenerator $rngInstance) {
1173 $this->rngInstance = $rngInstance;
1177 * Getter for RNG instance
1179 * @return $rngInstance An instance of a random number generator (RNG)
1181 public final function getRngInstance () {
1182 return $this->rngInstance;
1186 * Setter for Iterator instance
1188 * @param $iteratorInstance An instance of an Iterator
1191 protected final function setIteratorInstance (Iterator $iteratorInstance) {
1192 $this->iteratorInstance = $iteratorInstance;
1196 * Getter for Iterator instance
1198 * @return $iteratorInstance An instance of an Iterator
1200 public final function getIteratorInstance () {
1201 return $this->iteratorInstance;
1205 * "Getter" as a time() replacement but with milliseconds. You should use this
1206 * method instead of the encapsulated getimeofday() function.
1208 * @return $milliTime Timestamp with milliseconds
1210 public function getMilliTime () {
1211 // Get the time of day as float
1212 $milliTime = gettimeofday(true);
1219 * Idles (sleeps) for given milliseconds
1221 * @return $hasSlept Wether it goes fine
1223 public function idle ($milliSeconds) {
1224 // Sleep is fine by default
1227 // Idle so long with found function
1228 if (function_exists('time_sleep_until')) {
1229 // Get current time and add idle time
1230 $sleepUntil = $this->getMilliTime() + abs($milliSeconds) / 1000;
1232 // New PHP 5.1.0 function found
1233 $hasSlept = time_sleep_until($sleepUntil);
1235 // My Sun Station doesn't have that function even with latest PHP
1237 usleep($milliSeconds * 1000);
1245 * Setter for the list instance
1247 * @param $listInstance A list of Listable
1250 protected final function setListInstance (Listable $listInstance) {
1251 $this->listInstance = $listInstance;
1255 * Getter for the list instance
1257 * @return $listInstance A list of Listable
1259 protected final function getListInstance () {
1260 return $this->listInstance;
1264 * Setter for the menu instance
1266 * @param $menuInstance A RenderableMenu instance
1269 protected final function setMenuInstance (RenderableMenu $menuInstance) {
1270 $this->menuInstance = $menuInstance;
1274 * Getter for the menu instance
1276 * @return $menuInstance A RenderableMenu instance
1278 protected final function getMenuInstance () {
1279 return $this->menuInstance;
1283 * Setter for image instance
1285 * @param $imageInstance An instance of an image
1288 public final function setImageInstance (BaseImage $imageInstance) {
1289 $this->imageInstance = $imageInstance;
1293 * Getter for image instance
1295 * @return $imageInstance An instance of an image
1297 public final function getImageInstance () {
1298 return $this->imageInstance;
1302 * Setter for stacker instance
1304 * @param $stackerInstance An instance of an stacker
1307 public final function setStackerInstance (Stackable $stackerInstance) {
1308 $this->stackerInstance = $stackerInstance;
1312 * Getter for stacker instance
1314 * @return $stackerInstance An instance of an stacker
1316 public final function getStackerInstance () {
1317 return $this->stackerInstance;
1321 * Setter for compressor instance
1323 * @param $compressorInstance An instance of an compressor
1326 public final function setCompressorInstance (Compressor $compressorInstance) {
1327 $this->compressorInstance = $compressorInstance;
1331 * Getter for compressor instance
1333 * @return $compressorInstance An instance of an compressor
1335 public final function getCompressorInstance () {
1336 return $this->compressorInstance;
1340 * Setter for Parseable instance
1342 * @param $parserInstance An instance of an Parseable
1345 public final function setParserInstance (Parseable $parserInstance) {
1346 $this->parserInstance = $parserInstance;
1350 * Getter for Parseable instance
1352 * @return $parserInstance An instance of an Parseable
1354 public final function getParserInstance () {
1355 return $this->parserInstance;
1359 * Setter for ProtocolHandler instance
1361 * @param $protocolInstance An instance of an ProtocolHandler
1364 public final function setProtocolInstance (ProtocolHandler $protocolInstance) {
1365 $this->protocolInstance = $protocolInstance;
1369 * Getter for ProtocolHandler instance
1371 * @return $protocolInstance An instance of an ProtocolHandler
1373 public final function getProtocolInstance () {
1374 return $this->protocolInstance;
1378 * Setter for BaseDatabaseWrapper instance
1380 * @param $wrapperInstance An instance of an BaseDatabaseWrapper
1383 public final function setWrapperInstance (BaseDatabaseWrapper $wrapperInstance) {
1384 $this->wrapperInstance = $wrapperInstance;
1388 * Getter for BaseDatabaseWrapper instance
1390 * @return $wrapperInstance An instance of an BaseDatabaseWrapper
1392 public final function getWrapperInstance () {
1393 return $this->wrapperInstance;
1397 * Setter for socket resource
1399 * @param $socketResource A valid socket resource
1402 public final function setSocketResource ($socketResource) {
1403 $this->socketResource = $socketResource;
1407 * Getter for socket resource
1409 * @return $socketResource A valid socket resource
1411 public function getSocketResource () {
1412 return $this->socketResource;
1416 * Setter for raw package Data
1418 * @param $packageData Raw package Data
1421 public final function setPackageData (array $packageData) {
1422 $this->packageData = $packageData;
1426 * Getter for raw package Data
1428 * @return $packageData Raw package Data
1430 public function getPackageData () {
1431 return $this->packageData;