Parses netrc file specified or default one

@param string|null $filename

@throws ParseException when netrc file could not be read or parsed

@return array of netrc values grouped by machines
426329
public static function parse($filename = null)
    {
        // fetch netrc filename if it is not specified
        if (!$filename) {
            if (!$homePath = getenv('HOME')) {
                throw new ParseException("HOME environment variable must be set for correctly netrc handling");
            }
            if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
                $filename = strtr($homePath, '\\', '/') . '/_netrc';
            } else {
                $filename = rtrim($homePath, '/') . '/.netrc';
            }
        }
        $filename = realpath($filename);

        // check that netrc file is available
        if (!file_exists($filename) || !is_readable($filename) || !$content = file_get_contents($filename)) {
            throw new ParseException("netrc file does not exist or is not readable");
        }

        // parse file
        $parser = new Parser();
        return $parser->parse($content);
    }
1318821
public function fromString($fileName)
    {
        $fileNameArray = $fileName ? explode('.', $fileName) : array();
        if(!$fileNameArray || count($fileNameArray) < 2){
            throw new Exception\InvalidArgumentException('File name not correct');
        }

        $fileExt = array_pop($fileNameArray);
        $fileNameMain = implode('.', $fileNameArray);
        $fileNameArray = explode(',', $fileNameMain);
        if(!$fileExt || !$fileNameArray || !$fileNameArray[0]){
            throw new Exception\InvalidArgumentException('File name not correct');
        }

        //remove empty elements
        $fileNameArray = array_filter($fileNameArray);
        $fileNameMain = array_shift($fileNameArray);
        $this->setExtension($fileExt);
        $this->setFilename($fileNameMain);

        $args = $fileNameArray;
        $argMapping = $this->argMapping;
        $params = array();
        foreach($args as $arg){
            if(!$arg){
                continue;
            }
            if(strlen($arg) < 3 || strpos($arg, '_') !== 1){
                continue;
            }
            $argKey = $arg{0};
            if(isset($argMapping[$argKey])){
                $arg = substr($arg, 2);
                if($arg !== ''){
                    $params[$argMapping[$argKey]] = $arg;
                }
            }
        }

        $this->fromArray($params);
        return $params;
    }
1116431
public function find($fileName)
    {
        $fileName = $this->validateFileName($fileName);

        $filePath = $this->getFilePath($fileName);

        if (!File::isFile($filePath)) {
            return null;
        }

        if (($content = @File::get($filePath)) === false) {
            return null;
        }

        $this->fileName = $fileName;
        $this->mtime = File::lastModified($filePath);
        $this->content = $content;
        return $this;
    }
526963
public static function parser($filename)
    {
        $builder = new self($filename);
        $builder->engine = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
        // Parse
        $builder->parse();
        return $builder;
    }
272025
public function parseFile($filename)
    {
        $data = json_decode(file_get_contents($filename), true);

        return (array)$this->parse($data, $filename);
    }
569694
protected function loadFile($filename) {
        $lines = file($filename, FILE_IGNORE_NEW_LINES);            // don't use FILE_SKIP_EMPTY_LINES to have correct line
                                                                    // numbers for error messages
        if ($lines && strStartsWith($lines[0], "\xEF\xBB\xBF")) {
            $lines[0] = substr($lines[0], 3);                       // detect and drop a possible BOM header
        }

        foreach ($lines as $i => $line) {
            $line = trim($line);
            if (!strlen($line) || $line[0]=='#')                    // skip empty and comment lines
                continue;

            $parts = explode('=', $line, 2);                        // split key/value
            if (sizeof($parts) < 2) {
                // Don't trigger a regular error as it will cause an infinite loop if the same config is used by the error handler.
                $msg = __METHOD__.'()  Skipping syntax error in "'.$filename.'", line '.($i+1).': missing key-value separator';
                stderr($msg);
                error_log($msg, ERROR_LOG_DEFAULT);
                continue;
            }
            $key      = trim($parts[0]);
            $rawValue = trim($parts[1]);

            // drop possible comments
            if (strpos($rawValue, '#')!==false && strlen($comment=$this->getLineComment($rawValue))) {
                $value = trim(strLeft($rawValue, -strlen($comment)));
            }
            else {
                $value = $rawValue;
            }

            // parse and store property value
            $this->setProperty($key, $value);
        }
        return true;
    }
641052
public function getLogFilenameList($filename = null)
    {
        $data = [];

        if (empty($filename)) {
            $filename = '*.*';
        }

        $files = $this->getLogFileList($filename);

        if (is_array($files)) {
            foreach ($files as $file) {
                $basename = pathinfo($file, PATHINFO_BASENAME);
                $data[$basename] = $file;
            }
        }

        return $data;
    }
459778
public static function parseFileNamespace($fileName, $namespaceName)
    {
        $topLevelNodes = self::parseFile($fileName);
        // namespaces can be only top-level nodes, so we can scan them directly
        foreach ($topLevelNodes as $topLevelNode) {
            if (!$topLevelNode instanceof Namespace_) {
                continue;
            }
            $topLevelNodeName = $topLevelNode->name ? $topLevelNode->name->toString() : '';
            if (ltrim($topLevelNodeName, '\\') === trim($namespaceName, '\\')) {
                return $topLevelNode;
            }
        }

        throw new ReflectionException("Namespace $namespaceName was not found in the file $fileName");
    }
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;
    }
179172
protected function parse($data = null, $filename = null)
    {
        // If we have a callable, run it and expect an array back
        if (is_callable($data)) {
            $data = call_user_func($data);
        }

        // Check for array, if its anything else, throw an exception
        if (!is_array($data)) {
            throw new UnsupportedFormatException('PHP data does not return an array');
        }

        return $data;
    }
1172500
public static function getTokens(string $filename): array
    {
        $tokens = token_get_all(file_get_contents($filename));

        $line = 0;
        foreach ($tokens as &$token) {
            if (isset($token[self::LINE])) {
                $line = $token[self::LINE];
            }

            if (!is_array($token)) {
                $token = [$token, $token, $line];
            }

            unset($token);
        }

        return $tokens;
    }
208636
protected function processFile($filename, $configArray=[], $parsedFiles=[]) {
    // avoid circular includes
    if (!in_array($filename, $parsedFiles)) {
      $parsedFiles[] = $filename;

      $content = $this->parseIniFile($filename);

      // process includes
      $includes = $this->getConfigIncludes($content);
      if ($includes) {
        $this->processValue($includes);
        foreach ($includes as $include) {
          $result = $this->processFile($this->configPath.$include, $configArray, $parsedFiles);
          $configArray = $this->configMerge($configArray, $result['config'], true);
          $parsedFiles = $result['files'];
        }
      }

      // process self
      $configArray = $this->configMerge($configArray, $content, true);
    }
    return ['config' => $configArray, 'files' => $parsedFiles];
  }
59878
public static function parseFromFile($filename)
    {
        if (file_exists($filename) && is_readable($filename)) {
            return new self(file_get_contents($filename));
        } else {
            throw new \RuntimeException(sprintf("File %s is not readable, or doesn't exist.", $filename));
        }
    }
1227567
public function parse($filename)
    {
        $tokens = token_get_all(file_get_contents($filename));
        $classNames = [];
        $interfaceNames = [];
        $traitNames = [];
        $namespace = [];
        $curleys = 0;
        $isInNamespace = false;
        $totalTokens = count($tokens);

        for ($i = 0; $i <= $totalTokens; $i++) {
            if (!isset($tokens[$i])) {
                break;
            }

            $token = $tokens[$i];
            if (is_string($token)) {
                if (in_array($token[0], ['{'])) {
                    $curleys++;
                }

                if (in_array($token[0], ['}'])) {
                    $curleys--;
                }
                $token = [0 => $token];
            }

            // iterate until space to get FQ NS name.
            if ($token[0] == T_NAMESPACE) {
                $namespace = [];
                $i = $i + 2; 
                for (; $i <= $totalTokens; $i++) {
                    if (!isset($tokens[$i])) {
                        break;
                    }
                    $token = $tokens[$i];

                    if ($token[0] == T_STRING) {
                        $namespace[] = $token[1];
                    }

                    if ($token[0] == ';') {
                        $isInNamespace = true;
                        break;
                    }

                    if ($token[0] == '{') {
                        $curleys++;
                        break;
                    }

                    if ($token[0] == '{') {
                        $curleys--;
                    }
                }
            }

            if ($token[0] == T_CLASS) {
                $prevToken = $tokens[$i - 1];
                if (is_array($prevToken) && $prevToken[0] == T_DOUBLE_COLON) {
                    continue;
                }
                
                $i = $i + 2;
                for (; $i <= count($tokens); $i++) {
                    $token = $tokens[$i];
                    if ($token[0] == T_STRING) {
                        if ($curleys == 0 && !$isInNamespace) {
                            $namespace = [];
                        }
                        $classParts = array_merge($namespace, [$token[1]]);
                        $classNames[] = join('\\', $classParts);
                        break;
                    }
                }
            }

            if ($token[0] == T_INTERFACE) {
                $i = $i + 2;
                for (; $i <= count($tokens); $i++) {
                    $token = $tokens[$i];
                    if ($token[0] == T_STRING) {
                        if ($curleys == 0 && !$isInNamespace) {
                            $namespace = [];
                        }
                        $interfaceParts = array_merge($namespace, [$token[1]]);
                        $interfaceNames[] = join('\\', $interfaceParts);
                        break;
                    }
                }
            }

            if ($token[0] == T_TRAIT) {
                $i = $i + 2;
                for (; $i <= count($tokens); $i++) {
                    $token = $tokens[$i];
                    if ($token[0] == T_STRING) {
                        if ($curleys == 0 && !$isInNamespace) {
                            $namespace = [];
                        }
                        $traitParts = array_merge($namespace, [$token[1]]);
                        $traitNames[] = join('\\', $traitParts);
                        break;
                    }
                }
            }
        }
        return [
            'classes' => $classNames,
            'interfaces' => $interfaceNames,
            'traits' => $traitNames
        ];
    }
356403
protected function loadCurrentSitemapIndex($filename)
    {
        if (!file_exists($filename)) {
            return array();
        }

        $urlsets = array();
        $index = simplexml_load_file($filename);
        foreach ($index->children() as $child) {
            /** @var $child \SimpleXMLElement */
            if ($child->getName() == 'sitemap') {
                if (!isset($child->loc)) {
                    throw new \InvalidArgumentException(
                        "One of referenced sitemaps in $filename doesn't contain 'loc' attribute"
                    );
                }
                $basename = preg_replace(
                    '/^' . preg_quote($this->sitemapFilePrefix) . '\.(.+)\.xml(?:\.gz)?$/',
                    '\1',
                    basename($child->loc)
                ); // cut .xml|.xml.gz

                if (!isset($child->lastmod)) {
                    throw new \InvalidArgumentException(
                        "One of referenced sitemaps in $filename doesn't contain 'lastmod' attribute"
                    );
                }
                $lastmod = new \DateTime($child->lastmod);
                $urlsets[$basename] = $this->newUrlset($basename, $lastmod);
            }
        }

        return $urlsets;
    }
1027517
protected function getQueueStorageFile($fileName)
    {
        $file = $this->getQueueStorage()->getFile($fileName);

        if ($file->exists()) {
            return $file;
        }

        return null;
    }
23244
protected function readFromCache($fileName)
    {
        $cacheFile = $this->getCacheFile($fileName);
        if (file_exists($cacheFile) && is_readable($cacheFile)) {
            include($cacheFile);
            if (isset($crudlexCacheContent)) {
                return $crudlexCacheContent;
            }
        }
        return null;
    }