public function onKernelException(GetResponseForExceptionEvent $event) { $exception = $event->getException(); if ($this->env != "prod") { $event->setException($exception); return; } try { $code = 404; if ($exception instanceof \Symfony\Component\HttpKernel\Exception\NotFoundHttpException) { $code = 404; } else { if ($exception instanceof \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException) { $code = 403; } } $file = $code; if ($this->env != "prod") { //$file = $file . '.' . $this->env; } $file = $file . '.html.twig'; $template = $this->siteManager->getTemplate("portal"); $template = "SymbbTemplateDefaultBundle:Exception:" . $file; $response = new Response($this->templating->render($template, array('status_code' => $code, 'status_text' => $exception->getMessage(), 'exception' => $exception))); // setup the Response object based on the caught exception $event->setResponse($response); } catch (\Exception $exc) { $event->setException($exception); } // you can alternatively set a new Exception // $exception = new \Exception('Some special exception'); // $event->setException($exception); }
public function sendTopicNotifications(Topic $topic, $user) { if (is_numeric($user)) { $user = $this->em->getRepository('SymbbCoreUserBundle:User')->find($user); } $templateBundle = $this->siteManager->getTemplate("email"); $subject = $this->translator->trans('It was written a new answer to "%topic%"', array('%topic%' => $topic->getName()), 'symbb_email'); $sender = $this->siteManager->getSite()->getEmail(); if (!empty($sender)) { $recipient = $user->getEmail(); $message = \Swift_Message::newInstance()->setSubject($subject)->setFrom($sender)->setTo($recipient)->setBody($this->container->get('twig')->render($templateBundle . ':Email:topic_notify.' . $this->getLocale() . '.html.twig', array('topic' => $topic, 'user' => $user, 'site' => $this->siteManager->getSite())), 'text/html'); $this->mailer->send($message); } }