<?php


namespace App\Exception;

/*
 * 重写Handle的render方法，实现自定义异常消息
 */

use Helpers\ApiResponse;
use Yaf\Registry;

class ErrorHandler
{
    use ApiResponse;

    private $http_code;
    private $msg;
    private $code;

    public function render($errno, $errstr, $errfile, $errline)
    {
        $debug = Registry::get('config')->debug;

        $msg = ' file_name : '.$errfile . '<br> line_num : '.$errline . '<br> message : ' . $errstr;
        if($debug){
            echo $msg;
            exit;
        }

        $this->msg  = Registry::get('config')->exception->sys->msg;
        $this->code = Registry::get('config')->exception->sys->code;

        $this->recordErrorLog($msg);
        $this->failed($this->code, $this->msg);
    }

    /*
     * 将异常写入日志
     */
    private function recordErrorLog($msg)
    {
//        LogUtil::error('Error handler', $msg);
    }
}