public function initErrorHandler(Config $config)
    {
        if ($this->getDI()->get('environment') === Constants::PROD_ENV) {
            return;
        }

        $this->debug = new Debug();
        $this->debug->listen();

        set_error_handler([$this, 'errorHandler'], error_reporting());

        register_shutdown_function(function() {
            if ((error_reporting() & E_ERROR) === E_ERROR) {
                $lastError = error_get_last();

                if ($lastError['type'] === E_ERROR) {
                    // fatal error
                    $this->errorHandler(E_ERROR, $lastError['message'], $lastError['file'], $lastError['line']);
                }
            }
        });
    }