<?php

use xmvc\MVC;
use xmvc\Log;

// @codingStandardsIgnoreStart
if($error){
	!isset($error['method']) && $error['method'] = '';
	if (in_array($error['type'], [E_WARNING, E_ERROR, E_PARSE, E_CORE_ERROR, E_COMPILE_ERROR, E_USER_ERROR])) {
		Log::channel('error');
		if($error['type'] == E_WARNING){
			Log::critical($error['message'], $error);
			$message = "<h1>WARNING: " . lg('程序执行完成, 但出现警告信息') . "</h1>\r\n";
		}else{
			Log::emergency($error['message'], $error);
			$message = "<h1>ERROR: " . lg('发生异常, 详细信息请联系管理员查阅错误日志'). "</h1>\r\n";
		}
		$file = relDir(dirname($error['file'])) . '/' . str_replace('.php', '.py', basename($error['file']));
		$message .=  "[ " . date('Y-m-d H:i:s') . " ] Stop By: " . $file . " Line: " . $error['line'] . "\r\n";
		if($error['method']){
			$message .= ", Call: ". $error['method'] . "()\r\n";
		}
		if (IS_CLI) {
			echo $error['message'] . "\r\n";
			echo $message;
		} else {
			MVC::warning($message);
		}
	}
}
