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, this is free software
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 to an application helper class
29 private static $applicationInstance = null;
32 * The language instance for the template loader
34 private static $langInstance = null;
39 private static $debugInstance = null;
42 * Instance of a request class
44 private $requestInstance = null;
47 * Instance of a response class
49 private $responseInstance = null;
52 * Search criteria instance
54 private $searchInstance = null;
57 * The file I/O instance for the template loader
59 private $fileIoInstance = null;
64 private $resolverInstance = null;
69 private $realClass = "FrameworkSystem";
72 * A human-readable description for this simulator part
74 private $objectDescription = "Namenlose Framework-Einheit";
77 * The unique ID string for identifying all type of classes
79 private $uniqueID = "";
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_DEFAUL_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;
151 * In the super constructor these system classes shall be ignored or else
152 * we would get an endless calling loop.
154 *--------------------------------------------------------------------*
155 * ATTENTION: IF YOU REMOVE ONE OF THEM YOU WILL SHOOT YOUR SERVER!!! *
156 *--------------------------------------------------------------------*
158 private $systemClasses = array(
159 "DebugMiddleware", // Debug middleware output sub-system
160 "Registry", // Object registry
161 "ObjectFactory", // Object factory
162 "DebugWebOutput", // Debug web output sub-system
163 "WebOutput", // Web output sub-system
164 "CompressorChannel", // Compressor sub-system
165 "DebugConsoleOutput", // Debug console output sub-system
166 "DebugErrorLogOutput", // Debug error_log() output sub-system
167 "FrameworkDirectoryPointer", // Directory handler sub-system
168 "NullCompressor", // Null compressor
169 "Bzip2Compressor", // BZIP2 compressor
170 "GzipCompressor", // GZIP compressor
177 * Private super constructor
179 * @param $className Name of the class
182 protected function __construct ($className) {
184 $this->setRealClass($className);
186 // Initialize the class if the registry is there
187 if ((class_exists('Registry')) && (Registry::isInitialized() === false)) {
188 $this->initInstance();
193 * Destructor reached...
197 public function __destruct() {
198 // Is this object already destroyed?
199 if ($this->__toString() != "DestructedObject") {
201 if ((defined('DEBUG_DESTRUCTOR')) && (is_object($this->getDebugInstance()))) {
202 $this->getDebugInstance()->output(sprintf("[%s:] Das Objekt <strong>%s</strong> wird zerstört.",
203 __CLASS__, $this->__toString()
207 // Destroy all informations about this class but keep some text about it alive
208 $this->setObjectDescription(sprintf("Entferntes Objekt <em>%s</em>", $this->__toString()));
209 $this->setRealClass("DestructedObject");
210 $this->resetUniqueID();
211 } elseif ((defined('DEBUG_DESTRUCTOR')) && (is_object($this->getDebugInstance()))) {
212 // Already destructed object
213 $this->getDebugInstance()->output(sprintf("[%s:] Das Objekt <strong>%s</strong> wurde bereits zerstört.",
214 __CLASS__, $this->__toString()
220 * The call method where all non-implemented methods end up
224 public final function __call ($methodName, $args) {
225 // Implode all given arguments
229 $argsString = "NULL";
230 } elseif (is_array($args)) {
231 // Some arguments are there
232 foreach ($args as $arg) {
236 if ($arg) $argsString .= "true(bool)"; else $argsString .= "false(bool)";
237 } elseif (is_int($arg)) {
239 $argsString .= $arg."(int)";
240 } elseif (is_float($arg)) {
242 $argsString .= $arg."(float)";
243 } elseif ($arg instanceof BaseFrameworkSystem) {
244 // Own object instance
245 $argsString .= $arg->__toString()."(Object)";
246 } elseif (is_object($arg)) {
248 $argsString .= "unknown object(!)";
249 } elseif (is_array($arg)) {
251 $argsString .= "Array(array)";
252 } elseif (is_string($arg)) {
254 $argsString .= "\"".$arg."\"(string)";
255 } elseif (is_null($arg)) {
257 $argsString .= "(null)";
259 // Unknown type (please report!)
260 $argsString .= $arg."(unknown!)";
268 if (substr($argsString, -2, 1) === ",") $argsString = substr($argsString, 0, -2);
270 // Invalid arguments!
271 $argsString = sprintf("!INVALID:%s!", $args);
274 // Output stub message
275 $this->getDebugInstance()->output(sprintf("[%s::%s] Stub! Args: %s",
286 * Private initializer for this class
290 private final function initInstance () {
291 // Is this a system class?
292 if (!in_array($this->__toString(), $this->systemClasses)) {
293 // Add application helper to our class
294 $this->systemclasses[] = $this->getConfigInstance()->readConfig('app_helper_class');
296 // Set debug instance
297 $this->setDebugInstance(DebugMiddleware::createDebugMiddleware($this->getConfigInstance()->readConfig('debug_class')));
299 // Get output instance and set it
300 $outputInstance = ObjectFactory::createObjectByConfiguredName('web_engine', array($this->getConfigInstance()->readConfig('web_content_type')));
301 $this->setWebOutputInstance($outputInstance);
303 // Set the compressor channel
304 $this->setCompressorChannel(CompressorChannel::createCompressorChannel(sprintf("%s%s",
306 $this->getConfigInstance()->readConfig('compressor_base_path')
309 // Initialization done! :D
310 Registry::isInitialized("OK");
311 } elseif ($this->__toString() == "DebugMiddleware") {
312 // Set configuration instance
313 $this->setConfigInstance(FrameworkConfiguration::createFrameworkConfiguration());
318 * Setter for search instance
320 * @param $searchInstance Searchable criteria instance
323 public final function setSearchInstance (LocalSearchCriteria $searchInstance) {
324 $this->searchInstance = $searchInstance;
328 * Getter for search instance
330 * @return $searchInstance Searchable criteria instance
332 public final function getSearchInstance () {
333 return $this->searchInstance;
337 * Setter for resolver instance
339 * @param $resolverInstance Instance of a command resolver class
342 public final function setResolverInstance (Resolver $resolverInstance) {
343 $this->resolverInstance = $resolverInstance;
347 * Getter for resolver instance
349 * @return $resolverInstance Instance of a command resolver class
351 public final function getResolverInstance () {
352 return $this->resolverInstance;
356 * Setter for language instance
358 * @param $configInstance The configuration instance which shall
359 * be FrameworkConfiguration
362 public final function setConfigInstance (FrameworkConfiguration $configInstance) {
363 Registry::getRegistry()->addInstance('config', $configInstance);
367 * Getter for configuration instance
369 * @return $cfgInstance Configuration instance
371 protected final function getConfigInstance () {
372 $cfgInstance = Registry::getRegistry()->getInstance('config');
377 * Setter for debug instance
379 * @param $debugInstance The instance for debug output class
382 public final function setDebugInstance (DebugMiddleware $debugInstance) {
383 self::$debugInstance = $debugInstance;
387 * Getter for debug instance
389 * @return $debugInstance Instance to class DebugConsoleOutput or DebugWebOutput
391 public final function getDebugInstance () {
392 return self::$debugInstance;
396 * Setter for web output instance
398 * @param $webInstance The instance for web output class
401 public final function setWebOutputInstance (OutputStreamer $webInstance) {
402 Registry::getRegistry()->addInstance('web_output', $webInstance);
406 * Getter for web output instance
408 * @return $webOutput - Instance to class WebOutput
410 public final function getWebOutputInstance () {
411 return Registry::getRegistry()->getInstance('web_output');
415 * Setter for database instance
417 * @param $dbInstance The instance for the database connection
418 * (forced DatabaseConnection)
421 public final function setDatabaseInstance (DatabaseConnection $dbInstance) {
422 Registry::getRegistry()->addInstance('dbInstance', $dbInstance);
426 * Getter for database layer
428 * @return $dbInstance The database layer instance
430 public final function getDatabaseInstance () {
431 if ((class_exists('Registry')) && (Registry::isInitialized() === true)) {
432 return Registry::getRegistry()->getInstance('dbInstance');
439 * Setter for compressor channel
441 * @param $compressorChannel An instance of CompressorChannel
444 public final function setCompressorChannel (CompressorChannel $compressorChannel) {
445 Registry::getRegistry()->addInstance('compressor', $compressorChannel);
449 * Getter for compressor channel
451 * @return $compressor The compressor channel
453 public final function getCompressorChannel () {
454 return Registry::getRegistry()->getInstance('compressor');
458 * Protected getter for a manageable application helper class
460 * @return $applicationInstance An instance of a manageable application helper class
462 protected final function getApplicationInstance () {
463 return self::$applicationInstance;
467 * Setter for a manageable application helper class
469 * @param $applicationInstance An instance of a manageable application helper class
472 public final function setApplicationInstance (ManageableApplication $applicationInstance) {
473 self::$applicationInstance = $applicationInstance;
477 * Setter for request instance
479 * @param $requestInstance An instance of a Requestable class
482 public final function setRequestInstance (Requestable $requestInstance) {
483 $this->requestInstance = $requestInstance;
487 * Getter for request instance
489 * @return $requestInstance An instance of a Requestable class
491 public final function getRequestInstance () {
492 return $this->requestInstance;
496 * Setter for response instance
498 * @param $responseInstance An instance of a Responseable class
501 public final function setResponseInstance (Responseable $responseInstance) {
502 $this->responseInstance = $responseInstance;
506 * Getter for response instance
508 * @return $responseInstance An instance of a Responseable class
510 public final function getResponseInstance () {
511 return $this->responseInstance;
515 * Getter for $realClass
517 * @return $realClass The name of the real class (not BaseFrameworkSystem)
519 public final function __toString () {
520 return $this->realClass;
524 * Setter for the real class name
526 * @param $realClass Class name (string)
529 public final function setRealClass ($realClass) {
531 $realClass = (string) $realClass;
534 $this->realClass = $realClass;
538 * Generate unique ID from a lot entropy
542 public final function generateUniqueId () {
543 // Is the id set for this class?
544 if (empty($this->uniqueID)) {
546 // Correct missing class name
548 if ($this->__toString() == "") {
549 $this->setRealClass(__CLASS__);
553 // Cache datbase instance
554 $db = $this->getDatabaseInstance();
559 // Generate a unique ID number
560 $tempID = $this->generateIdNumber();
563 // Try to figure out if the ID number is not yet used
565 // Is this a registry?
566 if ($this->__toString() == "Registry") {
567 // Registry, then abort here
569 } elseif (is_object($db)) {
570 $isUsed = $db->isUniqueIdUsed($tempID, true);
572 } catch (FrameworkException $e) {
573 // Catches all and ignores all ;-)
597 $this->setUniqueID($tempID);
599 // Revert maybe corrected class name
601 $this->setRealClass("");
604 // Remove system classes if we are in a system class
605 if ((isset($this->systemClasses)) && (in_array($this->__toString(), $this->systemClasses))) {
606 // This may save some RAM...
607 $this->removeSystemArray();
613 * Generates a new ID number for classes based from the class' real name,
614 * the description and some random data
616 * @return $tempID The new (temporary) ID number
618 private final function generateIdNumber () {
619 return sprintf("%s@%s",
621 md5(sprintf("%s:%s:%s:%s:%s:%s",
623 $this->getObjectDescription(),
625 getenv('REMOTE_ADDR'),
626 getenv('SERVER_ADDR'),
633 * Setter for unique ID
635 * @param $uniqueID The newly generated unique ID number
638 private final function setUniqueID ($uniqueID) {
640 $uniqueID = (string) $uniqueID;
643 $this->uniqueID = $uniqueID;
647 * Getter for unique ID
649 * @return $uniqueID The unique ID of this class
651 public final function getUniqueID () {
652 return $this->uniqueID;
656 * Resets or recreates the unique ID number
660 public final function resetUniqueID() {
661 // Sweet and simple... ;-)
662 $newUniqueID = $this->generateIdNumber();
663 $this->setUniqueID($newUniqueID);
667 * Getter for simulator description
669 * @return $objectDescription The description of this simulation part
671 public final function getObjectDescription () {
672 if (isset($this->objectDescription)) {
673 return $this->objectDescription;
680 * Setter for simulation part description
682 * @param $objectDescription The description as string for this simulation part
685 public final function setObjectDescription ($objectDescription) {
686 $this->objectDescription = (String) $objectDescription;
690 * Validate if given object is the same as current
692 * @param $object An object instance for comparison with this class
693 * @return boolean The result of comparing both's unique ID
695 public final function equals (FrameworkInterface $object) {
696 return ($this->getUniqueID() == $object->getUniqueID());
700 * Compare if both simulation part description and class name matches
703 * @param $itemInstance An object instance to an other class
704 * @return boolean The result of comparing class name simulation part description
706 public function itemMatches ($itemInstance) {
709 $this->__toString() == $itemInstance->__toString()
711 $this->getObjectDescription() == $itemInstance->getObjectDescription()
717 * Compare class name of this and given class name
719 * @param $className The class name as string from the other class
720 * @return boolean The result of comparing both class names
722 public final function isClass ($className) {
723 return ($this->__toString() == $className);
727 * Stub method (only real cabins shall override it)
729 * @return boolean false = is no cabin, true = is a cabin
731 public function isCabin () {
736 * Stub method for tradeable objects
738 * @return boolean false = is not tradeable by the Merchant class,
739 * true = is a tradeable object
741 public function isTradeable () {
746 * Formats computer generated price values into human-understandable formats
747 * with thousand and decimal seperators.
749 * @param $value The in computer format value for a price
750 * @param $currency The currency symbol (use HTML-valid characters!)
751 * @param $decNum Number of decimals after commata
752 * @return $price The for the current language formated price string
753 * @throws MissingDecimalsThousandsSeperatorException If decimals or
754 * thousands seperator
757 public function formatCurrency ($value, $currency = "€", $decNum = 2) {
758 // Are all required attriutes set?
759 if ((!isset($this->decimals)) || (!isset($this->thousands))) {
760 // Throw an exception
761 throw new MissingDecimalsThousandsSeperatorException($this, self::EXCEPTION_ATTRIBUTES_ARE_MISSING);
765 $value = (float) $value;
767 // Reformat the US number
768 $price = sprintf("%s %s",
769 number_format($value, $decNum, $this->decimals, $this->thousands),
773 // Return as string...
778 * Removes number formating characters
782 public final function removeNumberFormaters () {
783 unset($this->thousands);
784 unset($this->decimals);
788 * Private getter for language instance
790 * @return $langInstance An instance to the language sub-system
792 protected final function getLanguageInstance () {
793 return self::$langInstance;
797 * Setter for language instance
799 * @param $langInstance An instance to the language sub-system
801 * @see LanguageSystem
803 public final function setLanguageInstance (ManageableLanguage $langInstance) {
804 self::$langInstance = $langInstance;
808 * Remove the $systemClasses array from memory
812 public final function removeSystemArray () {
813 unset($this->systemClasses);
817 * Create a file name and path name from the object's unique ID number.
818 * The left part of the ID shall always be a valid class name and the
819 * right part an ID number.
821 * @return $pfn The file name with a prepended path name
822 * @throws NoArrayCreatedException If explode() fails to create an array
823 * @throws InvalidArrayCountException If the array contains less or
824 * more than two elements
826 public final function getPathFileNameFromObject () {
827 // Get the main object's unique ID. We use this as a path/filename combination
828 $pathFile = $this->getUniqueID();
830 // Split it up in path and file name
831 $pathFile = explode("@", $pathFile);
833 // Are there two elements? Index 0 is the path, 1 the file name + global extension
834 if (!is_array($pathFile)) {
836 throw new NoArrayCreatedException(array($this, "pathFile"), self::EXCEPTION_ARRAY_EXPECTED);
837 } elseif (count($pathFile) != 2) {
838 // Invalid ID returned!
839 throw new InvalidArrayCountException(array($this, "pathFile", count($pathFile), 2), self::EXCEPTION_ARRAY_HAS_INVALID_COUNT);
842 // Auto-append missing trailing slash
843 $pathFile[0] = $this->addMissingTrailingSlash($pathFile[0]);
845 // Create the file name and return it
846 $pfn = ($pathFile[0] . $pathFile[1]);
851 * Appends a trailing slash to a string
853 * @param $str A string (maybe) without trailing slash
854 * @return $str A string with an auto-appended trailing slash
856 public final function addMissingTrailingSlash ($str) {
857 // Is there a trailing slash?
858 if (substr($str, -1, 1) != "/") $str .= "/";
863 * Private getter for file IO instance
865 * @return $fileIoInstance An instance to the file I/O sub-system
867 protected final function getFileIoInstance () {
868 return $this->fileIoInstance;
872 * Setter for file I/O instance
874 * @param $fileIoInstance An instance to the file I/O sub-system
877 public final function setFileIoInstance (FileIoHandler $fileIoInstance) {
878 $this->fileIoInstance = $fileIoInstance;
882 * Prepare the template engine (TemplateEngine by default) for a given
883 * application helper instance (ApplicationHelper by default).
885 * @param $appInstance An application helper instance or
886 * null if we shall use the default
887 * @return $tplEngine The template engine instance
888 * @throws NullPointerException If the template engine could not
890 * @throws UnsupportedTemplateEngineException If $tplEngine is an
891 * unsupported template engine
892 * @throws MissingLanguageHandlerException If the language sub-system
893 * is not yet initialized
894 * @throws NullPointerException If the discovered application
895 * instance is still null
897 protected function prepareTemplateEngine (BaseFrameworkSystem $appInstance=null) {
898 // Is the application instance set?
899 if (is_null($appInstance)) {
900 // Get the current instance
901 $appInstance = $this->getApplicationInstance();
904 if (is_null($appInstance)) {
905 // Thrown an exception
906 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
910 // Generate FQFN for all application templates
911 $fqfn = sprintf("%s%s/%s/%s",
913 $this->getConfigInstance()->readConfig('application_path'),
914 strtolower($appInstance->getAppShortName()),
915 $this->getConfigInstance()->readConfig('tpl_base_path')
918 // Are both instances set?
919 if ($appInstance->getLanguageInstance() === null) {
920 // Invalid language instance
921 throw new MissingLanguageHandlerException($appInstance, self::EXCEPTION_MISSING_LANGUAGE_HANDLER);
922 } elseif ($appInstance->getFileIoInstance() === null) {
923 // Invalid language instance
924 throw new MissingFileIoHandlerException($appInstance, self::EXCEPTION_MISSING_FILE_IO_HANDLER);
927 // Initialize the template engine
928 $tplEngine = ObjectFactory::createObjectByConfiguredName('template_class', array($fqfn, $appInstance->getLanguageInstance(), $appInstance->getFileIoInstance()));
930 // Return the prepared instance
935 * Debugs this instance by putting out it's full content
939 public final function debugInstance () {
940 // Generate the output
941 $content = sprintf("<pre>%s</pre>",
942 trim(print_r($this, true))
946 ApplicationEntryPoint::app_die(sprintf("<strong>%s debug output:</strong><div id=\"debug_content\">%s</div>Loaded includes: <div id=\"debug_include_list\">%s</div>",
949 ClassLoader::getInstance()->getPrintableIncludeList()
954 * Output a partial stub message for the caller method
956 * @param $message An optional message to display
959 protected function partialStub ($message = "") {
961 $backtrace = debug_backtrace();
963 // Generate the class::method string
964 $methodName = "UnknownClass::unknownMethod";
965 if ((isset($backtrace[1]['class'])) && (isset($backtrace[1]['function']))) {
966 $methodName = $backtrace[1]['class']."::".$backtrace[1]['function'];
969 // Construct the full message
970 $stubMessage = sprintf("[%s:] Partial stub!",
974 // Is the extra message given?
975 if (!empty($message)) {
976 // Then add it as well
977 $stubMessage .= sprintf(" Message: <span id=\"stub_message\">%s</span>", $message);
980 // Debug instance is there?
981 if (!is_null($this->getDebugInstance())) {
982 // Output stub message
983 $this->getDebugInstance()->output($stubMessage);
986 trigger_error($stubMessage."<br />\n");
991 * Outputs a debug backtrace and stops further script execution
995 public function debugBacktrace () {
996 // Sorry, there is no other way getting this nice backtrace
998 debug_print_backtrace();
1004 * Outputs a debug message wether to debug instance (should be set!) or dies with or pints the message
1006 * @param $message Message we shall send out...
1007 * @param $doPrint Wether we shall print or die here which last is the default
1010 public function debugOutput ($message, $doPrint = false) {
1011 // Get debug instance
1012 $debugInstance = $this->getDebugInstance();
1014 // Is the debug instance there?
1015 if (is_object($debugInstance)) {
1016 // Use debug output handler
1017 $debugInstance->output($message);
1018 if (!$doPrint) die(); // Die here if not printed
1021 // DO NOT REWRITE THIS TO app_die() !!!
1031 * Converts e.g. a command from URL to a valid class by keeping out bad characters
1033 * @param $str The string, what ever it is needs to be converted
1034 * @return $className Generated class name
1036 public function convertToClassName ($str) {
1040 // Convert all dashes in underscores
1041 $str = str_replace("-", "_", $str);
1043 // Now use that underscores to get classname parts for hungarian style
1044 foreach (explode("_", $str) as $strPart) {
1045 // Make the class name part lower case and first upper case
1046 $className .= ucfirst(strtolower($strPart));
1049 // Return class name
1054 * Marks up the code by adding e.g. line numbers
1056 * @param $phpCode Unmarked PHP code
1057 * @return $markedCode Marked PHP code
1059 public function markupCode ($phpCode) {
1061 $errorArray = error_get_last();
1063 // Init the code with error message
1065 if (is_array($errorArray)) {
1067 $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>",
1068 basename($errorArray['file']),
1069 $errorArray['line'],
1070 $errorArray['message'],
1075 // Add line number to the code
1076 foreach (explode("\n", $phpCode) as $lineNo=>$code) {
1078 $markedCode .= sprintf("<span id=\"code_line\">%s</span>: %s\n",
1080 htmlentities($code, ENT_QUOTES)