lithium\analysis\Inspector::lines PHP Method

lines() public static method

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.
public static lines ( string $data, array $lines ) : array
$data string 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.
$lines array The array of lines to read. If a given line is not present in the data, it will be silently ignored.
return array Returns an array where the keys are matching `$lines`, and the values are the corresponding line numbers in `$data`.
    public static function lines($data, $lines)
    {
        $c = array();
        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)));
    }

Usage Example

Beispiel #1
0
 protected static function _method(array $object, array $data, array $options = array())
 {
     if (!$data) {
         return array();
     }
     $lines = Inspector::lines($data['file'], range($data['start'], $data['end']));
     $object = array('source' => join("\n", $lines)) + $object;
     $object += array('tags' => isset($data['tags']) ? $data['tags'] : array());
     if (isset($object['tags']['return'])) {
         list($type, $text) = explode(' ', $object['tags']['return'], 2) + array('', '');
         $object['return'] = compact('type', 'text');
     }
     return $object;
 }
All Usage Examples Of lithium\analysis\Inspector::lines