XSException
包 | XS |
---|---|
继承关系 | class XSException » Exception |
子类 | XSErrorException |
版本 | 1.0.0 |
源代码 | sdk/php/lib/XS.class.php |
XS 异常类定义, XS 所有操作过程发生异常均抛出该实例
Public 方法
名称 | 描述 | 定义于 |
---|---|---|
__construct() | Exception | |
__toString() | 将类对象转换成字符串 | XSException |
getCode() | Exception | |
getFile() | Exception | |
getLine() | Exception | |
getMessage() | Exception | |
getPrevious() | Exception | |
getRelPath() | 取得相对当前的文件路径 | XSException |
getTrace() | Exception | |
getTraceAsString() | Exception |
方法明细
__toString()
方法
public string __toString()
| ||
{return} | string | 异常的简要描述信息 |
源码: sdk/php/lib/XS.class.php#L67 (显示)
public function __toString()
{
$string = '[' . __CLASS__ . '] ' . $this->getRelPath($this->getFile()) . '(' . $this->getLine() . '): ';
$string .= $this->getMessage() . ($this->getCode() > 0 ? '(S#' . $this->getCode() . ')' : '');
return $string;
}
将类对象转换成字符串
getRelPath()
方法
public static string getRelPath(string $file)
| ||
$file | string | 需要转换的绝对路径 |
{return} | string | 转换后的相对路径 |
源码: sdk/php/lib/XS.class.php#L79 (显示)
public static function getRelPath($file)
{
$from = getcwd();
$file = realpath($file);
if (is_dir($file))
{
$pos = false;
$to = $file;
}
else
{
$pos = strrpos($file, '/');
$to = substr($file, 0, $pos);
}
for ($rel = '';; $rel .= '../')
{
if ($from === $to)
break;
if ($from === dirname($from))
{
$rel .= substr($to, 1);
break;
}
if (!strncmp($from . '/', $to, strlen($from) + 1))
{
$rel .= substr($to, strlen($from) + 1);
break;
}
$from = dirname($from);
}
if (substr($rel, -1, 1) === '/')
$rel = substr($rel, 0, -1);
if ($pos !== false)
$rel .= substr($file, $pos);
return $rel;
}
取得相对当前的文件路径