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;
67 * Template engine instance
69 private $templateInstance = null;
74 private $realClass = "FrameworkSystem";
77 * A human-readable description for this simulator part
79 private $objectDescription = "Namenlose Framework-Einheit";
82 * The unique ID string for identifying all type of classes
84 private $uniqueID = "";
89 private $thousands = "."; // German
94 private $decimals = ","; // German
96 /***********************
97 * Exception codes.... *
98 ***********************/
100 const EXCEPTION_IS_NULL_POINTER = 0x001;
101 const EXCEPTION_IS_NO_OBJECT = 0x002;
102 const EXCEPTION_IS_NO_ARRAY = 0x003;
103 const EXCEPTION_MISSING_METHOD = 0x004;
104 const EXCEPTION_CLASSES_NOT_MATCHING = 0x005;
105 const EXCEPTION_INDEX_OUT_OF_BOUNDS = 0x006;
106 const EXCEPTION_DIMENSION_ARRAY_INVALID = 0x007;
107 const EXCEPTION_ITEM_NOT_TRADEABLE = 0x008;
108 const EXCEPTION_ITEM_NOT_IN_PRICE_LIST = 0x009;
109 const EXCEPTION_GENDER_IS_WRONG = 0x00a;
110 const EXCEPTION_BIRTH_DATE_IS_INVALID = 0x00b;
111 const EXCEPTION_EMPTY_STRUCTURES_ARRAY = 0x00c;
112 const EXCEPTION_HAS_ALREADY_PERSONELL_LIST = 0x00d;
113 const EXCEPTION_NOT_ENOUGTH_UNEMPLOYEES = 0x00e;
114 const EXCEPTION_TOTAL_PRICE_NOT_CALCULATED = 0x00f;
115 const EXCEPTION_HARBOR_HAS_NO_SHIPYARDS = 0x010;
116 const EXCEPTION_CONTRACT_PARTNER_INVALID = 0x011;
117 const EXCEPTION_CONTRACT_PARTNER_MISMATCH = 0x012;
118 const EXCEPTION_CONTRACT_ALREADY_SIGNED = 0x013;
119 const EXCEPTION_UNEXPECTED_EMPTY_STRING = 0x014;
120 const EXCEPTION_PATH_NOT_FOUND = 0x015;
121 const EXCEPTION_INVALID_PATH_NAME = 0x016;
122 const EXCEPTION_READ_PROTECED_PATH = 0x017;
123 const EXCEPTION_WRITE_PROTECED_PATH = 0x018;
124 const EXCEPTION_DIR_POINTER_INVALID = 0x019;
125 const EXCEPTION_FILE_POINTER_INVALID = 0x01a;
126 const EXCEPTION_INVALID_DIRECTORY_POINTER = 0x01b;
127 const EXCEPTION_UNEXPECTED_OBJECT = 0x01c;
128 const EXCEPTION_LIMIT_ELEMENT_IS_UNSUPPORTED = 0x01d;
129 const EXCEPTION_GETTER_IS_MISSING = 0x01e;
130 const EXCEPTION_ARRAY_EXPECTED = 0x01f;
131 const EXCEPTION_ARRAY_HAS_INVALID_COUNT = 0x020;
132 const EXCEPTION_ID_IS_INVALID_FORMAT = 0x021;
133 const EXCEPTION_MD5_CHECKSUMS_MISMATCH = 0x022;
134 const EXCEPTION_UNEXPECTED_STRING_SIZE = 0x023;
135 const EXCEPTION_SIMULATOR_ID_INVALID = 0x024;
136 const EXCEPTION_MISMATCHING_COMPRESSORS = 0x025;
137 const EXCEPTION_CONTAINER_ITEM_IS_NULL = 0x026;
138 const EXCEPTION_ITEM_IS_NO_ARRAY = 0x027;
139 const EXCEPTION_CONTAINER_MAYBE_DAMAGED = 0x028;
140 const EXCEPTION_INVALID_STRING = 0x029;
141 const EXCEPTION_VARIABLE_NOT_SET = 0x02a;
142 const EXCEPTION_ATTRIBUTES_ARE_MISSING = 0x02b;
143 const EXCEPTION_ARRAY_ELEMENTS_MISSING = 0x02c;
144 const EXCEPTION_TEMPLATE_ENGINE_UNSUPPORTED = 0x02d;
145 const EXCEPTION_MISSING_LANGUAGE_HANDLER = 0x02e;
146 const EXCEPTION_MISSING_FILE_IO_HANDLER = 0x02f;
147 const EXCEPTION_MISSING_ELEMENT = 0x030;
148 const EXCEPTION_HEADERS_ALREADY_SENT = 0x031;
149 const EXCEPTION_DEFAULT_CONTROLLER_GONE = 0x032;
150 const EXCEPTION_CLASS_NOT_FOUND = 0x033;
151 const EXCEPTION_REQUIRED_INTERFACE_MISSING = 0x034;
152 const EXCEPTION_FATAL_ERROR = 0x035;
153 const EXCEPTION_FILE_NOT_FOUND = 0x036;
154 const EXCEPTION_ASSERTION_FAILED = 0x037;
155 const EXCEPTION_FILE_CANNOT_BE_READ = 0x038;
158 * In the super constructor these system classes shall be ignored or else
159 * we would get an endless calling loop.
161 *--------------------------------------------------------------------*
162 * ATTENTION: IF YOU REMOVE ONE OF THEM YOU WILL SHOOT YOUR SERVER!!! *
163 *--------------------------------------------------------------------*
165 private $systemClasses = array(
166 "DebugMiddleware", // Debug middleware output sub-system
167 "Registry", // Object registry
168 "ObjectFactory", // Object factory
169 "DebugWebOutput", // Debug web output sub-system
170 "WebOutput", // Web output sub-system
171 "CompressorChannel", // Compressor sub-system
172 "DebugConsoleOutput", // Debug console output sub-system
173 "DebugErrorLogOutput", // Debug error_log() output sub-system
174 "FrameworkDirectoryPointer", // Directory handler sub-system
175 "NullCompressor", // Null compressor
176 "Bzip2Compressor", // BZIP2 compressor
177 "GzipCompressor", // GZIP compressor
184 * Private super constructor
186 * @param $className Name of the class
189 protected function __construct ($className) {
191 $this->setRealClass($className);
193 // Initialize the class if the registry is there
194 if ((class_exists('Registry')) && (Registry::isInitialized() === false)) {
195 $this->initInstance();
200 * Destructor reached...
204 public function __destruct() {
205 // Is this object already destroyed?
206 if ($this->__toString() != 'DestructedObject') {
207 // Destroy all informations about this class but keep some text about it alive
208 $this->setObjectDescription(sprintf("Removed object <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)";
258 } elseif (is_resource($arg)) {
260 $argsString .= "(resource)";
262 // Unknown type (please report!)
263 $argsString .= $arg."(<em>unknown!</em>)";
271 if (substr($argsString, -2, 1) === ",") {
272 $argsString = substr($argsString, 0, -2);
275 // Invalid arguments!
276 $argsString = sprintf("!INVALID:%s!", $args);
279 // Output stub message
280 $this->getDebugInstance()->output(sprintf("[%s->%s] Stub! Args: %s",
291 * Private initializer for this class
295 private final function initInstance () {
296 // Is this a system class?
297 if (!in_array($this->__toString(), $this->systemClasses)) {
298 // Add application helper to our class
299 $this->systemclasses[] = $this->getConfigInstance()->readConfig('app_helper_class');
301 // Set debug instance
302 $this->setDebugInstance(DebugMiddleware::createDebugMiddleware($this->getConfigInstance()->readConfig('debug_class')));
304 // Get output instance and set it
305 $outputInstance = ObjectFactory::createObjectByConfiguredName('web_engine', array($this->getConfigInstance()->readConfig('web_content_type')));
306 $this->setWebOutputInstance($outputInstance);
308 // Set the compressor channel
309 $this->setCompressorChannel(CompressorChannel::createCompressorChannel(sprintf("%s%s",
311 $this->getConfigInstance()->readConfig('compressor_base_path')
314 // Initialization done! :D
315 Registry::isInitialized('OK');
316 } elseif ($this->__toString() == 'DebugMiddleware') {
317 // Set configuration instance
318 $this->setConfigInstance(FrameworkConfiguration::createFrameworkConfiguration());
323 * Setter for template engine instances
325 * @param $templateInstance An instance of a template engine class
328 protected final function setTemplateInstance (CompileableTemplate $templateInstance) {
329 $this->templateInstance = $templateInstance;
333 * Getter for template engine instances
335 * @return $templateInstance An instance of a template engine class
337 protected final function getTemplateInstance () {
338 return $this->templateInstance;
342 * Setter for search instance
344 * @param $searchInstance Searchable criteria instance
347 public final function setSearchInstance (LocalSearchCriteria $searchInstance) {
348 $this->searchInstance = $searchInstance;
352 * Getter for search instance
354 * @return $searchInstance Searchable criteria instance
356 public final function getSearchInstance () {
357 return $this->searchInstance;
361 * Setter for resolver instance
363 * @param $resolverInstance Instance of a command resolver class
366 public final function setResolverInstance (Resolver $resolverInstance) {
367 $this->resolverInstance = $resolverInstance;
371 * Getter for resolver instance
373 * @return $resolverInstance Instance of a command resolver class
375 public final function getResolverInstance () {
376 return $this->resolverInstance;
380 * Setter for language instance
382 * @param $configInstance The configuration instance which shall
383 * be FrameworkConfiguration
386 public final function setConfigInstance (FrameworkConfiguration $configInstance) {
387 Registry::getRegistry()->addInstance('config', $configInstance);
391 * Getter for configuration instance
393 * @return $cfgInstance Configuration instance
395 public final function getConfigInstance () {
396 $cfgInstance = Registry::getRegistry()->getInstance('config');
401 * Setter for debug instance
403 * @param $debugInstance The instance for debug output class
406 public final function setDebugInstance (DebugMiddleware $debugInstance) {
407 self::$debugInstance = $debugInstance;
411 * Getter for debug instance
413 * @return $debugInstance Instance to class DebugConsoleOutput or DebugWebOutput
415 public final function getDebugInstance () {
416 return self::$debugInstance;
420 * Setter for web output instance
422 * @param $webInstance The instance for web output class
425 public final function setWebOutputInstance (OutputStreamer $webInstance) {
426 Registry::getRegistry()->addInstance('web_output', $webInstance);
430 * Getter for web output instance
432 * @return $webOutput - Instance to class WebOutput
434 public final function getWebOutputInstance () {
435 return Registry::getRegistry()->getInstance('web_output');
439 * Setter for database instance
441 * @param $dbInstance The instance for the database connection
442 * (forced DatabaseConnection)
445 public final function setDatabaseInstance (DatabaseConnection $dbInstance) {
446 Registry::getRegistry()->addInstance('dbInstance', $dbInstance);
450 * Getter for database layer
452 * @return $dbInstance The database layer instance
454 public final function getDatabaseInstance () {
455 if ((class_exists('Registry')) && (Registry::isInitialized() === true)) {
456 return Registry::getRegistry()->getInstance('dbInstance');
463 * Setter for compressor channel
465 * @param $compressorChannel An instance of CompressorChannel
468 public final function setCompressorChannel (CompressorChannel $compressorChannel) {
469 Registry::getRegistry()->addInstance('compressor', $compressorChannel);
473 * Getter for compressor channel
475 * @return $compressor The compressor channel
477 public final function getCompressorChannel () {
478 return Registry::getRegistry()->getInstance('compressor');
482 * Protected getter for a manageable application helper class
484 * @return $applicationInstance An instance of a manageable application helper class
486 protected final function getApplicationInstance () {
487 return self::$applicationInstance;
491 * Setter for a manageable application helper class
493 * @param $applicationInstance An instance of a manageable application helper class
496 public final function setApplicationInstance (ManageableApplication $applicationInstance) {
497 self::$applicationInstance = $applicationInstance;
501 * Setter for request instance
503 * @param $requestInstance An instance of a Requestable class
506 public final function setRequestInstance (Requestable $requestInstance) {
507 $this->requestInstance = $requestInstance;
511 * Getter for request instance
513 * @return $requestInstance An instance of a Requestable class
515 public final function getRequestInstance () {
516 return $this->requestInstance;
520 * Setter for response instance
522 * @param $responseInstance An instance of a Responseable class
525 public final function setResponseInstance (Responseable $responseInstance) {
526 $this->responseInstance = $responseInstance;
530 * Getter for response instance
532 * @return $responseInstance An instance of a Responseable class
534 public final function getResponseInstance () {
535 return $this->responseInstance;
539 * Getter for $realClass
541 * @return $realClass The name of the real class (not BaseFrameworkSystem)
543 public final function __toString () {
544 return $this->realClass;
548 * Setter for the real class name
550 * @param $realClass Class name (string)
553 public final function setRealClass ($realClass) {
555 $realClass = (string) $realClass;
558 $this->realClass = $realClass;
562 * Generate unique ID from a lot entropy
566 public final function generateUniqueId () {
567 // Is the id set for this class?
568 if (empty($this->uniqueID)) {
570 // Correct missing class name
572 if ($this->__toString() == "") {
573 $this->setRealClass(__CLASS__);
577 // Cache datbase instance
578 $db = $this->getDatabaseInstance();
583 // Generate a unique ID number
584 $tempID = $this->generateIdNumber();
587 // Try to figure out if the ID number is not yet used
589 // Is this a registry?
590 if ($this->__toString() == "Registry") {
591 // Registry, then abort here
593 } elseif (is_object($db)) {
594 $isUsed = $db->isUniqueIdUsed($tempID, true);
596 } catch (FrameworkException $e) {
597 // Catches all and ignores all ;-)
621 $this->setUniqueID($tempID);
623 // Revert maybe corrected class name
625 $this->setRealClass("");
628 // Remove system classes if we are in a system class
629 if ((isset($this->systemClasses)) && (in_array($this->__toString(), $this->systemClasses))) {
630 // This may save some RAM...
631 $this->removeSystemArray();
637 * Generates a new ID number for classes based from the class' real name,
638 * the description and some random data
640 * @return $tempID The new (temporary) ID number
642 private final function generateIdNumber () {
643 return sprintf("%s@%s",
645 md5(sprintf("%s:%s:%s:%s:%s:%s",
647 $this->getObjectDescription(),
649 getenv('REMOTE_ADDR'),
650 getenv('SERVER_ADDR'),
657 * Setter for unique ID
659 * @param $uniqueID The newly generated unique ID number
662 private final function setUniqueID ($uniqueID) {
664 $uniqueID = (string) $uniqueID;
667 $this->uniqueID = $uniqueID;
671 * Getter for unique ID
673 * @return $uniqueID The unique ID of this class
675 public final function getUniqueID () {
676 return $this->uniqueID;
680 * Resets or recreates the unique ID number
684 public final function resetUniqueID() {
685 // Sweet and simple... ;-)
686 $newUniqueID = $this->generateIdNumber();
687 $this->setUniqueID($newUniqueID);
691 * Getter for simulator description
693 * @return $objectDescription The description of this simulation part
695 public final function getObjectDescription () {
696 if (isset($this->objectDescription)) {
697 return $this->objectDescription;
704 * Setter for simulation part description
706 * @param $objectDescription The description as string for this simulation part
709 public final function setObjectDescription ($objectDescription) {
710 $this->objectDescription = (String) $objectDescription;
714 * Validate if given object is the same as current
716 * @param $object An object instance for comparison with this class
717 * @return boolean The result of comparing both's unique ID
719 public final function equals (FrameworkInterface $object) {
720 return ($this->getUniqueID() == $object->getUniqueID());
724 * Compare if both simulation part description and class name matches
727 * @param $itemInstance An object instance to an other class
728 * @return boolean The result of comparing class name simulation part description
730 public function itemMatches ($itemInstance) {
733 $this->__toString() == $itemInstance->__toString()
735 $this->getObjectDescription() == $itemInstance->getObjectDescription()
741 * Compare class name of this and given class name
743 * @param $className The class name as string from the other class
744 * @return boolean The result of comparing both class names
746 public final function isClass ($className) {
747 return ($this->__toString() == $className);
751 * Stub method (only real cabins shall override it)
753 * @return boolean false = is no cabin, true = is a cabin
755 public function isCabin () {
760 * Stub method for tradeable objects
762 * @return boolean false = is not tradeable by the Merchant class,
763 * true = is a tradeable object
765 public function isTradeable () {
770 * Formats computer generated price values into human-understandable formats
771 * with thousand and decimal seperators.
773 * @param $value The in computer format value for a price
774 * @param $currency The currency symbol (use HTML-valid characters!)
775 * @param $decNum Number of decimals after commata
776 * @return $price The for the current language formated price string
777 * @throws MissingDecimalsThousandsSeperatorException If decimals or
778 * thousands seperator
781 public function formatCurrency ($value, $currency = "€", $decNum = 2) {
782 // Are all required attriutes set?
783 if ((!isset($this->decimals)) || (!isset($this->thousands))) {
784 // Throw an exception
785 throw new MissingDecimalsThousandsSeperatorException($this, self::EXCEPTION_ATTRIBUTES_ARE_MISSING);
789 $value = (float) $value;
791 // Reformat the US number
792 $price = sprintf("%s %s",
793 number_format($value, $decNum, $this->decimals, $this->thousands),
797 // Return as string...
802 * Removes number formating characters
806 public final function removeNumberFormaters () {
807 unset($this->thousands);
808 unset($this->decimals);
812 * Private getter for language instance
814 * @return $langInstance An instance to the language sub-system
816 protected final function getLanguageInstance () {
817 return self::$langInstance;
821 * Setter for language instance
823 * @param $langInstance An instance to the language sub-system
825 * @see LanguageSystem
827 public final function setLanguageInstance (ManageableLanguage $langInstance) {
828 self::$langInstance = $langInstance;
832 * Remove the $systemClasses array from memory
836 public final function removeSystemArray () {
837 unset($this->systemClasses);
841 * Create a file name and path name from the object's unique ID number.
842 * The left part of the ID shall always be a valid class name and the
843 * right part an ID number.
845 * @return $pfn The file name with a prepended path name
846 * @throws NoArrayCreatedException If explode() fails to create an array
847 * @throws InvalidArrayCountException If the array contains less or
848 * more than two elements
850 public final function getPathFileNameFromObject () {
851 // Get the main object's unique ID. We use this as a path/filename combination
852 $pathFile = $this->getUniqueID();
854 // Split it up in path and file name
855 $pathFile = explode("@", $pathFile);
857 // Are there two elements? Index 0 is the path, 1 the file name + global extension
858 if (!is_array($pathFile)) {
860 throw new NoArrayCreatedException(array($this, 'pathFile'), self::EXCEPTION_ARRAY_EXPECTED);
861 } elseif (count($pathFile) != 2) {
862 // Invalid ID returned!
863 throw new InvalidArrayCountException(array($this, 'pathFile', count($pathFile), 2), self::EXCEPTION_ARRAY_HAS_INVALID_COUNT);
866 // Auto-append missing trailing slash
867 $pathFile[0] = $this->addMissingTrailingSlash($pathFile[0]);
869 // Create the file name and return it
870 $pfn = ($pathFile[0] . $pathFile[1]);
875 * Appends a trailing slash to a string
877 * @param $str A string (maybe) without trailing slash
878 * @return $str A string with an auto-appended trailing slash
880 public final function addMissingTrailingSlash ($str) {
881 // Is there a trailing slash?
882 if (substr($str, -1, 1) != "/") $str .= "/";
887 * Private getter for file IO instance
889 * @return $fileIoInstance An instance to the file I/O sub-system
891 protected final function getFileIoInstance () {
892 return $this->fileIoInstance;
896 * Setter for file I/O instance
898 * @param $fileIoInstance An instance to the file I/O sub-system
901 public final function setFileIoInstance (FileIoHandler $fileIoInstance) {
902 $this->fileIoInstance = $fileIoInstance;
906 * Prepare the template engine (WebTemplateEngine by default) for a given
907 * application helper instance (ApplicationHelper by default).
909 * @param $appInstance An application helper instance or
910 * null if we shall use the default
911 * @return $tplEngine The template engine instance
912 * @throws NullPointerException If the template engine could not
914 * @throws UnsupportedTemplateEngineException If $tplEngine is an
915 * unsupported template engine
916 * @throws MissingLanguageHandlerException If the language sub-system
917 * is not yet initialized
918 * @throws NullPointerException If the discovered application
919 * instance is still null
921 protected function prepareTemplateEngine (BaseFrameworkSystem $appInstance=null) {
922 // Is the application instance set?
923 if (is_null($appInstance)) {
924 // Get the current instance
925 $appInstance = $this->getApplicationInstance();
928 if (is_null($appInstance)) {
929 // Thrown an exception
930 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
934 // Generate FQFN for all application templates
935 $fqfn = sprintf("%s%s/%s/%s",
937 $this->getConfigInstance()->readConfig('application_path'),
938 strtolower($appInstance->getAppShortName()),
939 $this->getConfigInstance()->readConfig('tpl_base_path')
942 // Are both instances set?
943 if ($appInstance->getLanguageInstance() === null) {
944 // Invalid language instance
945 throw new MissingLanguageHandlerException($appInstance, self::EXCEPTION_MISSING_LANGUAGE_HANDLER);
946 } elseif ($appInstance->getFileIoInstance() === null) {
947 // Invalid language instance
948 throw new MissingFileIoHandlerException($appInstance, self::EXCEPTION_MISSING_FILE_IO_HANDLER);
951 // Initialize the template engine
952 $tplEngine = ObjectFactory::createObjectByConfiguredName('template_class', array($fqfn, $appInstance->getLanguageInstance(), $appInstance->getFileIoInstance()));
954 // Return the prepared instance
959 * Debugs this instance by putting out it's full content
963 public final function debugInstance () {
964 // Generate the output
965 $content = sprintf("<pre>%s</pre>",
966 trim(print_r($this, true))
970 ApplicationEntryPoint::app_die(sprintf("<strong>%s debug output:</strong><div id=\"debug_content\">%s</div>Loaded includes: <div id=\"debug_include_list\">%s</div>",
973 ClassLoader::getInstance()->getPrintableIncludeList()
978 * Output a partial stub message for the caller method
980 * @param $message An optional message to display
983 protected function partialStub ($message = "") {
985 $backtrace = debug_backtrace();
987 // Generate the class::method string
988 $methodName = "UnknownClass->unknownMethod";
989 if ((isset($backtrace[1]['class'])) && (isset($backtrace[1]['function']))) {
990 $methodName = $backtrace[1]['class']."->".$backtrace[1]['function'];
993 // Construct the full message
994 $stubMessage = sprintf("[%s:] Partial stub!",
998 // Is the extra message given?
999 if (!empty($message)) {
1000 // Then add it as well
1001 $stubMessage .= sprintf(" Message: <span id=\"stub_message\">%s</span>", $message);
1004 // Debug instance is there?
1005 if (!is_null($this->getDebugInstance())) {
1006 // Output stub message
1007 $this->getDebugInstance()->output($stubMessage);
1010 trigger_error($stubMessage."<br />\n");
1015 * Outputs a debug backtrace and stops further script execution
1019 public function debugBackTrace () {
1020 // Sorry, there is no other way getting this nice backtrace
1022 debug_print_backtrace();
1028 * Outputs a debug message wether to debug instance (should be set!) or dies with or pints the message
1030 * @param $message Message we shall send out...
1031 * @param $doPrint Wether we shall print or die here which last is the default
1034 public function debugOutput ($message, $doPrint = false) {
1035 // Get debug instance
1036 $debugInstance = $this->getDebugInstance();
1038 // Is the debug instance there?
1039 if (is_object($debugInstance)) {
1040 // Use debug output handler
1041 $debugInstance->output($message);
1042 if (!$doPrint) die(); // Die here if not printed
1045 // DO NOT REWRITE THIS TO app_die() !!!
1055 * Converts e.g. a command from URL to a valid class by keeping out bad characters
1057 * @param $str The string, what ever it is needs to be converted
1058 * @return $className Generated class name
1060 public function convertToClassName ($str) {
1064 // Convert all dashes in underscores
1065 $str = str_replace("-", "_", $str);
1067 // Now use that underscores to get classname parts for hungarian style
1068 foreach (explode("_", $str) as $strPart) {
1069 // Make the class name part lower case and first upper case
1070 $className .= ucfirst(strtolower($strPart));
1073 // Return class name
1078 * Marks up the code by adding e.g. line numbers
1080 * @param $phpCode Unmarked PHP code
1081 * @return $markedCode Marked PHP code
1083 public function markupCode ($phpCode) {
1085 $errorArray = error_get_last();
1087 // Init the code with error message
1089 if (is_array($errorArray)) {
1091 $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>",
1092 basename($errorArray['file']),
1093 $errorArray['line'],
1094 $errorArray['message'],
1099 // Add line number to the code
1100 foreach (explode("\n", $phpCode) as $lineNo=>$code) {
1102 $markedCode .= sprintf("<span id=\"code_line\">%s</span>: %s\n",
1104 htmlentities($code, ENT_QUOTES)