/** * Print the stack trace for this exception. * * @param string The format you wish to use for printing. Options * include: * - html * - plain */ public function printStackTrace($format = MO_EXCEPTION_FORMAT) { // exception related properties $class = $this->getFile() != null ? \Mojavi\Util\Toolkit::extractClassName($this->getFile()) : 'N/A'; $class = $class != '' ? $class : 'N/A'; $code = $this->getCode() > 0 ? $this->getCode() : 'N/A'; $file = $this->getFile() != null ? $this->getFile() : 'N/A'; $line = $this->getLine() != null ? $this->getLine() : 'N/A'; $message = $this->getMessage() != null ? $this->getMessage() : 'N/A'; $name = $this->getName(); $traceData = $this->getTrace(); $trace = array(); // lower-case the format to avoid sensitivity issues $format = strtolower($format); if ($trace !== null && count($traceData) > 0) { // format the stack trace for ($i = 0, $z = count($traceData); $i < $z; $i++) { if (!isset($traceData[$i]['file'])) { // no file key exists, skip this index continue; } // grab the class name from the file // (this only works with properly named classes) $tClass = \Mojavi\Util\Toolkit::extractClassName($traceData[$i]['file']); $tFile = $traceData[$i]['file']; $tFunction = $traceData[$i]['function']; $tLine = $traceData[$i]['line']; if ($tClass != null) { $tFunction = $tClass . '::' . $tFunction . '()'; } else { $tFunction = $tFunction . '()'; } if ($format == 'html') { $tFunction = '<strong>' . $tFunction . '</strong>'; } $data = 'at %s in [%s:%s]'; $data = sprintf($data, $tFunction, $tFile, $tLine); $trace[] = $data; } } $output = ""; switch ($format) { case 'html': // print the exception info $output .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/> <title>Mojavi Exception</title> <style type="text/css"> #exception { background-color: #EEEEEE; border: solid 1px #750000; font-family: verdana, helvetica, sans-serif; font-size: 76%; font-style: normal; font-weight: normal; margin: 10px; } #help { color: #750000; font-size: 0.9em; } .message { color: #FF0000; font-weight: bold; } .title { font-size: 1.1em; font-weight: bold; } td { background-color: #EEEEEE; padding: 5px; } th { background-color: #750000; color: #FFFFFF; font-size: 1.2em; font-weight: bold; padding: 5px; text-align: left; } </style> </head> <body> <table id="exception" cellpadding="0" cellspacing="0"> <tr> <th colspan="2">' . $name . '</th> </tr> <tr> <td class="title">Message:</td> <td class="message">' . $message . '</td> </tr> <tr> <td class="title">Code:</td> <td>' . $code . '</td> </tr> <tr> <td class="title">Class:</td> <td>' . $class . '</td> </tr> <tr> <td class="title">File:</td> <td>' . $file . '</td> </tr> <tr> <td class="title">Line:</td> <td>' . $line . '</td> </tr>'; if (count($trace) > 0) { $output .= '<tr> <th colspan="2">Stack Trace</th> </tr>'; foreach ($trace as $line) { $output .= '<tr> <td colspan="2">' . $line . '</td> </tr>'; } } $output .= '<tr> <th colspan="2">Info</th> </tr> <tr> <td class="title">Mojavi Version:</td> <td>' . MO_APP_VERSION . '</td> </tr> <tr> <td class="title">PHP Version:</td> <td>' . PHP_VERSION . '</td> </tr> <tr id="help"> <td colspan="2"> For help resolving this issue, please visit <a href="http://www.mojavi.org">www.mojavi.org</a>. </td> </tr> </table> </body> </html>'; echo $output; break; case 'console': $output .= "\n" . \Mojavi\Util\StringTools::consoleColor($message, \Mojavi\Util\StringTools::CONSOLE_COLOR_RED); $output .= "\n\tfrom {$class} in [{$file}:{$line}]"; if (count($trace) > 0) { foreach ($trace as $line) { $output .= "\n\t{$line}"; } } echo $output . "\n"; break; case 'json': $ret_val = array('message' => $message); $output = "from {$class} in [{$file}:{$line}]"; if (count($trace) > 0) { foreach ($trace as $line) { $output .= "\n{$line}"; } } $ret_val['stack_trace'] = $output; return json_encode($ret_val); break; case 'plain': default: $output .= $message; $output .= "\n\tfrom {$class} in [{$file}:{$line}]"; if (count($trace) > 0) { foreach ($trace as $line) { $output .= "\n\t{$line}"; } } return $output; break; } exit; }
/** * Set the template for this view. * * If the template path is relative, it will be based on the currently * executing module's template sub-directory. * * @param string An absolute or relative filesystem path to a template. * * @return void */ public function setTemplate($template) { if (Toolkit::isPathAbsolute($template)) { $this->directory = dirname($template); $this->template = basename($template); } else { $this->template = $template; } }
/** * Replace a relative filesystem path with an absolute one. * * @param string A relative filesystem path. * * @return string The new path. */ public static function &replacePath($path) { if (!Toolkit::isPathAbsolute($path)) { // not an absolute path so we'll prepend to it $path = MO_WEBAPP_DIR . '/' . $path; } return $path; }
/** * Check to see if a configuration file has been modified and if so * recompile the cache file associated with it. * * If the configuration file path is relative, the path itself is relative * to the Mojavi MO_WEBAPP_DIR application setting. * * @param string A filesystem path to a configuration file. * * @return string An absolute filesystem path to the cache filename * associated with this specified configuration file. * * @throws <b>ConfigurationException</b> If a requested configuration file * does not exist. */ public static function checkConfig($config) { // the full filename path to the config $filename = $config; if (!Toolkit::isPathAbsolute($filename)) { $filename = MO_WEBAPP_DIR . '/' . $filename; } if (!is_readable($filename)) { // configuration file does not exist $error = 'Configuration file "%s" does not exist or is unreadable'; $error = sprintf($error, $filename); throw new ConfigurationException($error); } // the cache filename we'll be using $cache = self::getCacheName($config); if (!is_readable($cache) || filemtime($filename) > filemtime($cache)) { // configuration file has changed so we need to reparse it self::callHandler($config, $filename, $cache); } return $cache; }