Parses an array of code lines from source file with given filename.

Attempts to automatically detect the line break character used in the file.

@param string $filename
@return string[] An array of lines of code from the given source file.
420103
private function getSourceLines($filename)
    {
        $rawSource = file_get_contents($filename);

        $source = explode(PHP_EOL, $rawSource);

        if (count($source) === 1) {
            if (substr_count($rawSource, "\n") > substr_count($rawSource, "\r")) {
                $source = explode("\n", $rawSource);
            } else {
                $source = explode("\r", $rawSource);
            }
        }

        $source = str_replace(array("\n", "\t", "\r"), '', $source);

        return $source;
    }
161656
private function getDirs($fileName)
    {
        if (is_file($fileName)) {
            return [];
        }

        $currentDir = getcwd();

        if (is_dir($fileName)) {
            $currentDir = $fileName;
        }

        $dirs[] = $currentDir;
        if (is_dir($currentDir.'/conf')) {
            $dirs[] = $currentDir.'/conf';
        }
        if (is_dir($currentDir.'/config')) {
            $dirs[] = $currentDir.'/config';
        }

        return $dirs;
    }
1146365
protected function getTrans($filename)
    {
        if (is_file($filename)) {
            $trans = Yaml::parse(file_get_contents($filename));
        } else {
            $trans = array();
        }

        $keys = array('breadcrumb', 'list', 'filter', 'show', 'form');
        foreach ($keys as $key) {
            if (!array_key_exists($key, $trans)) {
                $trans[$key] = array();
            }
        }

        return $trans;
    }
912632
protected function parse($data = null, $filename = null)
    {
        if (json_last_error() !== JSON_ERROR_NONE) {
            $error_message  = 'Syntax error';
            if (function_exists('json_last_error_msg')) {
                $error_message = json_last_error_msg();
            }

            $error = [
                'message' => $error_message,
                'type'    => json_last_error(),
                'file'    => $filename,
            ];

            throw new ParseException($error);
        }

        return $data;
    }
948080
public static function getContents($filename)
    {
        $contents = file_get_contents($filename);
        if ($contents === false) {
            throw new \RuntimeException("Cannot read the file: " . $filename);
        }

        return $contents;
    }
405881
protected function parseRoutesFromFile($filename)
    {
        // Assume empty result
        $routes            = [];
        $actionsWithRoutes = [];

        // Check if file exists ...
        if (true === $this->getRegistry()->getFilesystem()->readable($filename)) {
            include $filename;

            $content = file_get_contents($filename);
            $matches = preg_match('/class\s([A-Za-z\_]+)/', $content, $classes);

            // Process all found classes ...
            if ($matches > 0) {

                // Use our selection from result
                $className = $classes[1];

                // Lookup for namespace ...
                $namespaceCount = preg_match('#^namespace\s+(.+?);$#sm', $content, $namespace);

                // Extract namespace of file/class if found ...
                if ($namespaceCount > 0) {
                    $namespace = $namespace[1].'\\';
                } else {
                    $namespace = '';
                }

                // Combine everything to a full qualified className ...
                $fullQualifiedClassName = $namespace.$className;

                $reflection = new ReflectionClass($fullQualifiedClassName);

                // Extract the methods (potentially an ...Action())
                $methods = $reflection->getMethods(ReflectionMethod::IS_PUBLIC);

                foreach ($methods as $key => $reflection) {
                    if (preg_match('/(Action)$/ui', $reflection->name)) {
                        if (isset($actionsWithRoutes[$filename]) === false) {
                            $actionsWithRoutes[$filename] = [];
                        }

                        $actionsWithRoutes[$filename][$reflection->name] =
                            $this->getAnnotationReader()->getMethodAnnotations($reflection);
                    }
                }
            }

            $routes = $this->sortRoutes($actionsWithRoutes);
        }

        return $routes;
    }
1213456
public function parseFile($filename)
    {
        libxml_use_internal_errors(true);
        $data = simplexml_load_file($filename, null, LIBXML_NOERROR);

        return (array)$this->parse($data, $filename);
    }
913123
public function read($fileName)
    {
        $parsedYaml = $this->readFromCache($fileName);
        if ($parsedYaml !== null) {
            return $parsedYaml;
        }

        try {
            $fileContent = file_get_contents($fileName);
            $parsedYaml  = Yaml::parse($fileContent);
            if (!is_array($parsedYaml)) {
                $parsedYaml = [];
            }
            $this->writeToCache($fileName, $parsedYaml);
            return $parsedYaml;
        } catch (\Exception $e) {
            throw new \RuntimeException('Could not read Yaml file '.$fileName, $e->getCode(), $e);
        }
    }
607487
public function getLinesFromFile() : array
    {
        $filename = $this->filename;

        if (!file_exists($filename)) {
            throw new \InvalidArgumentException("File not found: {$filename}");
        }

        return (array) file($filename, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
    }
1115705
public function ini(string $filename): array {
		$ini = parse_ini_file($filename, true);
		if($ini !== false) {
			$parameters = $ini[Environment::choose()];
			return $parameters;
		} else {
			return [];
		}
	}
1169420
private function parseFilename($filename) {
    if (defined('DRUPAL_ROOT') && stripos($filename, DRUPAL_ROOT) === 0) {
      return substr($filename, strpos($filename, DRUPAL_ROOT) + strlen(DRUPAL_ROOT) + 1);
    }
    else {
      return $filename;
    }
  }
1059497
private function parseClassCode(string $code, string $className):array
    {
        $codeSansComments = $this->stripComments($code);
        $lines = array_map("trim", explode("\n", $codeSansComments));
        preg_match_all("/p[a-zA-Z]*\sfunction\s+([a-zA-Z\_]*)\(.*?\).*/ui", $code, $matches);

        if (!empty($matches[0])) {

            $functions = array_map(function ($item, $key) use ($lines, $matches, $className) {

                $startLineNumber = array_search($item, $lines);
                if ($startLineNumber) {
                    if (isset($matches[0][$key+1])) {
                        $endLineNumber =  array_search($matches[0][$key+1], $lines);
                    }
                    if (isset($endLineNumber) && is_int($endLineNumber)) {
                        $code = trim(implode("\n", array_slice( $lines, $startLineNumber, $endLineNumber - $startLineNumber )));
                    } else {
                        $code = trim(implode("\n", array_slice( $lines, $startLineNumber )));
                    }
                }

                return array(
                    "className" => $className,
                    "name" => $matches[1][$key],
                    "code" => isset($code)?$code:""
                );

            }, $matches[0], array_keys($matches[0]));

            return $functions;

        }

        return array();

    }
1277699
private function parse($fname)
    {
        $buf = file_get_contents($fname);

        $res = $this->parseBuffer($buf);

        return $res;
    }
280697
protected function load($filename)
    {
        $this->catalog = array();

        $fp = fopen($filename, 'rb', false);
        if ($fp === false) {
            throw new \RuntimeException("Could not read $filename");
        }

        $data = fread($fp, 20);
        if (strlen($data) != 20) {
            throw new \RuntimeException('Invalid file');
        }

        $magic = substr($data, 0, 4);
        if ($magic === "\x95\x04\x12\xde") {
            $dword = 'N';
        } elseif ($magic === "\xde\x12\x04\x95") {
            $dword = 'V';
        } else {
            throw new \RuntimeException('Invalid file');
        }

        list(, $revision) = unpack("@4/${dword}", $data);

        if ($revision !== 0) {
            throw new \RuntimeException('Invalid file');
        }

        list(, $count, $origOffset, $transOffset) = unpack("@8/${dword}3", $data);

        fseek($fp, $origOffset);
        $origEntries = array();
        for ($i = 0; $i < $count; $i++) {
            $origEntries[] = unpack("${dword}2", fread($fp, 8));
        }

        fseek($fp, $transOffset);
        $transEntries = array();
        for ($i = 0; $i < $count; $i++) {
            $transEntries[] = unpack("${dword}2", fread($fp, 8));
        }

        for ($i = 0; $i < $count; $i++) {
            fseek($fp, $origEntries[$i][2]);
            $msgid = $origEntries[$i][1] > 0 ? fread($fp, $origEntries[$i][1]) : "";
            fseek($fp, $transEntries[$i][2]);
            $translations = $transEntries[$i][1] > 0 ? explode("\x00", fread($fp, $transEntries[$i][1])) : "";

            $ctx = self::NO_CONTEXT;
            if (($pos = strpos($msgid, self::NO_CONTEXT)) !== false) {
                $ctx = (string) substr($msgid, 0, $pos);
                $msgid = (string) substr($msgid, $pos + 1);
            }

            $this->catalog[$ctx][$msgid] = $translations;
        }
    }
775194
public static function getContents($filename)
    {
        $file = fopen($filename, "r");

        if ($file === false) {
            throw new \RuntimeException("Cannot read the file: {$filename}");
        }

        $data = [];
        while ($row = fgetcsv($file)) {
            $data[] = $row;
        }

        fclose($file);

        return $data;
    }
1309987
public function getNamesWithDifferentExtension(string $fileName)
    {
        if (! file_exists($this->basePath)) {
            return [];
        }

        $extension = pathinfo($fileName, PATHINFO_EXTENSION);

        $baseName = substr($fileName, 0, strlen($fileName) - strlen($extension) - 1);

        $allNames = scandir($this->basePath);

        $namesWithDifferentExtension = array_filter($allNames, function ($existingName) use ($baseName, $extension) {
            $existingExtension = pathinfo($existingName, PATHINFO_EXTENSION);

            $existingBaseName = substr($existingName, 0, strlen($existingName) - strlen($existingExtension) - 1);

            return $existingBaseName === $baseName && $existingExtension !== $extension;
        });

        return array_values($namesWithDifferentExtension);
    }
408390
public static List<String> readLines(String filename) {
    List<String> lines = Lists.newArrayList();
    try {
      BufferedReader in = new BufferedReader(new FileReader(filename));
      String line;
      while ((line = in.readLine()) != null) {
        // Ignore blank lines.
        if (line.trim().length() > 0) {
          lines.add(line);
        }
      }
      in.close();
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
    return lines;
  }