Get the objects of a tailed file

@param string $filepath
@param int $lines
@param bool $desc
@return array
331869
public function objectTail($filepath, $lines = 1, $desc = true)
    {
        $data = $this->tail($filepath, $lines);
        $tailed_log = explode(PHP_EOL, $data);
        $line_objects = [];

        foreach ($tailed_log as $line) {
            $line_objects[] = $this->parse($line);
        }

        return $desc ? $line_objects : array_reverse($line_objects);
    }
149401
public static function getInstance($filePath = "/data/config/", $fileExt = "json")
    {
        if (!self::$instance) {
            self::$instance = new self($filePath, $fileExt);
        }

        return self::$instance;
    }
1364179
private List<FieldNode> getFieldsByDesc(String desc, List<FieldNode> fields) {
        List<FieldNode> result = new ArrayList<FieldNode>();
        for (FieldNode fn : fields) {
            if (desc.equals(fn.desc)) {
                result.add(fn);
            }
        }
        return result;
    }
1069100
public static function openFile($filepath)
    {
        $contents = null;

        if ($realPath = realpath($filepath)) {
            $handle = fopen($realPath, 'rb');
            $contents = fread($handle, filesize($realPath));
            fclose($handle);
        }

        return $contents;
    }
320815
public function extract($filePath)
    {
        $directory = $this->directory->getDirectoryPath();
        $rarArchive = RarArchive::open($filePath);
        $rarEntries = $rarArchive->getEntries();

        /**
         * @var RarEntry $rarEntiry
         */
        foreach ($rarEntries as $rarEntry) {

            $rarEntry->extract($directory);
        }

        return $this->createFinderFromDirectory($directory);
    }
1257805
public static function returnMatchingLinesFromFile($filePath, $textMatch) {
        $allLines = file($filePath);
        $matches = preg_grep("/" . $textMatch . "/i", $allLines);

        $cleanMatches = array_map(function ($str) {
            return str_replace(PHP_EOL, '', $str);
        }, $matches);

        return $cleanMatches;
    }
1172903
public function openFileAsArray(string $filepath):array
    {
        if ($filepath == $this->filepath && $this->file != null) {
            return ($this->file);
        }

        if (!file_exists($filepath)) {
            Server::create($filepath, 'file');
        }

        if (!is_readable($filepath)) {
            throw new Server500(new \ArrayObject(array("explain" =>
                "Cannot open file $filepath : File not readable",
                "solution" => "Please set the readable permission")));
        }

        $this->perm = null;
        $this->filepath = $filepath;
        $this->file = file($filepath);

        if (!is_array($this->file)) {
            throw new Server500(new \ArrayObject(array("explain" =>
                "Invalid file array for $filepath",
                "solution" =>
                    "Use FileListener::open to open a file resource.")));
        }

        return ($this->file);
    }
679744
protected function readLinesFromFile($filePath)
    {
        // Read file into an array of lines with auto-detected line endings
        $autodetect = ini_get('auto_detect_line_endings');
        ini_set('auto_detect_line_endings', '1');
        $lines = file($filePath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
        ini_set('auto_detect_line_endings', $autodetect);
        return $lines;
    }
1087633
public function getFilesList( $basePath )
    {
        // The custom iterator filters out the file path in order to get a relative one
        return new eZDFSFileHandlerDFSBackendFilterIterator(
            new RecursiveIteratorIterator(
                new RecursiveDirectoryIterator(
                    $this->mountPointPath . '/' . $basePath,
                    FilesystemIterator::SKIP_DOTS|FilesystemIterator::UNIX_PATHS
                )
            ),
            $this->mountPointPath
        );
    }
364058
public static function loadJsonFromFile($filePath)
    {
        if (!file_exists($filePath)) {
            throw new \RuntimeException("File '{$filePath}' doesn't exist");
        }

        $content = json_decode(file_get_contents($filePath));

        if (json_last_error() !== JSON_ERROR_NONE) {
            throw new JsonDecodeException(sprintf(
                'Cannot decode JSON from file "%s" (error: %s)',
                $filePath,
                static::lastJsonErrorMessage()
            ));
        }

        return $content;
    }
1073766
public static function parseFile($filepath)
    {
        if (!is_file($filepath)) {
            throw new \RuntimeException('File not found: ' . $filepath);
        }

        if (!$filedata = static::readFiledata($filepath)) {
            throw new \RuntimeException('Error reading file: ' . $filepath);
        }

        if (!$json = self::decode($filedata)) {
            throw new \RuntimeException('Error parsing json: ' . $filepath);
        }

        return $json;
    }
40217
public function getData(string $filePath): array
    {
        if (!is_readable($filePath) || is_dir($filePath)) {
            throw new \InvalidArgumentException('File ' . $filePath . ' is not a readable or not even a file');
        }
        $this->filePath = $filePath;
        $normalizedMetaData = $this->getNormalizedMetaDataFileContent();
        $normalizedMetaData = $this->addPathToData($normalizedMetaData);
        $normalizedMetaData = $this->addFilePathToData($normalizedMetaData);
        $normalizedMetaData = $this->addCheckSumToData($normalizedMetaData);

        return $normalizedMetaData;
    }
173888
public function getLastLines(int $numberOfLines = self::DEFAULT_NUMBER_OF_LINES): array
    {
        $lines = [];
        if (null === $this->file) {
            return $lines;
        }

        $this->file->seek($this->lineCount);
        $currentKey = $this->file->key();
        while ($currentKey >= 0) {
            $line = $this->getDefaultParser()->parse($this->file->current());
            if ($line) {
                $lines[] = $line;
            }

            if (--$currentKey >= 0) {
                $this->file->seek($currentKey);
            }

            if (\count($lines) >= $numberOfLines) {
                break;
            }
        }

        return $lines;
    }
497207
public function readSynonymsFromFile(string $filepath): array
    {
        if (
            !is_file($filepath) ||
            !is_readable($filepath)
        ) {
            throw SynonymsException::synonymsFileNotFound($filepath);
        }

        $data = file_get_contents($filepath);

        if (!is_string($data)) {
            throw SynonymsException::synonymsMalformedData($filepath);
        }

        return array_filter(array_map(function ($line) {
            if (!is_string($line)) {
                return false;
            }

            $words = str_getcsv($line, ',');

            if (count($words) <= 1) {
                return false;
            }

            return Synonym::createByWords($words);
        }, str_getcsv($data, "\n")));
    }
70300
protected function getPacketFromFile(string $filePath): Packet
    {
        if (!is_readable($filePath)) {
            throw new BadPacketException('File not readable');
        }
        $packet = unserialize(file_get_contents($filePath));
        if (!($packet instanceof Packet)) {
            throw new BadPacketException('Unserialize failed');
        }
        return $packet;
    }
712047
public function readFile($filePath = null, array $options = [])
    {
        $filePath = empty($filePath)
            ? $this->filePath
            : $filePath;

        $result = new ArrayIterator();

        if (false !== ($xml = simplexml_load_file($filePath))) {
            $contents = json_decode(json_encode($xml), true); // force to array conversion

            if (count($contents) == 1) {
                $contents = reset($contents);
            }

            if (json_last_error() === JSON_ERROR_NONE) {
                foreach ($contents as $content) {
                    $result[] = new SplArrayObject($content);
                }
            }
        }

        return $result;
    }
377105
public function processFile($filePath, $functions) {
		$result = array(
			'problems' => array(),
			'fixes' => array(),
		);
		$phpTokens = new PhpFileParser($filePath);
		$changes = 0;
		foreach ($phpTokens as $key => $row) {
			// get non trivial tokens
			if (is_array($row)) {
				list($token, $functionName, $lineNumber) = $row;
				$originalFunctionName = $functionName;

				// prepare normalized version of function name for matching
				$functionName = strtolower($functionName);

				// check for function call
				if ($token == T_STRING
					&& !$phpTokens->isEqualToToken(T_OBJECT_OPERATOR, $key-1) //not method
					&& !$phpTokens->isEqualToToken(T_DOUBLE_COLON, $key-1) //not static method
					&& !$phpTokens->isEqualToToken(T_FUNCTION, $key-2) //not definition
				) {
					// mark function as called
					if (function_exists($functionName) && !in_array($functionName, $this->calledFunctions)) {
						$this->calledFunctions[] = $functionName;
					}
					// is it function we're looking for
					if (isset($functions[$functionName])) {
						$definingFunctionName = $phpTokens->getDefiningFunctionName($key);

						//we're skipping deprecated calls that are in deprecated function itself
						if (!$definingFunctionName || !isset($functions[strtolower($definingFunctionName)])) {
							$result['problems'][] = array($functions[$functionName], $originalFunctionName, $lineNumber);
						}

						//do instant replacement
						if ($this->fixProblems && isset($this->instantReplacements[$functionName])) {
							$phpTokens[$key] = array(T_STRING, $this->instantReplacements[$functionName]);
							$result['fixes'][] = array($originalFunctionName, $this->instantReplacements[$functionName], $lineNumber);
							$changes++;
						}
					}
				}
			}
		}
		if ($changes) {
			try {
				$phpTokens->exportPhp($filePath);
			} catch (\CodeReview\IOException $e) {
				echo '*** Error: ' . $e->getMessage() . " ***\n";
			}
		}
		unset($phpTokens);
		return $result;
	}