当前位置: 首页>>代码示例>>PHP>>正文


PHP ApiFormatBase::canPrintErrors方法代码示例

本文整理汇总了PHP中ApiFormatBase::canPrintErrors方法的典型用法代码示例。如果您正苦于以下问题:PHP ApiFormatBase::canPrintErrors方法的具体用法?PHP ApiFormatBase::canPrintErrors怎么用?PHP ApiFormatBase::canPrintErrors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ApiFormatBase的用法示例。


在下文中一共展示了ApiFormatBase::canPrintErrors方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: substituteResultWithError

 /**
  * Replace the result data with the information about an exception.
  * Returns the error code
  * @param $e Exception
  * @return string
  */
 protected function substituteResultWithError($e)
 {
     global $wgShowHostnames;
     $result = $this->getResult();
     // Printer may not be initialized if the extractRequestParams() fails for the main module
     if (!isset($this->mPrinter)) {
         // The printer has not been created yet. Try to manually get formatter value.
         $value = $this->getRequest()->getVal('format', self::API_DEFAULT_FORMAT);
         if (!$this->mModuleMgr->isDefined($value, 'format')) {
             $value = self::API_DEFAULT_FORMAT;
         }
         $this->mPrinter = $this->createPrinterByName($value);
     }
     // Printer may not be able to handle errors. This is particularly
     // likely if the module returns something for getCustomPrinter().
     if (!$this->mPrinter->canPrintErrors()) {
         $this->mPrinter->safeProfileOut();
         $this->mPrinter = $this->createPrinterByName(self::API_DEFAULT_FORMAT);
     }
     // Update raw mode flag for the selected printer.
     $result->setRawMode($this->mPrinter->getNeedsRawData());
     if ($e instanceof UsageException) {
         // User entered incorrect parameters - print usage screen
         $errMessage = $e->getMessageArray();
         // Only print the help message when this is for the developer, not runtime
         if ($this->mPrinter->getWantsHelp() || $this->mAction == 'help') {
             ApiResult::setContent($errMessage, $this->makeHelpMsg());
         }
     } else {
         global $wgShowSQLErrors, $wgShowExceptionDetails;
         // Something is seriously wrong
         if ($e instanceof DBQueryError && !$wgShowSQLErrors) {
             $info = 'Database query error';
         } else {
             $info = "Exception Caught: {$e->getMessage()}";
         }
         $errMessage = array('code' => 'internal_api_error_' . get_class($e), 'info' => $info);
         ApiResult::setContent($errMessage, $wgShowExceptionDetails ? "\n\n{$e->getTraceAsString()}\n\n" : '');
     }
     // Remember all the warnings to re-add them later
     $oldResult = $result->getData();
     $warnings = isset($oldResult['warnings']) ? $oldResult['warnings'] : null;
     $result->reset();
     $result->disableSizeCheck();
     // Re-add the id
     $requestid = $this->getParameter('requestid');
     if (!is_null($requestid)) {
         $result->addValue(null, 'requestid', $requestid);
     }
     if ($wgShowHostnames) {
         // servedby is especially useful when debugging errors
         $result->addValue(null, 'servedby', wfHostName());
     }
     if ($warnings !== null) {
         $result->addValue(null, 'warnings', $warnings);
     }
     $result->addValue(null, 'error', $errMessage);
     return $errMessage['code'];
 }
开发者ID:spring,项目名称:spring-website,代码行数:65,代码来源:ApiMain.php

示例2: createErrorPrinter

 /**
  * Create the printer for error output
  */
 private function createErrorPrinter()
 {
     if (!isset($this->mPrinter)) {
         $value = $this->getRequest()->getVal('format', self::API_DEFAULT_FORMAT);
         if (!$this->mModuleMgr->isDefined($value, 'format')) {
             $value = self::API_DEFAULT_FORMAT;
         }
         $this->mPrinter = $this->createPrinterByName($value);
     }
     // Printer may not be able to handle errors. This is particularly
     // likely if the module returns something for getCustomPrinter().
     if (!$this->mPrinter->canPrintErrors()) {
         $this->mPrinter = $this->createPrinterByName(self::API_DEFAULT_FORMAT);
     }
 }
开发者ID:soumyag213,项目名称:mediawiki,代码行数:18,代码来源:ApiMain.php


注:本文中的ApiFormatBase::canPrintErrors方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。