lithium\analysis\Inspector::lines()
Returns an array of lines from a file, class, or arbitrary string, where $data is the data to read the lines from and $lines is an array of line numbers specifying which lines should be read.
Parameters
-
string
$data
If
$data
contains newlines, it will be read from directly, and have its own lines returned. If$data
is a physical file path, that file will be read and have its lines returned. If$data
is a class name, it will be converted into a physical file path and read. -
array
$lines
The array of lines to read. If a given line is not present in the data, it will be silently ignored.
Returns
arrayReturns an array where the keys are matching $lines
, and the values are the
corresponding line numbers in $data
.
Source
public static function lines($data, $lines) {
$c = [];
if (strpos($data, PHP_EOL) !== false) {
$c = explode(PHP_EOL, PHP_EOL . $data);
} else {
if (!file_exists($data)) {
$data = Libraries::path($data);
if (!file_exists($data)) {
return null;
}
}
$file = new SplFileObject($data);
foreach ($file as $current) {
$c[$file->key() + 1] = rtrim($file->current());
}
}
if (!count($c) || !count($lines)) {
return null;
}
return array_intersect_key($c, array_combine($lines, array_fill(0, count($lines), null)));
}