think\exception\Handle::getSourceCode PHP Метод

getSourceCode() защищенный Метод

获取出错文件内容 获取错误的前9行和后9行
protected getSourceCode ( Exception $exception ) : array
$exception Exception
Результат array 错误文件内容
    protected function getSourceCode(Exception $exception)
    {
        // 读取前9行和后9行
        $line = $exception->getLine();
        $first = $line - 9 > 0 ? $line - 9 : 1;
        try {
            $contents = file($exception->getFile());
            $source = ['first' => $first, 'source' => array_slice($contents, $first - 1, 19)];
        } catch (Exception $e) {
            $source = [];
        }
        return $source;
    }