fuko-php / source
提取通过代码引用标识的源代码块,例如:文件名 + 行号
1.0.0
2021-06-08 09:02 UTC
Requires
- php: >=7.1
Requires (Dev)
- phpunit/phpunit: ^7.5 || ^8.5
README
Fuko\Source 是一个小的 PHP 库,它可以帮助你提取通过代码引用标识的源代码块,例如:文件名 + 行号。
使用非常简单。想象一下,你想提取一段代码,并且你知道你想要引用的确切源代码行:例如 /var/www/html/index.php 第 17 行。你必须首先创建一个新的 \Fuko\Source\Code 对象,然后调用 getLinesAt() 方法
include __DIR__ . '/vendor/autoload.php'; $source = new \Fuko\Source\Code('/var/www/html/index.php'); print_r($source->getLinesAt(17)); /* Array ( [14] => Illuminate\Support\ClassLoader::register(); [15] => Illuminate\Support\ClassLoader::addDirectories(array(CLASS_DIR,CONTROLLERS,CONTROLLERS.'Middleware/', MODELS, CONTROLLERS.'Admin/')); [16] => [17] => $FileLoader = new FileLoader(new Filesystem, RESOURCES.'lang'); [18] => $translator = new Translator($FileLoader, 'en'); [19] => $Container = new Container(); [20] => $validation = new Factory($translator, $Container); ) */
默认返回 7 行代码(LOC),但你可以指定一个 1 到 20 之间的不同数字(如 \Fuko\Source\Code::LOC_MAX 中定义的)
include __DIR__ . '/vendor/autoload.php'; $source = new \Fuko\Source\Code('/var/www/html/index.php'); print_r($source->getLinesAt(17, 1)); /* Array ( [17] => $FileLoader = new FileLoader(new Filesystem, RESOURCES.'lang'); ) */