Skip to content

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

License

Notifications You must be signed in to change notification settings

fuko-php/source

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Fuko\Source GitHub license Latest Version

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