Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. PhpParser.php

function PhpParser::getFileContent

Gets the content of the file right up to the given line number.

Parameters

string $filename The name of the file to load.:

int $lineNumber The number of lines to read from file.:

Return value

string|null The content of the file or null if the file does not exist.

1 call to PhpParser::getFileContent()
PhpParser::parseUseStatements in vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/PhpParser.php
Parse a class or function for use statements.

File

vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/PhpParser.php, line 59

Class

PhpParser
Parses a file for namespaces/use/class declarations.

Namespace

Doctrine\Common\Annotations

Code

private function getFileContent(string $filename, $lineNumber) {
    if (!is_file($filename)) {
        return null;
    }
    $content = '';
    $lineCnt = 0;
    $file = new SplFileObject($filename);
    while (!$file->eof()) {
        if ($lineCnt++ === $lineNumber) {
            break;
        }
        $content .= $file->fgets();
    }
    return $content;
}
RSS feed
Powered by Drupal