本文整理汇总了PHP中Symfony\Component\HttpKernel\Exception\FlattenException::getMessage方法的典型用法代码示例。如果您正苦于以下问题:PHP FlattenException::getMessage方法的具体用法?PHP FlattenException::getMessage怎么用?PHP FlattenException::getMessage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpKernel\Exception\FlattenException
的用法示例。
在下文中一共展示了FlattenException::getMessage方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: showAction
public function showAction(FlattenException $exception, DebugLoggerInterface $logger = null, $format = 'html')
{
$statusCode = $exception->getStatusCode();
$statusText = $exception->getMessage();
$response = $this->render('GitonomyWebsiteBundle:Error:error.html.twig', array('status_code' => $statusCode, 'status_text' => $statusText));
$response->setStatusCode($statusCode);
$response->headers->replace($exception->getHeaders());
return $response;
}
示例2: showAction
/**
* Converts an Exception to a Response.
*
* @param Request $request The request
* @param FlattenException $exception A FlattenException instance
* @param DebugLoggerInterface $logger A DebugLoggerInterface instance
*
* @param string $_format
* @return JsonResponse
*/
public function showAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null, $_format = 'html')
{
$this->getAndCleanOutputBuffering($request->headers->get('X-Php-Ob-Level', -1));
$wrapper = new ExceptionWrapper();
$wrapper->setCode($exception->getCode());
$wrapper->setMessage($exception->getMessage());
$wrapper->setStatusCode($exception->getStatusCode());
$wrapper->setTrace($this->debug ? $exception->getTrace() : array());
return $wrapper->getResponse();
}
示例3: showAction
/**
* @param Request $request
* @param FlattenException $exception
* @param DebugLoggerInterface $logger
* @return \GoIntegro\Hateoas\Http\JsonResponse
*/
public function showAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = NULL)
{
$error = new ErrorObject();
$error->status = $exception->getStatusCode();
$error->title = $exception->getMessage();
$error->code = $exception->getCode();
$serializer = new ErrorSerializer($error);
if (500 == $error->status && NULL != $logger) {
$logger->error(sprintf(self::ERROR_LOG_MESSAGE_PATTERN, $error->title, $exception->getFile(), $exception->getLine(), $error->id));
}
return $this->createNoCacheResponse($serializer->serialize(), $error->status, $exception->getHeaders());
}
示例4: showExceptionAction
/**
* @param Request $request
* @param FlattenException $exception
* @param DebugLoggerInterface $logger
* @return \Symfony\Component\HttpFoundation\Response
*/
public function showExceptionAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null)
{
/** @var Translator $translator */
$translator = $this->get('translator');
$message = $translator->trans('error.messages.generic');
// check if the error is whitelisted to overrule the message
if (in_array($exception->getClass(), $this->container->getParameter('sumo_coders_framework_error.show_messages_for'))) {
$message = $exception->getMessage();
}
// translate page not found messages
if ('Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException' == $exception->getClass()) {
$message = $translator->trans('error.messages.noRouteFound');
}
return $this->render('::error.html.twig', array('status_code' => $exception->getStatusCode(), 'status_text' => $message));
}
示例5: showAction
/**
* Converts an Exception to a Response.
*
* A "showException" request parameter can be used to force display of an error page (when set to false) or
* the exception page (when true). If it is not present, the "debug" value passed into the constructor will
* be used.
*
* @param Request $request The request
* @param FlattenException $exception A FlattenException instance
* @param DebugLoggerInterface $logger A DebugLoggerInterface instance
*
* @return Response
*
* @throws \InvalidArgumentException When the exception template does not exist
*/
public function showAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null)
{
$opts = array();
$params = array();
//------------------------------
$currentContent = $this->getAndCleanOutputBuffering($request->headers->get('X-Php-Ob-Level', -1));
$showException = $request->attributes->get('showException', $this->debug);
// As opposed to an additional parameter, this maintains BC
$code = $exception->getStatusCode();
$message = $exception->getMessage();
$arrAlertMessage = $this->getAlertMessage($message);
$attrs = $request->attributes->all();
if (isset($attrs['_route'])) {
$route = $attrs['_route'];
} else {
$route = 'indefinite';
}
if (isset($this->app["my.opts"]) && isset($this->app["my.opts"])) {
$opts = $this->app["my.opts"];
$params = $this->app["my.params"];
}
return new Response($this->twig->render($this->findTemplate($request, $request->getRequestFormat(), $code, $showException), array('route' => $route, 'status_code' => $code, 'status_text' => isset(Response::$statusTexts[$code]) ? Response::$statusTexts[$code] : '', 'exception' => $exception, 'logger' => $logger, 'currentContent' => $currentContent, 'parameters' => $this->ArrData2View($opts + $params))));
}
示例6: getExceptionMessage
/**
* Extract the exception message
*
* @param FlattenException $exception A FlattenException instance
*
* @return string Message
*/
protected function getExceptionMessage($exception)
{
$exceptionClass = $exception->getClass();
$exceptionMap = $this->container->getParameter('fos_rest.exception.messages');
return !empty($exceptionMap[$exceptionClass]) || $this->container->get('kernel')->isDebug() ? $exception->getMessage() : '';
}
示例7: exception
/**
* Retrieve a textual description of the given Exception, or FlattenException (as passed by Symfony HttpKernel).
*
* @param \Symfony\Component\HttpKernel\Exception\FlattenException|\Exception $exception
* @param string|null $adminName
* @param string|null $adminEmail
* @param string $heading
* @param null $stackTraceHeading
*
* @return string
*/
public static function exception($exception, $adminName = null, $adminEmail = null, $heading = null, $stackTraceHeading = null)
{
// Generate the error message.
ob_start();
echo $heading ?: '<h1>Error</h1>', PHP_EOL;
echo '<p><strong>', $exception->getMessage(), '</strong></p>', PHP_EOL;
echo '<p>Error occurred at ', date('Y-m-d H:i:s'), ', code: ', $exception->getCode(), ', ', TypeUtilities::describe($exception), '</p>', PHP_EOL;
echo '<p>Please contact your system administrator for assistance.</p>' . PHP_EOL;
if (!empty($adminName) || !empty($adminEmail)) {
echo '<ul>', PHP_EOL;
if (!empty($adminName)) {
echo '<li>Name: ', $adminName, '</li>', PHP_EOL;
}
if (!empty($adminEmail)) {
echo '<li>Email Address: ', $adminEmail, '</li>', PHP_EOL;
}
echo '</ul>', PHP_EOL;
}
echo '<hr/>', PHP_EOL;
echo $stackTraceHeading ?: '<h2>Stack Trace</h2>', PHP_EOL;
echo '<ol>', PHP_EOL;
foreach (array_reverse($exception->getTrace()) as $traceItem) {
$file = isset($traceItem['file']) ? $traceItem['file'] : '';
$line = isset($traceItem['line']) ? sprintf('(%s)', $traceItem['line']) : '';
$function = isset($traceItem['function']) ? isset($traceItem['class']) && !empty($traceItem['class']) ? sprintf('%s->%s', $traceItem['class'], $traceItem['function']) : $traceItem['function'] : '';
echo '<li>', $file, $line, ': ', $function, '()</li>', PHP_EOL;
}
echo '</ol>';
return ob_get_clean();
}
示例8: getContent
/**
* Gets the HTML content associated with the given exception.
*
* @param FlattenException $exception A FlattenException instance
*
* @return string The content as a string
*/
public function getContent(FlattenException $exception)
{
$title = '';
switch ($exception->getStatusCode()) {
case 404:
$title = 'Sorry, the page you are looking for could not be found.';
break;
default:
$title = 'Whoops, looks like something went wrong.';
}
$content = '';
if ($this->debug) {
try {
$message = nl2br($exception->getMessage());
$class = $this->abbrClass($exception->getClass());
$count = count($exception->getAllPrevious());
$content = '';
foreach ($exception->toArray() as $position => $e) {
$ind = $count - $position + 1;
$total = $count + 1;
$class = $this->abbrClass($e['class']);
$message = nl2br($e['message']);
$content .= sprintf(<<<EOF
<div class="block_exception clear_fix">
<h2><span>%d/%d</span> %s: %s</h2>
</div>
<div class="block">
<ol class="traces list_exception">
EOF
, $ind, $total, $class, $message);
foreach ($e['trace'] as $i => $trace) {
$content .= ' <li>';
if ($trace['function']) {
$content .= sprintf('at %s%s%s(%s)', $this->abbrClass($trace['class']), $trace['type'], $trace['function'], $this->formatArgs($trace['args']));
}
if (isset($trace['file']) && isset($trace['line'])) {
if ($linkFormat = ini_get('xdebug.file_link_format')) {
$link = str_replace(array('%f', '%l'), array($trace['file'], $trace['line']), $linkFormat);
$content .= sprintf(' in <a href="%s" title="Go to source">%s line %s</a>', $link, $trace['file'], $trace['line']);
} else {
$content .= sprintf(' in %s line %s', $trace['file'], $trace['line']);
}
}
$content .= "</li>\n";
}
$content .= " </ol>\n</div>\n";
}
} catch (\Exception $e) {
// something nasty happened and we cannot throw an exception anymore
if ($this->debug) {
$title = sprintf('Exception thrown when handling an exception (%s: %s)', get_class($exception), $exception->getMessage());
} else {
$title = 'Whoops, looks like something went wrong.';
}
}
}
return <<<EOF
<div id="sf-resetcontent" class="sf-reset">
<h1>{$title}</h1>
{$content}
</div>
EOF;
}
示例9: exceptionAction
public function exceptionAction(FlattenException $exception)
{
$msg = 'Something went wrong! (' . $exception->getMessage() . ')';
return new Response($msg, $exception->getStatusCode());
}