environment = $environment; set_error_handler([$this, 'errorHandler']); set_exception_handler([$this, 'exceptionHandler']); } /** * @param int $number * @param string $string * @param string $file * @param int $line * @param array $context */ public function errorHandler($number, $string, $file, $line, $context) { $this->handle('error', $number, $string, $file, $line, $context); } /** * @param Exception $e */ public function exceptionHandler(Exception $e) { $this->handle( 'exception', $e->getCode(), get_class($e) . ': ' . $e->getMessage(), $e->getFile(), $e->getLine(), ['exception' => $e] ); } /** * @param string $type * @param int $number * @param string $string * @param string $file * @param int $line * @param array $context */ protected function handle($type, $number, $string, $file, $line, $context = []) { error_log(sprintf('%s: Number: %s, String: %s, File: %s:%u, Context: %s', $type, $number, $string, $file, $line, json_encode($context) )); if ($this->environment == self::ENV_DEVELOPMENT) { echo '
'; echo sprintf('%s: (%s)' . PHP_EOL, ucfirst($type), $number); var_export([ 'string' => $string, 'file' => $file . ':' . $line, 'context' => ($this->environment == self::ENV_DEVELOPMENT ? $context : null), ]); echo ''; die(); } echo 'An