本文整理汇总了PHP中MWException类的典型用法代码示例。如果您正苦于以下问题:PHP MWException类的具体用法?PHP MWException怎么用?PHP MWException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MWException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: report
/**
* Overrides MWException::report to also write exceptions to error_log
*
* @see MWException::report
*/
function report()
{
$file = $this->getFile();
$line = $this->getLine();
$message = $this->getMessage();
$request = RequestContext::getMain()->getRequest();
$url = '[no URL]';
if (isset($request)) {
$url = $request->getFullRequestURL();
}
trigger_error("Exception from line {$line} of {$file}: {$message} ({$url})", E_USER_ERROR);
/*
bust the headers_sent check in MWException::report()
Uncomment to override normal MWException headers
in order to display an error page instead of a 500 error
WARNING: Varnish doesn't like those
flush();
*/
parent::report();
}
示例2: report
/**
* Report an exception to the user
* @param Exception $e
*/
protected static function report(Exception $e)
{
global $wgShowExceptionDetails;
$cmdLine = MWException::isCommandLine();
if ($e instanceof MWException) {
try {
// Try and show the exception prettily, with the normal skin infrastructure
$e->report();
} catch (Exception $e2) {
// Exception occurred from within exception handler
// Show a simpler message for the original exception,
// don't try to invoke report()
$message = "MediaWiki internal error.\n\n";
if ($wgShowExceptionDetails) {
$message .= 'Original exception: ' . self::getLogMessage($e) . "\nBacktrace:\n" . self::getRedactedTraceAsString($e) . "\n\nException caught inside exception handler: " . self::getLogMessage($e2) . "\nBacktrace:\n" . self::getRedactedTraceAsString($e2);
} else {
$message .= "Exception caught inside exception handler.\n\n" . "Set \$wgShowExceptionDetails = true; at the bottom of LocalSettings.php " . "to show detailed debugging information.";
}
$message .= "\n";
if ($cmdLine) {
self::printError($message);
} else {
echo nl2br(htmlspecialchars($message)) . "\n";
}
}
} else {
$message = "Exception encountered, of type \"" . get_class($e) . "\"";
if ($wgShowExceptionDetails) {
$message .= "\n" . MWExceptionHandler::getLogMessage($e) . "\nBacktrace:\n" . self::getRedactedTraceAsString($e) . "\n";
}
if ($cmdLine) {
self::printError($message);
} else {
echo nl2br(htmlspecialchars($message)) . "\n";
}
}
}
示例3: testisCommandLine
/**
* @dataProvider provideIsCommandLine
* @covers MWException::isCommandLine
*/
public function testisCommandLine($expected, $wgCommandLineMode)
{
$this->setMwGlobals(array('wgCommandLineMode' => $wgCommandLineMode));
$e = new MWException();
$this->assertEquals($expected, $e->isCommandLine());
}
示例4: report
/**
* Override MWException report() and write exceptions to error_log
*
* Uncomment the flush() line to override normal MWException headers
* so we can display an error page instead of a 500 error (varnish doesn't like those)
*
* TODO: display a nice walter?
*/
function report()
{
global $wgRequest;
$file = $this->getFile();
$line = $this->getLine();
$message = $this->getMessage();
$url = '[no URL]';
if (isset($wgRequest)) {
$url = $wgRequest->getFullRequestURL();
}
trigger_error("Exception from line {$line} of {$file}: {$message} ({$url})", E_USER_ERROR);
//flush(); // bust the headers_sent check in MWException::report()
parent::report();
}
示例5: __construct
/**
* Constructor
*
* @param int $httpCode HTTP status code to send to the client
* @param string|Message $content Content of the message
* @param string|Message|null $header Content of the header (\<title\> and \<h1\>)
*/
public function __construct($httpCode, $content, $header = null)
{
parent::__construct($content);
$this->httpCode = (int) $httpCode;
$this->header = $header;
$this->content = $content;
}
示例6: __construct
/**
* @todo Pass around Messages when Status class doesn't suck
* @param array $msg Message key with parameters
*/
public function __construct(array $msg)
{
$this->msg = $msg;
// Using ->plain() instead of ->text() due to bug T58226
$wikitext = call_user_func_array('wfMessage', $msg)->plain();
parent::__construct($wikitext);
}
示例7:
/**
* Construct a database error
* @param $db DatabaseBase object which threw the error
* @param $error String A simple error message to be used for debugging
*/
function __construct(DatabaseBase &$db, $error)
{
global $wgDBcluster;
$this->db = $db;
parent::__construct($error);
$isMaster = !is_null($db->getLBInfo('master'));
// Wikia change - @author macbre - MAIN-2304
\Wikia\Logger\WikiaLogger::instance()->error('DBError', ['name' => $db->getDBname(), 'cluster' => $wgDBcluster, 'server' => $db->getServer(), 'server_role' => $isMaster ? 'master' : 'slave', 'errno' => $db->lastErrno(), 'err' => $db->lastError(), 'exception' => $this]);
}
示例8: getHTML
function getHTML()
{
global $wgShowExceptionDetails;
$class = strtolower(get_class($this->getPrevious()));
$box_content = wfMessage($class . '-body')->text();
$box = '<div class="errorbox" style="float: none;">' . $box_content . "</div>";
if ($wgShowExceptionDetails) {
$box .= '<b>Status code:</b> ' . $this->previous->getCode() . "<br /><b>Message from authentication server:</b> " . $this->previous->getMessage();
}
return $box . parent::getHTML();
}
示例9: array
function __construct($exceptionID, $engine, $module = null, $line = null, $params = array())
{
if ($module) {
$codelocation = wfMsg('scripting-codelocation', $module, $line);
$msg = wfMsgExt("scripting-exception-{$engine}-{$exceptionID}", array(), array_merge(array($codelocation), $params));
} else {
$msg = wfMsgExt("scripting-exception-{$engine}-{$exceptionID}", array(), $params);
}
parent::__construct($msg);
$this->mExceptionID = $exceptionID;
$this->mLine = $line;
$this->mModule = $module;
$this->mParams = $params;
}
示例10: __construct
/**
* Note: these arguments are keys into wfMessage(), not text!
*
* @param string|Message $title Message key (string) for page title, or a Message object
* @param string|Message $msg Message key (string) for error text, or a Message object
* @param array $params Array with parameters to wfMessage()
*/
public function __construct($title, $msg, $params = [])
{
$this->title = $title;
$this->msg = $msg;
$this->params = $params;
// Bug 44111: Messages in the log files should be in English and not
// customized by the local wiki. So get the default English version for
// passing to the parent constructor. Our overridden report() below
// makes sure that the page shown to the user is not forced to English.
if ($msg instanceof Message) {
$enMsg = clone $msg;
} else {
$enMsg = wfMessage($msg, $params);
}
$enMsg->inLanguage('en')->useDatabase(false);
parent::__construct($enMsg->text());
}
示例11: array
/**
* @param string $messageName
* @param array $params
*/
function __construct($messageName, $params = array())
{
if (isset($params['args'])) {
$this->messageArgs = $params['args'];
} else {
$this->messageArgs = array();
}
if (isset($params['module']) && isset($params['line'])) {
$codeLocation = false;
if (isset($params['title'])) {
$moduleTitle = Title::newFromText($params['module']);
if ($moduleTitle && $moduleTitle->equals($params['title'])) {
$codeLocation = wfMessage('scribunto-line', $params['line'])->inContentLanguage()->text();
}
}
if ($codeLocation === false) {
$codeLocation = wfMessage('scribunto-module-line', $params['module'], $params['line'])->inContentLanguage()->text();
}
} else {
$codeLocation = '[UNKNOWN]';
}
array_unshift($this->messageArgs, $codeLocation);
$msg = wfMessage($messageName)->params($this->messageArgs)->inContentLanguage()->text();
parent::__construct($msg);
$this->messageName = $messageName;
$this->params = $params;
}
示例12:
/**
* Construct a database error
* @param Database $db The database object which threw the error
* @param string $error A simple error message to be used for debugging
*/
function __construct(Database &$db, $error)
{
$this->db =& $db;
parent::__construct($error);
}
示例13: __construct
/**
* @param string $message
* @param string $codestr
* @param int $code
* @param array|null $extradata
*/
public function __construct($message, $codestr, $code = 0, $extradata = null)
{
parent::__construct($message, $code);
$this->mCodestr = $codestr;
$this->mExtraData = $extradata;
}
示例14:
/**
* Construct a database error
* @param DatabaseBase $db Object which threw the error
* @param string $error A simple error message to be used for debugging
*/
function __construct(DatabaseBase $db = null, $error)
{
$this->db = $db;
parent::__construct($error);
}
示例15:
function __construct($message)
{
parent::__construct('CLDR plural rule error: ' . $message);
}