| 包 | XS | 
|---|---|
| 继承关系 | class XSException » Exception | 
| 实现接口 | Throwable | 
| 子类 | XSErrorException | 
| 版本 | 1.0.0 | 
| 源代码 | sdk/php/lib/XS.class.php | 
| 名称 | 描述 | 定义于 | 
|---|---|---|
| __construct() | Exception | |
| __toString() | 将类对象转换成字符串 | XSException | 
| __wakeup() | Exception | |
| getCode() | Exception | |
| getFile() | Exception | |
| getLine() | Exception | |
| getMessage() | Exception | |
| getPrevious() | Exception | |
| getRelPath() | 取得相对当前的文件路径 | XSException | 
| getTrace() | Exception | |
| getTraceAsString() | Exception | 
| 
public string __toString() | ||
| {return} | string | 异常的简要描述信息 | 
public function __toString()
{
    $string = '[' . __CLASS__ . '] ' . $this->getRelPath($this->getFile()) . '(' . $this->getLine() . '): ';
    $string .= $this->getMessage() . ($this->getCode() > 0 ? '(S#' . $this->getCode() . ')' : '');
    return $string;
}
将类对象转换成字符串
| 
public static string getRelPath(string $file) | ||
| $file | string | 需要转换的绝对路径 | 
| {return} | string | 转换后的相对路径 | 
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;
}
取得相对当前的文件路径
| 包 | XS | 
|---|---|
| 继承关系 | class XSException » Exception | 
| 实现接口 | Throwable | 
| 子类 | XSErrorException | 
| 版本 | 1.0.0 | 
| 源代码 | sdk/php/lib/XS.class.php | 
| 名称 | 描述 | 定义于 | 
|---|---|---|
| __construct() | Exception | |
| __toString() | 将类对象转换成字符串 | XSException | 
| __wakeup() | Exception | |
| getCode() | Exception | |
| getFile() | Exception | |
| getLine() | Exception | |
| getMessage() | Exception | |
| getPrevious() | Exception | |
| getRelPath() | 取得相对当前的文件路径 | XSException | 
| getTrace() | Exception | |
| getTraceAsString() | Exception | 
| 
public string __toString() | ||
| {return} | string | 异常的简要描述信息 | 
public function __toString()
{
    $string = '[' . __CLASS__ . '] ' . $this->getRelPath($this->getFile()) . '(' . $this->getLine() . '): ';
    $string .= $this->getMessage() . ($this->getCode() > 0 ? '(S#' . $this->getCode() . ')' : '');
    return $string;
}
将类对象转换成字符串
| 
public static string getRelPath(string $file) | ||
| $file | string | 需要转换的绝对路径 | 
| {return} | string | 转换后的相对路径 | 
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;
}
取得相对当前的文件路径
一条评论!
大家不觉得少了“异常code”列表吗?对异常做针对处理要用的,文档里没有。。。
请到论坛 登录 后刷新本页面!