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