本文整理汇总了PHP中Symfony\Component\HttpKernel\Exception\FlattenException::getClass方法的典型用法代码示例。如果您正苦于以下问题:PHP FlattenException::getClass方法的具体用法?PHP FlattenException::getClass怎么用?PHP FlattenException::getClass使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpKernel\Exception\FlattenException
的用法示例。
在下文中一共展示了FlattenException::getClass方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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));
}
示例2: showAction
public function showAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null, $format = 'html')
{
if ('Trez\\LogicielTrezBundle\\Exception\\LockedException' === $exception->getClass()) {
$this->session->getFlashBag()->set('error', "Vous ne pouvez pas éditer un exercice/budget verrouillé ou ses fils");
return new RedirectResponse($this->request->getRequestUri(), 302);
}
if ('Symfony\\Component\\HttpKernel\\Exception\\AccessDeniedHttpException' === $exception->getClass()) {
$this->session->getFlashBag()->set('error', "Vous n'avez pas les privilèges nécessaires pour effectuer cette action !");
if ($this->securityContext->isGranted('ROLE_USER') === true) {
return new Response($this->twig->render('TrezLogicielTrezBundle:Default:index.html.twig', array()));
} else {
return new Response("Vous n'avez pas les privilèges nécessaires pour afficher cette page !");
}
}
// else default behavior
return parent::showAction($exception, $logger, $format);
}
示例3: getStatusCode
protected function getStatusCode(FlattenException $exception)
{
switch ($exception->getClass()) {
case 'Symfony\\Component\\Security\\Exception\\AccessDeniedException':
return 403;
case 'Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException':
return 404;
default:
return 500;
}
}
示例4: exceptionAction
/**
* Converts an Exception to a Response.
*
* @param FlattenException $exception A FlattenException instance
* @param DebugLoggerInterface $logger A DebugLoggerInterface instance
* @param string $format The format to use for rendering (html, xml, ...)
* @param Boolean $embedded Whether the rendered Response will be embedded or not
*
* @throws \InvalidArgumentException When the exception template does not exist
*/
public function exceptionAction(FlattenException $exception, DebugLoggerInterface $logger = null, $format = 'html', $embedded = false)
{
$this->container->get('request')->setRequestFormat($format);
$currentContent = '';
while (false !== ($content = ob_get_clean())) {
$currentContent .= $content;
}
if ('Symfony\\Component\\Security\\Exception\\AccessDeniedException' === $exception->getClass()) {
$exception->setStatusCode($exception->getCode());
}
$templating = $this->container->get('templating');
$template = 'FrameworkBundle:Exception:' . ($this->container->get('kernel')->isDebug() ? 'exception.php' : 'error.php');
if (!$templating->exists($template)) {
$this->container->get('request')->setRequestFormat('html');
}
$response = $templating->renderResponse($template, array('exception' => $exception, 'logger' => $logger, 'currentContent' => $currentContent, 'embedded' => $embedded));
$response->setStatusCode($exception->getStatusCode());
return $response;
}
示例5: exceptionAction
/**
* Converts an Exception to a Response.
*
* @param FlattenException $exception A FlattenException instance
* @param DebugLoggerInterface $logger A DebugLoggerInterface instance
* @param string $format The format to use for rendering (html, xml, ...)
*
* @throws \InvalidArgumentException When the exception template does not exist
*/
public function exceptionAction(FlattenException $exception, DebugLoggerInterface $logger = null, $format = 'html')
{
$this->container->get('request')->setRequestFormat($format);
$currentContent = '';
while (ob_get_level()) {
$currentContent .= ob_get_clean();
}
if ('Symfony\Component\Security\Exception\AccessDeniedException' === $exception->getClass()) {
$exception->setStatusCode($exception->getCode());
}
$template = $this->container->get('kernel')->isDebug() ? 'exception' : 'error';
if ($this->container->get('kernel')->isDebug() && 'html' == $format) {
$template = 'exception_full';
}
$template = 'FrameworkBundle:Exception:'.$template.'.twig';
$templating = $this->container->get('templating');
if (!$templating->exists($template)) {
$this->container->get('request')->setRequestFormat('html');
}
$response = $templating->renderResponse(
$template,
array(
'exception' => $exception,
'logger' => $logger,
'currentContent' => $currentContent,
)
);
$response->setStatusCode($exception->getStatusCode());
return $response;
}
示例6: isSubclassOf
/**
* Extract the exception message
*
* @param HttpFlattenException|DebugFlattenException $exception A HttpFlattenException|DebugFlattenException instance
* @param array $exceptionMap
*
* @return string Message
*/
protected function isSubclassOf($exception, $exceptionMap)
{
$exceptionClass = $exception->getClass();
$reflectionExceptionClass = new \ReflectionClass($exceptionClass);
try {
foreach ($exceptionMap as $exceptionMapClass => $value) {
if ($value && ($exceptionClass === $exceptionMapClass || $reflectionExceptionClass->isSubclassOf($exceptionMapClass))) {
return $value;
}
}
} catch (\ReflectionException $re) {
return "FOSUserBundle: Invalid class in fos_res.exception.messages: " . $re->getMessage();
}
return false;
}
示例7: getStatusCode
/**
* Determine the status code to use for the response
*
* @param FlattenException $exception A FlattenException instance
*
* @return integer An HTTP response code
*/
protected function getStatusCode($exception)
{
$exceptionClass = $exception->getClass();
$exceptionMap = $this->container->getParameter('fos_rest.exception.codes');
return isset($exceptionMap[$exceptionClass]) ? $exceptionMap[$exceptionClass] : $exception->getStatusCode();
}
示例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: isSubclassOf
/**
* Extracts the exception message.
*
* @param HttpFlattenException|DebugFlattenException $exception
* @param array $exceptionMap
*
* @return int|false
*/
protected function isSubclassOf($exception, $exceptionMap)
{
$exceptionClass = $exception->getClass();
foreach ($exceptionMap as $exceptionMapClass => $value) {
if ($value && ($exceptionClass === $exceptionMapClass || is_subclass_of($exceptionClass, $exceptionMapClass))) {
return $value;
}
}
return false;
}
示例10: showAction
public function showAction(FlattenException $exception, DebugLoggerInterface $logger = null, $format = 'html')
{
$this->exceptionClass = $exception->getClass();
return parent::showAction($exception, $logger, $format);
}
示例11: showAction
public function showAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null)
{
$this->exceptionClass = $exception->getClass();
return parent::showAction($request, $exception, $logger);
// TODO: Change the autogenerated stub
}