Parse the swagger file

@param string $file - fully qualified file path
@return array
558541
protected function parse($file)
    {
        $data = json_decode(file_get_contents($file), true) ?: Yaml::parse(file_get_contents($file));

        return $data;
    }
229445
protected function getFileContents($file)
    {
        if ($file instanceof ModuleResource) {
            $path = $file->getPath();
        } else {
            $path = Director::baseFolder() . '/' . $file;
        }
        if (!file_exists($path)) {
            return null;
        }
        $content = file_get_contents($path);

        // Remove UTF-8 BOM
        if (substr($content, 0, 3) === pack("CCC", 0xef, 0xbb, 0xbf)) {
            $content = substr($content, 3);
        }

        return $content;
    }
1137202
protected function _parseFile($file)
    {
        //if modified parse it again
        if ($this->_hasBeenModified($file)) {
            $imports = array();
            $content = file_get_contents($file);
            //lets compress the file
            $matches = array();
            $dir = dirname($file);

            if (preg_match_all('/\/\/@depends (.*)/', $content, $matches)) {
                foreach ($matches[1] as $i => $match) {
                    $imported_file = $dir.'/'.$match;
                    $imports[] = $imported_file;

                    if (file_exists($imported_file)) {
                        $data = $this->_parseFile($imported_file);
                        $content = str_replace($matches[0][$i], $data, $content);
                    }
                }
            }

            $content = '//'.str_replace(ANPATH_ROOT, '', $file)."\n".$content;
            $this->_cache_data[$file] = array('data' => $content,'imports' => $imports);
        } else {
            $content = $this->_cache_data[$file]['data'];
        }

        return $content;
    }
936318
public function getFileFunctions($file) {
    $code = file_get_contents($file);
    //drush_print($code);

    $matches = array();
    $pattern = "/^function (\w+)/m";
    preg_match_all($pattern, $code, $matches);

    return $matches[1];
  }
27007
private function parseFile($file)
    {
        $data = sscanf($file, '@%[^:]:%[^?]');

        if (empty($data[0])) {
            throw new \InvalidArgumentException(sprintf('File "%s" has invalid syntax', $file));
        }

        return $data;
    }
75152
private static function getIgnoredFiles($file) {
    if (file_exists($file) === FALSE) {
      return array();
    }

    $contents = file_get_contents($file);
    if ($contents === FALSE) {
      return array();
    }

    return preg_split('/\s+/', $contents);
  }
955994
public function parse(string $file): array
    {
        if (false === file_exists($file)) {
            throw InvalidArgumentExceptionFactory::createForFileCouldNotBeFound($file);
        }

        try {
            $data = json_decode(file_get_contents($file), true);

            if (null === $data) {
                throw ParseExceptionFactory::createForInvalidJson($file);
            }

            return $data;
        } catch (\Exception $exception) {
            if ($exception instanceof UnparsableFileException) {
                throw $exception;
            }

            throw ParseExceptionFactory::createForUnparsableFile($file, 0, $exception);
        }
    }
212062
public function fileGetContents($file)
    {
        $client = new Client();
        $response = $client->createRequest()
            ->setMethod('get')
            ->setUrl($file)
            ->addHeaders(['user-agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36'])
            ->setOptions([
                'timeout' => $this->readFileTimeout, // set timeout to 1 seconds for the case server is not responding
            ])
            ->send();

        if ($response->isOk) {
            return $response->content;
        }

        throw new \Exception("File get contents '{$file}' error: ".$response->content);
    }
951390
private function parseXml($file)
    {
        $formats = [];

        // load xml file
        $xmlDoc = $this->tryLoad($file);

        $this->xpath = new \DOMXPath($xmlDoc);
        $this->xpath->registerNamespace('x', static::XML_NAMESPACE_URI);

        foreach ($this->xpath->query('/x:formats/x:format') as $formatNode) {
            $this->addFormatFromFormatNode($formatNode, $formats);
        }

        return $formats;
    }
766356
public function analyze_js(string $file): array
  {
    $res = [];
    $js = file_get_contents($file);
    if ( $tmp = \Gettext\Translations::fromJsCodeString($js, [
      'functions' => [
        '_' => 'gettext',
        'bbn._' => 'gettext'
      ],
      'file' => $file
      ]) ){
      foreach ( $tmp->getIterator() as $r => $tr ){
        $res[] = $tr->getOriginal();
      }
      $this->parser->mergeWith($tmp);
    }
    return array_unique($res);
  }
1017261
private function parseFileToDOM($file)
    {
        try {
            $dom = XmlUtils::loadFile($file, array($this, 'validateSchema'));
        } catch (\InvalidArgumentException $e) {
            throw new InvalidArgumentException(sprintf('Unable to parse file "%s".', $file), $e->getCode(), $e);
        }

        $this->validateExtensions($dom, $file);

        return $dom;
    }
1140156
protected static function getFiles($file)
    {
        if (empty($file)) {
            throw new InvalidArgumentException('There is not any file defined');
        }

        if (is_string($file)) {
            if (!is_file($file)) {
                throw new InvalidArgumentException("'$file' is not a valid file");
            }

            if (!is_readable($file)) {
                throw new InvalidArgumentException("'$file' is not a readable file");
            }

            return [$file];
        }

        if (is_array($file)) {
            $files = [];

            foreach ($file as $f) {
                $files = array_merge($files, self::getFiles($f));
            }

            return $files;
        }

        throw new InvalidArgumentException('The first argument must be string or array');
    }
533705
protected function parseFile($file)
    {
        try {
            $dom = XmlUtils::loadFile($file, __DIR__ . static::SCHEME_PATH);
        } catch (\InvalidArgumentException $e) {
            throw new \InvalidArgumentException(sprintf('Unable to parse file "%s".', $file), $e->getCode(), $e);
        }

        return $dom;
    }
362365
private function load($file)
    {
        if (null === $this->command) {
            $this->command = Yaml::parse($file);
        }
        return $this->command;
    }
815297
protected function readFile(string $file) : array
    {
        if (!file_exists($file)) {
            throw new \InvalidArgumentException(
                sprintf(
                    'Configuration %s is not exists',
                    $file
                ),
                E_WARNING
            );
        }

        if (!is_array(($configs = $this->parseFromFile($file)))) {
            throw new \RuntimeException(
                sprintf(
                    'Invalid %s configuration from file: %s',
                    ltrim(strrchr(get_class($this), '\\'), '\\'),
                    $file
                ),
                E_NOTICE
            );
        }

        return $configs;
    }
249060
protected function parse(\SplFileInfo $file)
    {
        if ($file->getExtension() !== 'php') {
            throw new \InvalidArgumentException(
                'Invalid file type.'
            );
        }
        $info = [];
        $tokens = token_get_all($file->getContents());

        for ($i = 0; $i < count($tokens); ++$i) {
            $token = is_array($tokens[$i])
                ? $tokens[$i][0]
                : $tokens[$i];

            switch ($token) {
                case T_NAMESPACE:
                    $info[$tokens[$i][1]] = $this->getTokenValue(
                        $tokens,
                        [';'],
                        $i
                    );
                    continue;

                case T_USE:
                    $info[$tokens[$i][1]][] = $this->getTokenValue(
                        $tokens,
                        [';', '{', T_AS],
                        $i
                    );
                    continue;

                case T_CLASS:
                    $classname = $this->getTokenValue(
                        $tokens,
                        [T_EXTENDS, T_IMPLEMENTS, '{'],
                        $i
                    );

                    // Resolve the class fully qualified namespace.
                    $info[$tokens[$i][1]] = $this->resolveNamespace(
                        $info,
                        $classname
                    );

                    continue;

                case T_EXTENDS:
                    $classname = $this->getTokenValue(
                        $tokens,
                        [T_IMPLEMENTS, '{'],
                        $i
                    );

                    // Resolve the extends class fully qualified namespace.
                    $info[$tokens[$i][1]] = $this->resolveNamespace(
                        $info,
                        $classname
                    );

                    continue;

                case T_IMPLEMENTS:
                    $interface = $this->getTokenValue(
                        $tokens,
                        ['{'],
                        $i
                    );

                    // Resolve the interface fully qualified namespace.
                    $info[$tokens[$i][1]][] = $this->resolveNamespace(
                        $info,
                        $interface
                    );

                    continue;
            }
        }

        return $info;
    }
1209394
public function read($file)
    {
        $file = '/settings/' . $file;

        /**
         * @todo validate that $file is a string
         */

        $result = [];

        if ($this->source_filesystem->has($file . '.yml')) {

            $result = $this->yaml->parse($this->source_filesystem->read($file . '.yml'));
        }

        return $result;
    }