php Symfony-Component-Debug-ExceptionHandler类(方法)实例源码

下面列出了php Symfony-Component-Debug-ExceptionHandler 类(方法)源码代码实例,从而了解它的用法。

作者:Nuwir    项目:laravel-error-emaile   
public function sendException($exception)
 {
     if (!$this->isErrorFromBot()) {
         $recipients = Config::get("error-emailer::to");
         if (isset($recipients['address'])) {
             // this is a single recipient
             if ($recipients['address']) {
                 $recipients = array($recipients);
             } else {
                 $recipients = array();
             }
         }
         if (sizeof($recipients) > 0) {
             if ($exception instanceof FlattenException) {
                 $flattened = $exception;
             } else {
                 $flattened = FlattenException::create($exception);
             }
             $handler = new ExceptionHandler();
             $content = $handler->getContent($flattened);
             $model = array('trace' => $content, 'exception' => $exception, 'flattened' => $flattened);
             Mail::send(Config::get("error-emailer::error_template"), $model, function ($message) use($model, $recipients) {
                 $subject = View::make(Config::get("error-emailer::subject_template"), $model)->render();
                 $message->subject($subject);
                 foreach ($recipients as $to) {
                     $message->to($to['address'], $to['name']);
                 }
             });
         }
     }
 }

作者:scrobo    项目:Lume   
public function testConfigure()
 {
     $logger = $this->getMock('Psr\\Log\\LoggerInterface');
     $userHandler = function () {
     };
     $listener = new DebugHandlersListener($userHandler, $logger);
     $xHandler = new ExceptionHandler();
     $eHandler = new ErrorHandler();
     $eHandler->setExceptionHandler(array($xHandler, 'handle'));
     $exception = null;
     set_error_handler(array($eHandler, 'handleError'));
     set_exception_handler(array($eHandler, 'handleException'));
     try {
         $listener->configure();
     } catch (\Exception $exception) {
     }
     restore_exception_handler();
     restore_error_handler();
     if (null !== $exception) {
         throw $exception;
     }
     $this->assertSame($userHandler, $xHandler->setHandler('var_dump'));
     $loggers = $eHandler->setLoggers(array());
     $this->assertArrayHasKey(E_DEPRECATED, $loggers);
     $this->assertSame(array($logger, LogLevel::INFO), $loggers[E_DEPRECATED]);
 }

作者:rlacerda8    项目:lumen-framewor   
/**
  * Render an exception into an HTTP response.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Exception  $e
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function render($request, Exception $e)
 {
     $e = FlattenException::create($e);
     $handler = new SymfonyExceptionHandler(env('APP_DEBUG', false));
     $decorated = $this->decorate($handler->getContent($e), $handler->getStylesheet($e));
     return Response::create($decorated, $e->getStatusCode(), $e->getHeaders());
 }

作者:ngitimfoy    项目:Nyari-AppPH   
public function testNestedExceptions()
 {
     $handler = new ExceptionHandler(true);
     ob_start();
     $handler->sendPhpResponse(new \RuntimeException('Foo', 0, new \RuntimeException('Bar')));
     $response = ob_get_clean();
     $this->assertStringMatchesFormat('%A<span class="exception_message">Foo</span>%A<span class="exception_message">Bar</span>%A', $response);
 }

作者:autark    项目:framewor   
protected function handleWithSymfony(Exception $exception)
 {
     if (!$exception instanceof FlattenException) {
         $exception = FlattenException::create($exception);
     }
     $handler = new ExceptionHandler($this->debug);
     return Response::create($handler->getHtml($exception), $exception->getStatusCode(), $exception->getHeaders());
 }

作者:ahmedib    项目:projec   
public function onSilexError(GetResponseForExceptionEvent $event)
 {
     if (!$this->enabled) {
         return;
     }
     $handler = new DebugExceptionHandler($this->debug);
     $event->setResponse($handler->createResponse($event->getException()));
 }

作者:MikeGeorgef    项目:sipho   
/**
  * Convert an exception to a response
  *
  * @param \Exception $exception
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function handleException($exception)
 {
     if (!$exception instanceof FlattenException) {
         $exception = FlattenException::create($exception);
     }
     $handler = new BaseExceptionHandler($this->debug);
     $decorated = $this->decorate($handler->getContent($exception), $handler->getStylesheet($exception));
     return new Response($decorated, $exception->getStatusCode(), $exception->getHeaders());
 }

作者:abdono    项目:silex_simple_ap   
public function onSilexError(GetResponseForExceptionEvent $event)
 {
     $handler = new DebugExceptionHandler($this->debug);
     $exception = $event->getException();
     if (!$exception instanceof FlattenException) {
         $exception = FlattenException::create($exception);
     }
     $response = Response::create($handler->getHtml($exception), $exception->getStatusCode(), $exception->getHeaders())->setCharset(ini_get('default_charset'));
     $event->setResponse($response);
 }

作者:despar    项目:ignicm   
public function __toString()
 {
     try {
         return parent::__toString();
         // TODO: Change the autogenerated stub
     } catch (\Exception $exc) {
         ExceptionHelper::logException($exc);
         $eh = new ExceptionHandler(env('APP_DEBUG'));
         die($eh->getHtml($exc));
     }
 }

作者:xingshangh    项目:symfon   
/**
  * Renders the exception panel stylesheet for the given token.
  *
  * @param string $token The profiler token
  *
  * @return Response A Response instance
  *
  * @throws NotFoundHttpException
  */
 public function cssAction($token)
 {
     if (null === $this->profiler) {
         throw new NotFoundHttpException('The profiler must be enabled.');
     }
     $this->profiler->disable();
     $exception = $this->profiler->loadProfile($token)->getCollector('exception')->getException();
     $template = $this->getTemplate();
     if (!$this->templateExists($template)) {
         $handler = new ExceptionHandler($this->debug, $this->twig->getCharset());
         return new Response($handler->getStylesheet($exception), 200, array('Content-Type' => 'text/css'));
     }
     return new Response($this->twig->render('@WebProfiler/Collector/exception.css.twig'), 200, array('Content-Type' => 'text/css'));
 }

作者:ilosad    项目:chamilo-lms-icpn   
/**
  * @param Request          $request
  * @param FlattenException $exception
  * @param string           $format
  */
 public function showAction(Request $request, FlattenException $exception, $format)
 {
     $handler = new ExceptionHandler($this->pimple['debug']);
     if ($this->pimple['debug']) {
         return $handler->createResponse($exception);
     }
     $code = $exception->getStatusCode();
     $template = $this->resolve($request, $code, $format);
     if ($template) {
         $contents = $this->pimple['twig']->render($template, array('status_code' => $code, 'status_text' => isset(Response::$statusTexts[$code]) ? Response::$statusTexts[$code] : '', 'exception' => $exception));
         return new Response($contents, $code);
     }
     return $handler->createResponse($exception);
 }

作者:VOLKERMOR    项目:phpb   
/**
  * Enables the debug tools.
  *
  * This method registers an error handler and an exception handler.
  *
  * If the Symfony ClassLoader component is available, a special
  * class loader is also registered.
  *
  * @param int  $errorReportingLevel The level of error reporting you want
  * @param bool $displayErrors       Whether to display errors (for development) or just log them (for production)
  */
 public static function enable($errorReportingLevel = null, $displayErrors = true)
 {
     if (static::$enabled) {
         return;
     }
     static::$enabled = true;
     if ($errorReportingLevel !== null) {
         error_reporting($errorReportingLevel);
     } else {
         error_reporting(-1);
     }
     if ('cli' !== php_sapi_name()) {
         ini_set('display_errors', 0);
         ExceptionHandler::register();
     } else {
         if ($displayErrors && (!ini_get('log_errors') || ini_get('error_log'))) {
             // CLI - display errors only if they're not already logged to STDERR
             ini_set('display_errors', 1);
         }
     }
     if ($displayErrors) {
         error_handler::register(new error_handler(new BufferingLogger()));
     } else {
         error_handler::register()->throwAt(0, true);
     }
     DebugClassLoader::enable();
 }

作者:cmsile    项目:cmsile   
public function bootstrap()
 {
     $app = $this;
     $app['dir.base'] = __DIR__ . "/../../../../";
     $app->register(new ConfigServiceProvider());
     $app['debug'] = $app['config']['debug'];
     ErrorHandler::register();
     ExceptionHandler::register($app['debug']);
     $app->register(new HttpFragmentServiceProvider());
     $app->register(new ServiceControllerServiceProvider());
     $app->register(new ORMServiceProvider());
     $app->register(new SessionServiceProvider());
     $app->register(new SecurityServiceProvider());
     $app['security.encoder.digest'] = function ($app) {
         // uses the password-compat encryption
         return new BCryptPasswordEncoder(10);
     };
     $app->register(new ManagerRegistryServiceProvider());
     $app['security.firewalls'] = array('default' => array('pattern' => '/', 'form' => array('login_path' => '/login', 'check_path' => '/login_check'), 'logout' => array('logout_path' => '/logout', 'invalidate_session' => true), 'users' => function () use($app) {
         return new EntityUserProvider($app['manager_registry'], User::class, 'username');
     }, 'anonymous' => true));
     $app['security.access_rules'] = [['^/admin', 'ROLE_ADMIN']];
     $app->register(new TranslationServiceProvider(), array('locale_fallbacks' => array('en'), 'locale' => 'en'));
     $app->register(new ValidatorServiceProvider());
     $app->register(new FormServiceProvider());
     $app->register(new TwigServiceProvider(), ['twig.path' => __DIR__ . '/../resources/views', 'twig.form.templates' => ['bootstrap_3_layout.html.twig'], 'twig.strict_variables' => false]);
     $app->extend('twig', function (\Twig_Environment $twig) {
         $twig->addTest(new \Twig_SimpleTest('callable', function ($variable) {
             return is_callable($variable);
         }));
         $twig->addFunction(new \Twig_SimpleFunction('is_callable', function ($variable) {
             return is_callable($variable);
         }));
         $twig->addFunction(new \Twig_SimpleFunction('call_user_func', function ($callable, $params = null) {
             return call_user_func($callable, $params);
         }));
         $twig->getExtension('core')->setDateFormat('Y/m/d', '%d days');
         return $twig;
     });
     $app->extend('form.types', function ($types) use($app) {
         $types[] = new EntityType($app['manager_registry']);
         $types[] = new TemplateChoiceType($app['theme']);
         $types[] = new PageType($app['theme']);
         return $types;
     });
     $app->register(new SerializerServiceProvider());
     $app->register(new WebProfilerServiceProvider(), ['profiler.cache_dir' => './../storage/framework/cache/profiler', 'web_profiler.debug_toolbar.enable' => $app['debug'], 'profiler.mount_prefix' => '/admin/_profiler']);
     $app['finder'] = function () {
         return new Finder();
     };
     $app['filesystem'] = function () {
         return new Filesystem();
     };
     $app->register(new ConverterServiceProvider());
     $app->register(new ThemeServiceProvider());
     $app['twig.loader.filesystem']->addPath($app['dir.theme'], 'theme');
     $app->register(new CMSServiceProvider());
     $app->setRoutes();
 }

作者:jonathanpmartin    项目:lumen-framewor   
/**
  * Render an exception into an HTTP response.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Exception  $e
  * @return \Illuminate\Http\Response
  */
 public function render($request, Exception $e)
 {
     if ($e instanceof HttpResponseException) {
         return $e->getResponse();
     } elseif ($e instanceof ModelNotFoundException) {
         $e = new NotFoundHttpException($e->getMessage(), $e);
     } elseif ($e instanceof AuthorizationException) {
         $e = new HttpException(403, $e->getMessage());
     } elseif ($e instanceof ValidationException && $e->getResponse()) {
         return $e->getResponse();
     }
     $fe = FlattenException::create($e);
     $handler = new SymfonyExceptionHandler(env('APP_DEBUG', false));
     $decorated = $this->decorate($handler->getContent($fe), $handler->getStylesheet($fe));
     $response = new Response($decorated, $fe->getStatusCode(), $fe->getHeaders());
     $response->exception = $e;
     return $response;
 }

作者:jacobjj    项目:PageKit-framewor   
public function register(Application $app)
 {
     $debug = isset($app['config']) ? $app['config']['app.debug'] : true;
     $handler = ExceptionHandler::register($debug);
     ErrorHandler::register(E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR | E_RECOVERABLE_ERROR);
     if ($cli = $app->runningInConsole() or $debug) {
         ini_set('display_errors', 1);
     }
     $app['exception'] = $handler;
 }

作者:nawras    项目:tvguid   
public function __construct()
 {
     parent::__construct();
     // Convert errors to exceptions
     ErrorHandler::register();
     ExceptionHandler::register();
     $this['cache.directory'] = __DIR__ . '/../../../app/cache';
     $this['vendor.directory'] = __DIR__ . '/../../../vendor';
     $this->registerControllers();
     $this->registerServiceProviders();
     $this->registerInternalServices();
 }

作者:izziaraffael    项目:webcompose   
public function register(Application $app)
 {
     ErrorHandler::register();
     ExceptionHandler::register($app['debug']);
     $app->error(function (\Exception $exception, $code) use($app) {
         if (!$app['debug'] || $code === 404) {
             // 404.html, or 40x.html, or 4xx.html, or error.html
             $templates = array('errors/' . $code . '.html.twig', 'errors/' . substr($code, 0, 2) . 'x.html.twig', 'errors/' . substr($code, 0, 1) . 'xx.html.twig', 'errors/' . 'default.html.twig');
             return new Response($app['twig']->resolveTemplate($templates)->render(array('code' => $code)), $code);
         }
     });
 }

作者:billwaddyj    项目:Favorite-This-Dem   
/**
  * Enables the debug tools.
  *
  * This method registers an error handler and an exception handler.
  *
  * If the Symfony ClassLoader component is available, a special
  * class loader is also registered.
  *
  * @param integer $errorReportingLevel The level of error reporting you want
  * @param Boolean $displayErrors       Whether to display errors (for development) or just log them (for production)
  */
 public static function enable($errorReportingLevel = null, $displayErrors = true)
 {
     if (static::$enabled) {
         return;
     }
     static::$enabled = true;
     error_reporting(-1);
     ErrorHandler::register($errorReportingLevel, $displayErrors);
     if ('cli' !== php_sapi_name()) {
         ExceptionHandler::register();
         // CLI - display errors only if they're not already logged to STDERR
     } elseif ($displayErrors && (!ini_get('log_errors') || ini_get('error_log'))) {
         ini_set('display_errors', 1);
     }
     DebugClassLoader::enable();
 }

作者:johnarben246    项目:sampleffuf-cor   
public function onKernelException(GetResponseForExceptionEvent $e)
 {
     $ex = $e->getException();
     $response = new Response();
     if ($ex instanceof NotFoundHttpException) {
         $response->setContent($this->view->render('error/404'));
         $e->setResponse($response);
         return;
     }
     if ($this->debugMode) {
         \Symfony\Component\Debug\ExceptionHandler::register();
         throw $ex;
     }
     $response->setContent($this->view->render('error/exception'));
     $e->setResponse($response);
     $this->logger->handleException($ex);
 }

作者:ioano    项目:symfoxi   
/**
  * Sets default exception handler.
  *
  * If shop is in productive mode stick to default OXID exception handler
  * Else register Symfony Debug component's Exception and Error handlers
  *
  * Non-productive eShop mode is intended for eShop installation, configuration, template customization and module debugging phase.
  * As soon as productive mode is turned ON, the cache handling and the error reporting behavior is optimized for the live shop.
  */
 protected function _setDefaultExceptionHandler()
 {
     /**
      * @todo: consider also getEnvironment() function to detect environment
      */
     if (oxRegistry::getConfig()->isProductiveMode()) {
         parent::_setDefaultExceptionHandler();
         return;
     }
     /**
      * Debug::enable() also registers a DebugClassLoader which throw an error because oxid does not care about case when referring to objects
      * symfony is key sensitive:  oxarticlelist != oxArticleList
      */
     //Debug\Debug::enable();
     ini_set('display_errors', 0);
     Debug\ExceptionHandler::register();
     Debug\ErrorHandler::register()->throwAt(0, true);
 }


问题


面经


文章

微信
公众号

扫码关注公众号