bakaphp /
phalcon-api
| 1 | <?php |
||
|
0 ignored issues
–
show
Coding Style
introduced
by
Loading history...
|
|||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace Gewaer; |
||
| 6 | |||
| 7 | use Monolog\Logger; |
||
| 8 | use Phalcon\Config; |
||
| 9 | |||
| 10 | /** |
||
| 11 | * Class ErrorHandler |
||
| 12 | * |
||
| 13 | * @package Gewaer |
||
| 14 | */ |
||
| 15 | class ErrorHandler |
||
| 16 | {
|
||
| 17 | /** @var Config */ |
||
| 18 | private $config; |
||
| 19 | |||
| 20 | /** @var Logger */ |
||
| 21 | private $logger; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * ErrorHandler constructor. |
||
| 25 | * |
||
| 26 | * @param Logger $logger |
||
| 27 | * @param Config $config |
||
| 28 | */ |
||
| 29 | 6 | public function __construct(Logger $logger, Config $config) |
|
| 30 | {
|
||
| 31 | 6 | $this->config = $config; |
|
| 32 | 6 | $this->logger = $logger; |
|
| 33 | 6 | } |
|
| 34 | |||
| 35 | /** |
||
| 36 | * Handles errors by logging them |
||
| 37 | * |
||
| 38 | * @param int $number |
||
| 39 | * @param string $message |
||
| 40 | * @param string $file |
||
| 41 | * @param int $line |
||
| 42 | */ |
||
| 43 | 2 | public function handle(int $number, string $message, string $file = '', int $line = 0) |
|
| 44 | {
|
||
| 45 | $this |
||
| 46 | 2 | ->logger |
|
| 47 | 2 | ->error( |
|
| 48 | 2 | sprintf( |
|
| 49 | 2 | '[#:%s]-[L: %s] : %s (%s)', |
|
| 50 | 2 | $number, |
|
| 51 | 2 | $line, |
|
| 52 | 2 | $message, |
|
| 53 | 2 | $file |
|
| 54 | ) |
||
| 55 | ); |
||
| 56 | 2 | } |
|
| 57 | |||
| 58 | /** |
||
| 59 | * Application shutdown - logs metrics in devMode |
||
| 60 | */ |
||
| 61 | 1 | public function shutdown() |
|
| 62 | {
|
||
| 63 | 1 | if (true === $this->config->path('app.devMode')) {
|
|
| 64 | 1 | $memory = number_format(memory_get_usage() / 1000000, 2); |
|
| 65 | 1 | $execution = number_format( |
|
| 66 | 1 | microtime(true) - $this->config->path('app.time'),
|
|
| 67 | 1 | 4 |
|
| 68 | ); |
||
| 69 | |||
| 70 | $this |
||
| 71 | 1 | ->logger |
|
| 72 | 1 | ->info( |
|
| 73 | 1 | sprintf( |
|
| 74 | 1 | 'Shutdown completed [%s]s - [%s]MB', |
|
| 75 | 1 | $execution, |
|
| 76 | 1 | $memory |
|
| 77 | ) |
||
| 78 | ); |
||
| 79 | } |
||
| 80 | 1 | } |
|
| 81 | } |
||
| 82 |