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 | public function __construct(Logger $logger, Config $config) |
||
| 30 | {
|
||
| 31 | $this->config = $config; |
||
| 32 | $this->logger = $logger; |
||
| 33 | } |
||
| 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 | public function handle(int $number, string $message, string $file = '', int $line = 0) |
||
| 44 | {
|
||
| 45 | $this |
||
| 46 | ->logger |
||
| 47 | ->error( |
||
| 48 | sprintf( |
||
| 49 | '[#:%s]-[L: %s] : %s (%s)', |
||
| 50 | $number, |
||
| 51 | $line, |
||
| 52 | $message, |
||
| 53 | $file |
||
| 54 | ) |
||
| 55 | ); |
||
| 56 | } |
||
| 57 | |||
| 58 | /** |
||
| 59 | * Application shutdown - logs metrics in devMode |
||
| 60 | */ |
||
| 61 | public function shutdown() |
||
| 62 | {
|
||
| 63 | if (true === $this->config->path('app.devMode')) {
|
||
| 64 | $memory = number_format(memory_get_usage() / 1000000, 2); |
||
| 65 | $execution = number_format( |
||
| 66 | microtime(true) - $this->config->path('app.time'),
|
||
| 67 | 4 |
||
| 68 | ); |
||
| 69 | |||
| 70 | $this |
||
| 71 | ->logger |
||
| 72 | ->info( |
||
| 73 | sprintf( |
||
| 74 | 'Shutdown completed [%s]s - [%s]MB', |
||
| 75 | $execution, |
||
| 76 | $memory |
||
| 77 | ) |
||
| 78 | ); |
||
| 79 | } |
||
| 80 | } |
||
| 81 | } |
||
| 82 |