You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.3 KiB

3 years ago
  1. ErrorHandler Component
  2. ======================
  3. The ErrorHandler component provides tools to manage errors and ease debugging PHP code.
  4. Getting Started
  5. ---------------
  6. ```
  7. $ composer require symfony/error-handler
  8. ```
  9. ```php
  10. use Symfony\Component\ErrorHandler\Debug;
  11. use Symfony\Component\ErrorHandler\ErrorHandler;
  12. use Symfony\Component\ErrorHandler\DebugClassLoader;
  13. Debug::enable();
  14. // or enable only one feature
  15. //ErrorHandler::register();
  16. //DebugClassLoader::enable();
  17. // If you want a custom generic template when debug is not enabled
  18. // HtmlErrorRenderer::setTemplate('/path/to/custom/error.html.php');
  19. $data = ErrorHandler::call(static function () use ($filename, $datetimeFormat) {
  20. // if any code executed inside this anonymous function fails, a PHP exception
  21. // will be thrown, even if the code uses the '@' PHP silence operator
  22. $data = json_decode(file_get_contents($filename), true);
  23. $data['read_at'] = date($datetimeFormat);
  24. file_put_contents($filename, json_encode($data));
  25. return $data;
  26. });
  27. ```
  28. Resources
  29. ---------
  30. * [Contributing](https://symfony.com/doc/current/contributing/index.html)
  31. * [Report issues](https://github.com/symfony/symfony/issues) and
  32. [send Pull Requests](https://github.com/symfony/symfony/pulls)
  33. in the [main Symfony repository](https://github.com/symfony/symfony)