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 $realClass = 'FrameworkSystem';
84 private $thousands = '.'; // German
89 private $decimals = ','; // German
91 /***********************
92 * Exception codes.... *
93 ***********************/
95 const EXCEPTION_IS_NULL_POINTER = 0x001;
96 const EXCEPTION_IS_NO_OBJECT = 0x002;
97 const EXCEPTION_IS_NO_ARRAY = 0x003;
98 const EXCEPTION_MISSING_METHOD = 0x004;
99 const EXCEPTION_CLASSES_NOT_MATCHING = 0x005;
100 const EXCEPTION_INDEX_OUT_OF_BOUNDS = 0x006;
101 const EXCEPTION_DIMENSION_ARRAY_INVALID = 0x007;
102 const EXCEPTION_ITEM_NOT_TRADEABLE = 0x008;
103 const EXCEPTION_ITEM_NOT_IN_PRICE_LIST = 0x009;
104 const EXCEPTION_GENDER_IS_WRONG = 0x00a;
105 const EXCEPTION_BIRTH_DATE_IS_INVALID = 0x00b;
106 const EXCEPTION_EMPTY_STRUCTURES_ARRAY = 0x00c;
107 const EXCEPTION_HAS_ALREADY_PERSONELL_LIST = 0x00d;
108 const EXCEPTION_NOT_ENOUGTH_UNEMPLOYEES = 0x00e;
109 const EXCEPTION_TOTAL_PRICE_NOT_CALCULATED = 0x00f;
110 const EXCEPTION_HARBOR_HAS_NO_SHIPYARDS = 0x010;
111 const EXCEPTION_CONTRACT_PARTNER_INVALID = 0x011;
112 const EXCEPTION_CONTRACT_PARTNER_MISMATCH = 0x012;
113 const EXCEPTION_CONTRACT_ALREADY_SIGNED = 0x013;
114 const EXCEPTION_UNEXPECTED_EMPTY_STRING = 0x014;
115 const EXCEPTION_PATH_NOT_FOUND = 0x015;
116 const EXCEPTION_INVALID_PATH_NAME = 0x016;
117 const EXCEPTION_READ_PROTECED_PATH = 0x017;
118 const EXCEPTION_WRITE_PROTECED_PATH = 0x018;
119 const EXCEPTION_DIR_POINTER_INVALID = 0x019;
120 const EXCEPTION_FILE_POINTER_INVALID = 0x01a;
121 const EXCEPTION_INVALID_DIRECTORY_POINTER = 0x01b;
122 const EXCEPTION_UNEXPECTED_OBJECT = 0x01c;
123 const EXCEPTION_LIMIT_ELEMENT_IS_UNSUPPORTED = 0x01d;
124 const EXCEPTION_GETTER_IS_MISSING = 0x01e;
125 const EXCEPTION_ARRAY_EXPECTED = 0x01f;
126 const EXCEPTION_ARRAY_HAS_INVALID_COUNT = 0x020;
127 const EXCEPTION_ID_IS_INVALID_FORMAT = 0x021;
128 const EXCEPTION_MD5_CHECKSUMS_MISMATCH = 0x022;
129 const EXCEPTION_UNEXPECTED_STRING_SIZE = 0x023;
130 const EXCEPTION_SIMULATOR_ID_INVALID = 0x024;
131 const EXCEPTION_MISMATCHING_COMPRESSORS = 0x025;
132 const EXCEPTION_CONTAINER_ITEM_IS_NULL = 0x026;
133 const EXCEPTION_ITEM_IS_NO_ARRAY = 0x027;
134 const EXCEPTION_CONTAINER_MAYBE_DAMAGED = 0x028;
135 const EXCEPTION_INVALID_STRING = 0x029;
136 const EXCEPTION_VARIABLE_NOT_SET = 0x02a;
137 const EXCEPTION_ATTRIBUTES_ARE_MISSING = 0x02b;
138 const EXCEPTION_ARRAY_ELEMENTS_MISSING = 0x02c;
139 const EXCEPTION_TEMPLATE_ENGINE_UNSUPPORTED = 0x02d;
140 const EXCEPTION_MISSING_LANGUAGE_HANDLER = 0x02e;
141 const EXCEPTION_MISSING_FILE_IO_HANDLER = 0x02f;
142 const EXCEPTION_MISSING_ELEMENT = 0x030;
143 const EXCEPTION_HEADERS_ALREADY_SENT = 0x031;
144 const EXCEPTION_DEFAULT_CONTROLLER_GONE = 0x032;
145 const EXCEPTION_CLASS_NOT_FOUND = 0x033;
146 const EXCEPTION_REQUIRED_INTERFACE_MISSING = 0x034;
147 const EXCEPTION_FATAL_ERROR = 0x035;
148 const EXCEPTION_FILE_NOT_FOUND = 0x036;
149 const EXCEPTION_ASSERTION_FAILED = 0x037;
150 const EXCEPTION_FILE_CANNOT_BE_READ = 0x038;
151 const EXCEPTION_DATABASE_UPDATED_NOT_ALLOWED = 0x039;
152 const EXCEPTION_FILTER_CHAIN_INTERCEPTED = 0x040;
155 * In the super constructor these system classes shall be ignored or else
156 * we would get an endless calling loop.
158 *---------------------------------------------------------------------*
159 * ATTENTION: IF YOU REMOVE ONE OF THEM YOU WILL RUN YOUR SERVER IN AN *
161 *---------------------------------------------------------------------*
163 private $systemClasses = array(
164 'DebugMiddleware', // Debug middleware output sub-system
165 'Registry', // Object registry
166 'ObjectFactory', // Object factory
167 'DebugWebOutput', // Debug web output sub-system
168 'WebOutput', // Web output sub-system
169 'CompressorChannel', // Compressor sub-system
170 'DebugConsoleOutput', // Debug console output sub-system
171 'DebugErrorLogOutput', // Debug error_log() output sub-system
172 'FrameworkDirectoryPointer', // Directory handler sub-system
173 'NullCompressor', // Null compressor
174 'Bzip2Compressor', // BZIP2 compressor
175 'GzipCompressor', // GZIP compressor
178 * Protected super constructor
180 * @param $className Name of the class
183 protected function __construct ($className) {
185 $this->setRealClass($className);
187 // Initialize the class if class Registry is there
188 if ((class_exists('Registry')) && (Registry::isInitialized() === false)) {
189 // Initialize the registry automatically
190 $this->initInstance();
195 * Destructor reached...
198 * @todo This is old code. Do we still need this old lost code?
200 public function __destruct() {
201 // Flush any updated entries to the database
202 $this->flushPendingUpdates();
204 // Is this object already destroyed?
205 if ($this->__toString() != 'DestructedObject') {
206 // Destroy all informations about this class but keep some text about it alive
207 $this->setRealClass('DestructedObject');
208 } elseif ((defined('DEBUG_DESTRUCTOR')) && (is_object($this->getDebugInstance()))) {
209 // Already destructed object
210 $this->debugOutput(sprintf("[%s:] The object <span class=\"object_name\">%s</span> is already destroyed.",
218 * The call method where all non-implemented methods end up
222 public final function __call ($methodName, $args) {
223 // Implode all given arguments
227 $argsString = 'NULL';
228 } elseif (is_array($args)) {
229 // Some arguments are there
230 foreach ($args as $arg) {
232 $argsString .= $arg . ' (' . gettype($arg);
234 // Add length if type is string
235 if (gettype($arg) == 'string') $argsString .= ', '.strlen($arg);
238 $argsString .= '), ';
242 if (substr($argsString, -2, 1) == ',') {
243 $argsString = substr($argsString, 0, -2);
246 // Invalid arguments!
247 $argsString = '!INVALID:' . gettype($args) . '!';
250 // Output stub message
251 $this->debugOutput(sprintf("[%s->%s] Stub! Args: %s",
262 * Private initializer for this class
266 private final function initInstance () {
267 // Is this a system class?
268 if (!in_array($this->__toString(), $this->systemClasses)) {
269 // Set configuration instance
270 $this->setConfigInstance(FrameworkConfiguration::getInstance());
272 // Add application helper to our class
273 $this->systemclasses[] = $this->getConfigInstance()->getConfigEntry('app_helper_class');
275 // Set debug instance
276 $this->setDebugInstance(DebugMiddleware::createDebugMiddleware($this->getConfigInstance()->getConfigEntry('debug_class')));
278 // Get output instance and set it
279 $outputInstance = ObjectFactory::createObjectByConfiguredName('output_class', array($this->getConfigInstance()->getConfigEntry('web_content_type')));
280 $this->setWebOutputInstance($outputInstance);
282 // Set the compressor channel
283 $this->setCompressorChannel(CompressorChannel::createCompressorChannel(
284 $this->getConfigInstance()->getConfigEntry('base_path').
285 $this->getConfigInstance()->getConfigEntry('compressor_base_path')
288 // Initialization done! :D
289 Registry::isInitialized('OK');
290 } elseif ($this->__toString() == 'DebugMiddleware') {
291 // Set configuration instance
292 $this->setConfigInstance(FrameworkConfiguration::getInstance());
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 $debugInstance = Registry::getRegistry()->getInstance('debug');
430 return $debugInstance;
434 * Setter for web output instance
436 * @param $webInstance The instance for web output class
439 public final function setWebOutputInstance (OutputStreamer $webInstance) {
440 Registry::getRegistry()->addInstance('web_output', $webInstance);
444 * Getter for web output instance
446 * @return $webOutputInstance - Instance to class WebOutput
448 public final function getWebOutputInstance () {
449 $webOutputInstance = Registry::getRegistry()->getInstance('web_output');
450 return $webOutputInstance;
454 * Setter for database instance
456 * @param $dbInstance The instance for the database connection
457 * (forced DatabaseConnection)
460 public final function setDatabaseInstance (DatabaseConnection $dbInstance) {
461 Registry::getRegistry()->addInstance('db_instance', $dbInstance);
465 * Getter for database layer
467 * @return $dbInstance The database layer instance
469 public final function getDatabaseInstance () {
470 // Default is invalid db instance
473 // Is the registry there and initialized?
474 if ((class_exists('Registry')) && (Registry::isInitialized() === true)) {
475 $dbInstance = Registry::getRegistry()->getInstance('db_instance');
483 * Setter for compressor channel
485 * @param $compressorInstance An instance of CompressorChannel
488 public final function setCompressorChannel (CompressorChannel $compressorInstance) {
489 Registry::getRegistry()->addInstance('compressor', $compressorInstance);
493 * Getter for compressor channel
495 * @return $compressorInstance The compressor channel
497 public final function getCompressorChannel () {
498 $compressorInstance = Registry::getRegistry()->getInstance('compressor');
499 return $compressorInstance;
503 * Protected getter for a manageable application helper class
505 * @return $applicationInstance An instance of a manageable application helper class
507 protected final function getApplicationInstance () {
508 $applicationInstance = Registry::getRegistry()->getInstance('application');
509 return $applicationInstance;
513 * Setter for a manageable application helper class
515 * @param $applicationInstance An instance of a manageable application helper class
518 public final function setApplicationInstance (ManageableApplication $applicationInstance) {
519 Registry::getRegistry()->addInstance('application', $applicationInstance);
523 * Setter for request instance
525 * @param $requestInstance An instance of a Requestable class
528 public final function setRequestInstance (Requestable $requestInstance) {
529 $this->requestInstance = $requestInstance;
533 * Getter for request instance
535 * @return $requestInstance An instance of a Requestable class
537 public final function getRequestInstance () {
538 return $this->requestInstance;
542 * Setter for response instance
544 * @param $responseInstance An instance of a Responseable class
547 public final function setResponseInstance (Responseable $responseInstance) {
548 $this->responseInstance = $responseInstance;
552 * Getter for response instance
554 * @return $responseInstance An instance of a Responseable class
556 public final function getResponseInstance () {
557 return $this->responseInstance;
561 * Getter for $realClass
563 * @return $realClass The name of the real class (not BaseFrameworkSystem)
565 public final function __toString () {
566 return $this->realClass;
570 * Setter for the real class name
572 * @param $realClass Class name (string)
575 public final function setRealClass ($realClass) {
577 $realClass = (string) $realClass;
580 $this->realClass = $realClass;
584 * Compare class name of this and given class name
586 * @param $className The class name as string from the other class
587 * @return boolean The result of comparing both class names
589 public final function isClass ($className) {
590 return ($this->__toString() == $className);
594 * Formats computer generated price values into human-understandable formats
595 * with thousand and decimal seperators.
597 * @param $value The in computer format value for a price
598 * @param $currency The currency symbol (use HTML-valid characters!)
599 * @param $decNum Number of decimals after commata
600 * @return $price The for the current language formated price string
601 * @throws MissingDecimalsThousandsSeperatorException If decimals or
602 * thousands seperator
605 public function formatCurrency ($value, $currency = '€', $decNum = 2) {
606 // Are all required attriutes set?
607 if ((!isset($this->decimals)) || (!isset($this->thousands))) {
608 // Throw an exception
609 throw new MissingDecimalsThousandsSeperatorException($this, self::EXCEPTION_ATTRIBUTES_ARE_MISSING);
613 $value = (float) $value;
615 // Reformat the US number
616 $price = number_format($value, $decNum, $this->decimals, $this->thousands) . $currency;
618 // Return as string...
623 * Removes number formating characters
627 public final function removeNumberFormaters () {
628 unset($this->thousands);
629 unset($this->decimals);
633 * Private getter for language instance
635 * @return $langInstance An instance to the language sub-system
637 protected final function getLanguageInstance () {
638 $langInstance = Registry::getRegistry()->getInstance('language');
639 return $langInstance;
643 * Setter for language instance
645 * @param $langInstance An instance to the language sub-system
647 * @see LanguageSystem
649 public final function setLanguageInstance (ManageableLanguage $langInstance) {
650 Registry::getRegistry()->addInstance('language', $langInstance);
654 * Remove the $systemClasses array from memory
658 public final function removeSystemArray () {
659 unset($this->systemClasses);
663 * Appends a trailing slash to a string
665 * @param $str A string (maybe) without trailing slash
666 * @return $str A string with an auto-appended trailing slash
668 public final function addMissingTrailingSlash ($str) {
669 // Is there a trailing slash?
670 if (substr($str, -1, 1) != '/') $str .= '/';
675 * Private getter for file IO instance
677 * @return $fileIoInstance An instance to the file I/O sub-system
679 protected final function getFileIoInstance () {
680 return $this->fileIoInstance;
684 * Setter for file I/O instance
686 * @param $fileIoInstance An instance to the file I/O sub-system
689 public final function setFileIoInstance (FileIoHandler $fileIoInstance) {
690 $this->fileIoInstance = $fileIoInstance;
694 * Prepare the template engine (WebTemplateEngine by default) for a given
695 * application helper instance (ApplicationHelper by default).
697 * @param $appInstance An application helper instance or
698 * null if we shall use the default
699 * @return $templateInstance The template engine instance
700 * @throws NullPointerException If the template engine could not
702 * @throws UnsupportedTemplateEngineException If $templateInstance is an
703 * unsupported template engine
704 * @throws MissingLanguageHandlerException If the language sub-system
705 * is not yet initialized
706 * @throws NullPointerException If the discovered application
707 * instance is still null
709 protected function prepareTemplateInstance (BaseFrameworkSystem $appInstance=null) {
710 // Is the application instance set?
711 if (is_null($appInstance)) {
712 // Get the current instance
713 $appInstance = $this->getApplicationInstance();
716 if (is_null($appInstance)) {
717 // Thrown an exception
718 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
722 // Are both instances set?
723 if ($appInstance->getLanguageInstance() === null) {
724 // Invalid language instance
725 throw new MissingLanguageHandlerException($appInstance, self::EXCEPTION_MISSING_LANGUAGE_HANDLER);
726 } elseif ($appInstance->getFileIoInstance() === null) {
727 // Invalid language instance
728 throw new MissingFileIoHandlerException($appInstance, self::EXCEPTION_MISSING_FILE_IO_HANDLER);
731 // Initialize the template engine
732 $templateInstance = ObjectFactory::createObjectByConfiguredName('template_class', array($appInstance));
734 // Return the prepared instance
735 return $templateInstance;
739 * Debugs this instance by putting out it's full content
741 * @param $message Optional message to show in debug output
744 public final function debugInstance ($message = '') {
745 // Restore the error handler to avoid trouble with missing array elements or undeclared variables
746 restore_error_handler();
752 if (!empty($message)) {
754 $content = sprintf("<div class=\"debug_message\">Message: %s</div>\n", $message);
757 // Generate the output
758 $content .= sprintf("<pre>%s</pre>",
767 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>",
770 ClassLoader::getInstance()->getPrintableIncludeList()
775 * Output a partial stub message for the caller method
777 * @param $message An optional message to display
780 protected function partialStub ($message = '') {
782 $backtrace = debug_backtrace();
784 // Generate the class::method string
785 $methodName = 'UnknownClass->unknownMethod';
786 if ((isset($backtrace[1]['class'])) && (isset($backtrace[1]['function']))) {
787 $methodName = $backtrace[1]['class']."->".$backtrace[1]['function'];
790 // Construct the full message
791 $stubMessage = sprintf("[%s:] Partial stub!",
795 // Is the extra message given?
796 if (!empty($message)) {
797 // Then add it as well
798 $stubMessage .= sprintf(" Message: <span id=\"stub_message\">%s</span>", $message);
801 // Debug instance is there?
802 if (!is_null($this->getDebugInstance())) {
803 // Output stub message
804 $this->debugOutput($stubMessage);
807 trigger_error($stubMessage."<br />\n");
812 * Outputs a debug backtrace and stops further script execution
816 public function debugBackTrace () {
817 // Sorry, there is no other way getting this nice backtrace
819 debug_print_backtrace();
825 * Outputs a debug message wether to debug instance (should be set!) or dies with or pints the message
827 * @param $message Message we shall send out...
828 * @param $doPrint Wether we shall print or die here which first is the default
831 public function debugOutput ($message, $doPrint = true) {
832 // Get debug instance
833 $debugInstance = $this->getDebugInstance();
835 // Is the debug instance there?
836 if (is_object($debugInstance)) {
837 // Use debug output handler
838 $debugInstance->output($message);
839 if ($doPrint === false) die(); // Die here if not printed
842 if ($doPrint === true) {
845 // DO NOT REWRITE THIS TO app_die() !!!
852 * Converts e.g. a command from URL to a valid class by keeping out bad characters
854 * @param $str The string, what ever it is needs to be converted
855 * @return $className Generated class name
857 public function convertToClassName ($str) {
861 // Convert all dashes in underscores
862 $str = $this->convertDashesToUnderscores($str);
864 // Now use that underscores to get classname parts for hungarian style
865 foreach (explode('_', $str) as $strPart) {
866 // Make the class name part lower case and first upper case
867 $className .= ucfirst(strtolower($strPart));
875 * Converts dashes to underscores, e.g. useable for configuration entries
877 * @param $str The string with maybe dashes inside
878 * @return $str The converted string with no dashed, but underscores
880 public final function convertDashesToUnderscores ($str) {
882 $str = str_replace('-', '_', $str);
884 // Return converted string
889 * Marks up the code by adding e.g. line numbers
891 * @param $phpCode Unmarked PHP code
892 * @return $markedCode Marked PHP code
894 public function markupCode ($phpCode) {
899 $errorArray = error_get_last();
901 // Init the code with error message
902 if (is_array($errorArray)) {
904 $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>",
905 basename($errorArray['file']),
907 $errorArray['message'],
912 // Add line number to the code
913 foreach (explode("\n", $phpCode) as $lineNo => $code) {
915 $markedCode .= sprintf("<span id=\"code_line\">%s</span>: %s\n",
917 htmlentities($code, ENT_QUOTES)
926 * Filter a given GMT timestamp (non Uni* stamp!) to make it look more
927 * beatiful for web-based front-ends. If null is given a message id
928 * null_timestamp will be resolved and returned.
930 * @param $timestamp Timestamp to prepare (filter) for display
931 * @return $readable A readable timestamp
933 public function doFilterFormatTimestamp ($timestamp) {
934 // Default value to return
937 // Is the timestamp null?
938 if (is_null($timestamp)) {
939 // Get a message string
940 $readable = $this->getLanguageInstance()->getMessage('null_timestamp');
942 switch ($this->getLanguageInstance()->getLanguageCode()) {
943 case "de": // German format is a bit different to default
944 // Split the GMT stamp up
945 $dateTime = explode(' ', $timestamp );
946 $dateArray = explode('-', $dateTime[0]);
947 $timeArray = explode(':', $dateTime[1]);
949 // Construct the timestamp
950 $readable = sprintf($this->getConfigInstance()->getConfigEntry('german_date_time'),
960 default: // Default is pass-through
961 $readable = $timestamp;
971 * "Getter" for databse entry
973 * @return $entry An array with database entries
974 * @throws NullPointerException If the database result is not found
975 * @throws InvalidDatabaseResultException If the database result is invalid
977 protected final function getDatabaseEntry () {
978 // Is there an instance?
979 if (is_null($this->getResultInstance())) {
980 // Throw an exception here
981 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
985 $this->getResultInstance()->rewind();
987 // Do we have an entry?
988 if ($this->getResultInstance()->valid() === false) {
989 throw new InvalidDatabaseResultException(array($this, $this->getResultInstance()), DatabaseResult::EXCEPTION_INVALID_DATABASE_RESULT);
993 $this->getResultInstance()->next();
996 $entry = $this->getResultInstance()->current();
1003 * Getter for field name
1005 * @param $fieldName Field name which we shall get
1006 * @return $fieldValue Field value from the user
1007 * @throws NullPointerException If the result instance is null
1009 public final function getField ($fieldName) {
1010 // Default field value
1013 // Get result instance
1014 $resultInstance = $this->getResultInstance();
1016 // Is this instance null?
1017 if (is_null($resultInstance)) {
1018 // Then the user instance is no longer valid (expired cookies?)
1019 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
1022 // Get current array
1023 $fieldArray = $resultInstance->current();
1025 // Does the field exist?
1026 if (isset($fieldArray[$fieldName])) {
1028 $fieldValue = $fieldArray[$fieldName];
1036 * Protected setter for user instance
1038 * @param $userInstance An instance of a user class
1041 protected final function setUserInstance (ManageableAccount $userInstance) {
1042 $this->userInstance = $userInstance;
1046 * Getter for user instance
1048 * @return $userInstance An instance of a user class
1050 public final function getUserInstance () {
1051 return $this->userInstance;
1055 * Setter for controller instance (this surely breaks a bit the MVC patterm)
1057 * @param $controllerInstance An instance of the controller
1060 public final function setControllerInstance (Controller $controllerInstance) {
1061 $this->controllerInstance = $controllerInstance;
1065 * Getter for controller instance (this surely breaks a bit the MVC patterm)
1067 * @return $controllerInstance An instance of the controller
1069 public final function getControllerInstance () {
1070 return $this->controllerInstance;
1074 * Flushs all pending updates to the database layer
1078 public function flushPendingUpdates () {
1079 // Get result instance
1080 $resultInstance = $this->getResultInstance();
1082 // Do we have data to update?
1083 if ((is_object($resultInstance)) && ($resultInstance->ifDataNeedsFlush())) {
1084 // Get wrapper class name config entry
1085 $configEntry = $resultInstance->getUpdateInstance()->getWrapperConfigEntry();
1087 // Create object instance
1088 $wrapperInstance = ObjectFactory::createObjectByConfiguredName($configEntry);
1090 // Yes, then send the whole result to the database layer
1091 $wrapperInstance->doUpdateByResult($this->getResultInstance());
1096 * Outputs a deprecation warning to the developer.
1098 * @param $message The message we shall output to the developer
1100 * @todo Write a logging mechanism for productive mode
1102 public function deprecationWarning ($message) {
1103 // Is developer mode active?
1104 if (defined('DEVELOPER')) {
1105 // Debug instance is there?
1106 if (!is_null($this->getDebugInstance())) {
1107 // Output stub message
1108 $this->debugOutput($message);
1111 trigger_error($message."<br />\n");
1114 // @TODO Finish this part!
1115 $this->partialStub('Developer mode inactive. Message:' . $message);