本文整理汇总了PHP中Exception::getReferenceCode方法的典型用法代码示例。如果您正苦于以下问题:PHP Exception::getReferenceCode方法的具体用法?PHP Exception::getReferenceCode怎么用?PHP Exception::getReferenceCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Exception
的用法示例。
在下文中一共展示了Exception::getReferenceCode方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handleException
/**
* Explicitly handle an exception, should be called from an exception handler (in Flow or TypoScript)
*
* @param \Exception $exception The exception to capture
* @param array $extraData Additional data passed to the Sentry sample
*/
public function handleException(\Exception $exception, array $extraData = array())
{
$this->setUserContext();
$tags = array('code' => $exception->getCode());
if ($exception instanceof \TYPO3\Flow\Exception) {
$extraData['referenceCode'] = $exception->getReferenceCode();
}
$this->client->captureException($exception, array('extra' => $extraData, 'tags' => $tags));
}
示例2: writeResponseAndExit
/**
* Displays a human readable, partly beautified version of the given exception
* and stops the application, return a non-zero exit code.
*
* @static
* @param \Exception $exception
* @return void
*/
public static function writeResponseAndExit(\Exception $exception)
{
$response = new Response();
$exceptionMessage = '';
$exceptionReference = "\n<b>More Information</b>\n";
$exceptionReference .= " Exception code #" . $exception->getCode() . "\n";
$exceptionReference .= " File " . $exception->getFile() . ($exception->getLine() ? ' line ' . $exception->getLine() : '') . "\n";
$exceptionReference .= $exception instanceof \TYPO3\Flow\Exception ? " Exception reference #" . $exception->getReferenceCode() . "\n" : '';
foreach (explode(chr(10), wordwrap($exception->getMessage(), 73)) as $messageLine) {
$exceptionMessage .= " {$messageLine}\n";
}
$response->setContent(sprintf("<b>Uncaught Exception</b>\n%s%s\n", $exceptionMessage, $exceptionReference));
$response->send();
exit(1);
}
示例3: handleException
/**
* Formats and echoes the exception for the command line
*
* @param \Exception $exception The exception object
* @return void
*/
public function handleException(\Exception $exception)
{
$pathPosition = strpos($exception->getFile(), 'ext/');
$filePathAndName = $pathPosition !== FALSE ? substr($exception->getFile(), $pathPosition) : $exception->getFile();
$exceptionCodeNumber = $exception->getCode() > 0 ? '#' . $exception->getCode() . ': ' : '';
echo PHP_EOL . 'Uncaught Exception in TYPO3 CMS ' . $exceptionCodeNumber . $exception->getMessage() . PHP_EOL;
echo 'thrown in file ' . $filePathAndName . PHP_EOL;
echo 'in line ' . $exception->getLine() . PHP_EOL;
if ($exception instanceof \TYPO3\Flow\Exception) {
echo 'Reference code: ' . $exception->getReferenceCode() . PHP_EOL;
}
$indent = ' ';
while (($exception = $exception->getPrevious()) !== NULL) {
echo PHP_EOL . $indent . 'Nested exception:' . PHP_EOL;
$pathPosition = strpos($exception->getFile(), 'Packages/');
$filePathAndName = $pathPosition !== FALSE ? substr($exception->getFile(), $pathPosition) : $exception->getFile();
$exceptionCodeNumber = $exception->getCode() > 0 ? '#' . $exception->getCode() . ': ' : '';
echo PHP_EOL . $indent . 'Uncaught Exception in Flow ' . $exceptionCodeNumber . $exception->getMessage() . PHP_EOL;
echo $indent . 'thrown in file ' . $filePathAndName . PHP_EOL;
echo $indent . 'in line ' . $exception->getLine() . PHP_EOL;
if ($exception instanceof \TYPO3\Flow\Exception) {
echo 'Reference code: ' . $exception->getReferenceCode() . PHP_EOL;
}
$indent .= ' ';
}
if (function_exists('xdebug_get_function_stack')) {
$backtraceSteps = xdebug_get_function_stack();
} else {
$backtraceSteps = debug_backtrace();
}
for ($index = 0; $index < count($backtraceSteps); $index++) {
echo PHP_EOL . '#' . $index . ' ';
if (isset($backtraceSteps[$index]['class'])) {
echo $backtraceSteps[$index]['class'];
}
if (isset($backtraceSteps[$index]['function'])) {
echo '::' . $backtraceSteps[$index]['function'] . '()';
}
echo PHP_EOL;
if (isset($backtraceSteps[$index]['file'])) {
echo ' ' . $backtraceSteps[$index]['file'] . (isset($backtraceSteps[$index]['line']) ? ':' . $backtraceSteps[$index]['line'] : '') . PHP_EOL;
}
}
echo PHP_EOL;
exit(1);
}
示例4: echoExceptionWeb
/**
* Echoes an exception for the web.
*
* @param \Exception $exception The exception
* @return void
*/
protected function echoExceptionWeb(\Exception $exception)
{
$statusCode = 500;
if ($exception instanceof FlowException) {
$statusCode = $exception->getStatusCode();
}
$statusMessage = Response::getStatusMessageByCode($statusCode);
$referenceCode = $exception instanceof FlowException ? $exception->getReferenceCode() : null;
if (!headers_sent()) {
header(sprintf('HTTP/1.1 %s %s', $statusCode, $statusMessage));
}
try {
if (isset($this->renderingOptions['templatePathAndFilename'])) {
echo $this->buildCustomFluidView($exception, $this->renderingOptions)->render();
} else {
echo $this->renderStatically($statusCode, $referenceCode);
}
} catch (\Exception $innerException) {
$this->systemLogger->logException($innerException);
}
}
示例5: buildCustomFluidView
/**
* Prepares a Fluid view for rendering the custom error page.
*
* @param \Exception $exception
* @param array $renderingOptions Rendering options as defined in the settings
* @return StandaloneView
*/
protected function buildCustomFluidView(\Exception $exception, array $renderingOptions)
{
$statusCode = 500;
$referenceCode = NULL;
if ($exception instanceof FlowException) {
$statusCode = $exception->getStatusCode();
$referenceCode = $exception->getReferenceCode();
}
$statusMessage = Response::getStatusMessageByCode($statusCode);
$fluidView = new StandaloneView();
$fluidView->getRequest()->setControllerPackageKey('TYPO3.Flow');
$fluidView->setTemplatePathAndFilename($renderingOptions['templatePathAndFilename']);
if (isset($renderingOptions['layoutRootPath'])) {
$fluidView->setLayoutRootPath($renderingOptions['layoutRootPath']);
}
if (isset($renderingOptions['partialRootPath'])) {
$fluidView->setPartialRootPath($renderingOptions['partialRootPath']);
}
if (isset($renderingOptions['format'])) {
$fluidView->setFormat($renderingOptions['format']);
}
if (isset($renderingOptions['variables'])) {
$fluidView->assignMultiple($renderingOptions['variables']);
}
$fluidView->assignMultiple(array('exception' => $exception, 'renderingOptions' => $renderingOptions, 'statusCode' => $statusCode, 'statusMessage' => $statusMessage, 'referenceCode' => $referenceCode));
return $fluidView;
}
示例6: convertException
/**
* @param \Exception $exception
* @return array
*/
protected function convertException(\Exception $exception)
{
$exceptionData = array('code' => $exception->getCode(), 'message' => $exception->getMessage());
$splitMessagePattern = '/
(?<= # Begin positive lookbehind.
[.!?]\\s # Either an end of sentence punct,
| \\n # or line break
)
(?<! # Begin negative lookbehind.
i\\.E\\.\\s # Skip "i.E."
) # End negative lookbehind.
/ix';
$sentences = preg_split($splitMessagePattern, $exception->getMessage(), 2, PREG_SPLIT_NO_EMPTY);
if (!isset($sentences[1])) {
$exceptionData['message'] = $exception->getMessage();
} else {
$exceptionData['message'] = trim($sentences[0]);
$exceptionData['details'] = trim($sentences[1]);
}
if ($exception instanceof FlowException) {
$exceptionData['referenceCode'] = $exception->getReferenceCode();
}
if ($exception->getPrevious() !== null) {
$exceptionData['previous'] = $this->convertException($exception->getPrevious());
}
return $exceptionData;
}
示例7: logException
/**
* @param \Exception $exception
* @return void
*/
public function logException(\Exception $exception)
{
if (!isset($this->settings['host']) || strlen($this->settings['host']) === 0) {
return;
}
$statusCode = NULL;
if ($exception instanceof FlowException) {
$statusCode = $exception->getStatusCode();
}
// skip exceptions with status codes matching "skipStatusCodes" setting
if (isset($this->settings['skipStatusCodes']) && in_array($statusCode, $this->settings['skipStatusCodes'])) {
return;
}
$host = $this->settings['host'];
$port = isset($this->settings['port']) ? $this->settings['port'] : UdpTransport::DEFAULT_PORT;
// set chunk size option to wan (default) or lan
if (isset($this->settings['chunksize']) && strtolower($this->settings['chunksize']) === 'lan') {
$chunkSize = UdpTransport::CHUNK_SIZE_LAN;
} else {
$chunkSize = UdpTransport::CHUNK_SIZE_WAN;
}
// setup connection to graylog server
$transport = new UdpTransport($host, $port, $chunkSize);
$publisher = new Publisher();
$publisher->addTransport($transport);
// set logLevel depending on http status code
$logLevel = 4;
// warning
if ($statusCode === 500) {
$logLevel = 3;
// error
}
// build message context
$messageContext = array('full_message' => $exception->getTraceAsString(), 'reference_code' => $exception instanceof FlowException ? $exception->getReferenceCode() : NULL, 'response_status' => $statusCode, 'short_message' => sprintf('%d %s', $statusCode, Response::getStatusMessageByCode($statusCode)), 'code' => $exception->getCode(), 'file' => $exception->getFile(), 'line' => $exception->getLine());
if ($this->securityContext !== NULL && $this->securityContext->isInitialized()) {
$account = $this->securityContext->getAccount();
if ($account !== NULL) {
$messageContext['authenticated_account'] = $account->getAccountIdentifier() . ' (' . $this->persistenceManager->getIdentifierByObject($account) . ')';
$messageContext['authenticated_roles'] = implode(', ', array_keys($this->securityContext->getRoles()));
if ($this->objectManager->isRegistered(PartyService::class)) {
/** @var PartyService $partyService */
$partyService = $this->objectManager->get(PartyService::class);
$person = $partyService->getAssignedPartyOfAccount($account);
if ($person instanceof Person) {
$messageContext['authenticated_person'] = (string) $person->getName() . ' (' . $this->persistenceManager->getIdentifierByObject($person) . ')';
}
}
}
}
// prepare request details
if (Bootstrap::$staticObjectManager instanceof ObjectManagerInterface) {
$bootstrap = Bootstrap::$staticObjectManager->get('TYPO3\\Flow\\Core\\Bootstrap');
/* @var Bootstrap $bootstrap */
$requestHandler = $bootstrap->getActiveRequestHandler();
if ($requestHandler instanceof HttpRequestHandlerInterface) {
$request = $requestHandler->getHttpRequest();
$requestData = array('request_domain' => $request->getHeader('Host'), 'request_remote_addr' => $request->getClientIpAddress(), 'request_path' => $request->getRelativePath(), 'request_uri' => $request->getUri()->getPath(), 'request_user_agent' => $request->getHeader('User-Agent'), 'request_method' => $request->getMethod(), 'request_port' => $request->getPort());
$messageContext = array_merge($messageContext, $requestData);
}
}
// send message to graylog server
$logger = new Logger($publisher);
$logger->log($logLevel, $exception->getMessage(), $messageContext);
}
示例8: convertException
/**
* @param \Exception $exception
* @return array
*/
protected function convertException(\Exception $exception)
{
if ($this->objectManager->getContext()->isProduction()) {
if ($exception instanceof FlowException) {
$exceptionData['message'] = 'When contacting the maintainer of this application please mention the following reference code:<br /><br />' . $exception->getReferenceCode();
}
} else {
$exceptionData = array('code' => $exception->getCode(), 'message' => $exception->getMessage());
$splitMessagePattern = '/
(?<= # Begin positive lookbehind.
[.!?]\\s # Either an end of sentence punct,
| \\n # or line break
)
(?<! # Begin negative lookbehind.
i\\.E\\.\\s # Skip "i.E."
) # End negative lookbehind.
/ix';
$sentences = preg_split($splitMessagePattern, $exception->getMessage(), 2, PREG_SPLIT_NO_EMPTY);
if (!isset($sentences[1])) {
$exceptionData['message'] = $exception->getMessage();
} else {
$exceptionData['message'] = trim($sentences[0]);
$exceptionData['details'] = trim($sentences[1]);
}
if ($exception instanceof FlowException) {
$exceptionData['referenceCode'] = $exception->getReferenceCode();
}
if ($exception->getPrevious() !== null) {
$exceptionData['previous'] = $this->convertException($exception->getPrevious());
}
}
return $exceptionData;
}