fuko-php/source

Extracts chunks of source code identified by code references, e.g. filename + line

1.0.0 2021-06-08 09:02 UTC

This package is auto-updated.

Last update: 2024-04-08 15:10:40 UTC


README

Fuko\Source is a small PHP library that helps you to extracts chunks of source code identified by code references, e.g. filename + line.

It is really simple to use. Imagine you want to extract a piece of code, and you know what source code line exactly you want to reference: for example /var/www/html/index.php at line 17. You must first create a new \Fuko\Source\Code object, and then call the getLinesAt() method:

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);
)
*/

By default there are 7 lines of code (LOCs) returned, but you can specify a different number in the range of 1 to 20 (as defined in \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');
)
*/