Exemple #1
0
 /**
  * sets the sort
  * @param string $arg0
  */
 function setSort($arg0)
 {
     $this->sort = StringTools::removeBadMySQLChars($arg0);
     return $this;
 }
Exemple #2
0
    /**
     * 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;
    }
 function redirect()
 {
     echo StringTools::getDebugBacktraceForLogs();
     die;
 }
Exemple #4
0
 /**
  * Helper method to return a value using the getter or property
  * @param string $name
  * @param string $default
  * @param string $encode_type
  * @return string
  */
 public function retrieveValue($name, $default = null, $encode_type = null)
 {
     $return_value = $default;
     $method_name = 'get' . \Mojavi\Util\StringTools::camelCase($name);
     if (method_exists($this, $method_name)) {
         $return_value = $this->{$method_name}();
     } else {
         if (property_exists($this, $name)) {
             if (!is_null($this->{$name})) {
                 $return_value = $this->{$name};
             }
         }
     }
     switch ($encode_type) {
         case 'htmlspecialchars':
             if (is_string($return_value)) {
                 $return_value = htmlspecialchars($return_value);
             }
             break;
         case 'rawurlencode':
             if (is_string($return_value)) {
                 $return_value = rawurlencode($return_value);
             }
             break;
     }
     return $return_value;
 }