<?php
// +----------------------------------------------------------------------
// | h-admin
// +----------------------------------------------------------------------
// | 错误提取和设置
// +----------------------------------------------------------------------
// | Author: waiszer <waiszer@163.com>
// +----------------------------------------------------------------------
declare(strict_types = 1);
namespace app\common\traits;
trait Error
{
public static string $staticErrorMsg = '';
public static int $staticErrorCode = 0;
public static mixed $staticErrorData = null;
public static mixed $staticErrorFile = null;
public static mixed $staticErrorLine = null;
public string $errorMsg = '';
public int $errorCode = 0;
public mixed $errorData = null;
public mixed $errorFile = null;
public mixed $errorLine = null;
/**
* 设置错误信息
* @param string $error
* @param int $code
* @param null $data
* @param string|null $file
* @param int|null $line
* @return void
*/
public function setError(string $error = '', int $code = 0, $data = null, ?string $file = null, ?int $line = null): void
{
$this->errorMsg = $error;
$this->errorCode = $code;
$this->errorData = $data;
$this->errorFile = $file;
$this->errorLine = $line;
}
/**
* 获取错误信息
* @return string
*/
public function getError(): string
{
return $this->errorMsg;
}
/**
* 获取错误码
* @return int
*/
public function getErrorCode(): int
{
return $this->errorCode;
}
/**
* 获取错误数据
* @return mixed
*/
public function getErrorData(): mixed
{
return $this->errorData;
}
/**
* 获取错误文件和行数
* @return mixed
*/
public function getErrorFile(): mixed
{
return $this->errorFile;
}
/**
* 获取错误文件和行数
* @return mixed
*/
public function getErrorLine(): mixed
{
return $this->errorLine;
}
/**
* 静态方法设置错误信息
* @param string $error
* @param int $code
* @param null $data
* @param string|null $file
* @param int|null $line
* @return void
*/
public static function setStaticError(string $error = '', int $code = 0, $data = null, ?string $file = null, ?int $line = null): void
{
self::$staticErrorMsg = $error;
self::$staticErrorCode = $code;
self::$staticErrorData = $data;
self::$staticErrorFile = $file;
self::$staticErrorLine = $line;
}
/**
* 获取错误信息
* @return string
*/
public static function getStaticError(): string
{
return self::$staticErrorMsg;
}
/**
* 获取错误码
* @return int
*/
public static function getStaticErrorCode(): int
{
return self::$staticErrorCode;
}
/**
* 获取错误信息
* @return mixed
*/
public static function getStaticData(): mixed
{
return self::$staticErrorData;
}
/**
* 获取错误文件行数
* @return mixed
*/
public static function getStaticFile(): mixed
{
return self::$staticErrorFile;
}
/**
* 获取错误文件行数
* @return mixed
*/
public static function getStaticLine(): mixed
{
return self::$staticErrorLine;
}
}
PHP traits Error
- 哇哈哈
- 0