src/Leevel/Kernel/Utils/Doc.php
public static function getClassBody(string $className): string
    {
        $doc = new static('');

        $lines = $doc->parseFileContnet($reflectionClass = new ReflectionClass($className));

        $startLine = $reflectionClass->getStartLine() - 1;
        $endLine = $reflectionClass->getEndLine();
        $hasUse = false;
        $result = [];
        $result[] = 'namespace '.$reflectionClass->getNamespaceName().';';
        $result[] = '';

        foreach ($lines as $k => $v) {
            if ($k < $startLine || $k >= $endLine) {
                // 适用于一个文件只有一个类的情况
                if ($k < $startLine && 0 === strpos($v, 'use ')) {
                    $result[] = $v;
                    $hasUse = true;
                }

                continue;
            }

            if ($k === $startLine && true === $hasUse) {
                $result[] = '';
            }

            $result[] = $v;
        }

        return implode(PHP_EOL, $result);
    }
public static function getClassBody(string $className): string
    {
        $doc = new static('');

        $lines = $doc->parseFileContnet($reflectionClass = new ReflectionClass($className));

        $startLine = $reflectionClass->getStartLine() - 1;
        $endLine = $reflectionClass->getEndLine();
        $hasUse = false;
        $result = [];
        $result[] = 'namespace '.$reflectionClass->getNamespaceName().';';
        $result[] = '';

        foreach ($lines as $k => $v) {
            if ($k < $startLine || $k >= $endLine) {
                // 适用于一个文件只有一个类的情况
                if ($k < $startLine && 0 === strpos($v, 'use ')) {
                    $result[] = $v;
                    $hasUse = true;
                }

                continue;
            }

            if ($k === $startLine && true === $hasUse) {
                $result[] = '';
            }

            $result[] = $v;
        }

        return implode(PHP_EOL, $result);
    }
获取类内容.

@param string $className

@return string