Read xml content from remote filesystem

@param $origin string server
@param $path   string relative path to content
@throws \UnexpectedValueException
@return \SimpleXMLElement
342487
protected function requestXml($origin, $path)
    {
        // http://components.ez.no/p/packages.xml is malformed. to read it we must ignore parsing errors.
        $xml = simplexml_load_string($this->requestContent($origin, $path), "SimpleXMLElement", LIBXML_NOERROR);

        if (false == $xml) {
            $url = rtrim($origin, '/') . '/' . ltrim($path, '/');
            throw new \UnexpectedValueException(sprintf('The PEAR channel at ' . $origin . ' is broken. (Invalid XML at file `%s`)', $path));
        }

        return $xml;
    }
1246450
public function read($length)
    {
        $streamResource = $this->getStreamResource();
        if (!is_resource($streamResource)) {
            throw new \UnexpectedValueException('Stream resource parameter must be a resource');
        }
        $streamsRead   = array($streamResource);
        $streamsWrite  = NULL;
        $streamsExcept = NULL;

        $hasDataToRead = stream_select(
            $streamsRead,
            $streamsWrite,
            $streamsExcept,
            0
        );

        if ($hasDataToRead) {
            return fread($streamResource, $length);
        }
        return false;
    }
982552
protected function serverRequest($path, $context)
	{
		if (strpos($path, '/') === 0)
		{
			$path = substr($path, 1);
		}

		$url = sprintf('http://%s/%s', $this->serverUrl, $path);

		$context = stream_context_create($context);
		$result = @file_get_contents($url, false, $context);

		if ($result === false)
		{
			throw new ClientException('Failed connecting to ' . $url);
		}

		if (($result = json_decode($result)) === false)
		{
			throw new ClientException("Failed decoding json response from server");
		}

		if (empty($result))
		{
			throw new ClientException("Did not receive a valid client instance");
		}

		return $result;
	}
1313327
public function read($path)
    {
        list (, $fileId) = $this->splitPath($path);
        if ($response = $this->service->files->get($fileId, $this->applyDefaultParams([
            'alt' => 'media'
        ], 'files.get'))) {
            return [
                'contents' => (string) $response->getBody()
            ];
        }

        return false;
    }
1352217
public static function load(string $path = null, array $paths = []): self
    {
        if (null === $path) {
            $config = [];
        } else {
            if (false === (new Filesystem())->isAbsolutePath($path)) {
                throw new InvalidArgumentException(
                    sprintf(
                        'Expected the path of the configuration file to load to be an absolute path, got "%s" '
                        .'instead',
                        $path
                    )
                );
            }

            if (false === file_exists($path)) {
                throw new InvalidArgumentException(
                    sprintf(
                        'Expected the path of the configuration file to exists but the file "%s" could not be '
                        .'found',
                        $path
                    )
                );
            }

            if (false === is_file($path) && false === (is_link($path) && is_file(readlink($path)))) {
                throw new InvalidArgumentException(
                    sprintf(
                        'Expected the path of the configuration file to be a file but "%s" appears to be a '
                        .'directory.',
                        $path
                    )
                );
            }

            $config = include $path;

            if (false === is_array($config)) {
                throw new InvalidArgumentException(
                    sprintf(
                        'Expected configuration to be an array, found "%s" instead.',
                        gettype($config)
                    )
                );
            }
        }

        self::validateConfigKeys($config);

        $prefix = self::retrievePrefix($config);

        $whitelistedFiles = null === $path ? [] : self::retrieveWhitelistedFiles(dirname($path), $config);

        $patchers = self::retrievePatchers($config);

        array_unshift($patchers, new SymfonyPatcher());

        $whitelist = self::retrieveWhitelist($config);

        $finders = self::retrieveFinders($config);
        $filesFromPaths = self::retrieveFilesFromPaths($paths);
        $filesWithContents = self::retrieveFilesWithContents(chain($filesFromPaths, ...$finders));

        return new self($path, $prefix, $filesWithContents, $patchers, $whitelist, $whitelistedFiles);
    }
1237446
public static function parse($path) {
        if (!file_exists($path)) {
            throw new \Exception("$path not found");
        }

        $src = file_get_contents($path);
        if (!$src) {
            throw new \Exception("could not read $path");
        }

        // first of all do we have any frontmatter in there?
        preg_match(self::$frontmatter_regex, $src, $matches);
        if (!empty($matches)) {
            // if we have an empty frontmatter, this will fail 
            // but we still want to act like there was something there
            if (!($frontmatter = json_decode(trim($matches[1]), true))) {
                $frontmatter = array();
            }
        } else {
            $frontmatter = false;
        }

        // remove any frontmatter
        $plain_src = preg_replace(self::$frontmatter_regex, "", $src);

        return array(
            'frontmatter' => $frontmatter,
            'content' => $plain_src
        );
    }
227014
public function get ($path) {
		list ($first, $rest) = self::getFirstAndRestPathElements($path);

		if (array_key_exists($first, $this -> data)) {
			$value = $this -> data[$first];
			if (is_null($rest)) {
				return $value;
			} else if ($value instanceof TreeInterface) {
				return $value -> get($rest);
			} else {
				throw new InvalidKeyException("Value at key `" . $first . "` is a scalar; cannot step further down the requested path `" . $rest . "`");
			}
		} else {
			throw new NonExistentKeyException("Key `" . $first . "` does not exist.");
		}
	}
227018
public function read( $path )
	{
		try {
			return $this->fs->get( $path );
		} catch( \Exception $e ) {
			throw new Exception( $e->getMessage(), 0, $e );
		}
	}
1326259
static function remoteXpathQuery($url, $xpath, array $post = []) {
		if (count($post) > 0) {
			$cont = self::postRequest($url, $post);
		} else {
			$cont = file_get_contents($url);
		}
		return self::xpathQuery($cont, $xpath);
	}
781209
public function parse($path)
    {
        libxml_use_internal_errors(true);

        $data = simplexml_load_file($path, null, LIBXML_NOERROR);

        if ($data === false) {
            $errors      = libxml_get_errors();
            $latestError = array_pop($errors);
            $error       = array(
                'message' => $latestError->message,
                'type'    => $latestError->level,
                'code'    => $latestError->code,
                'file'    => $latestError->file,
                'line'    => $latestError->line,
            );
            throw new ParseException($error);
        }

        $data = json_decode(json_encode($data), true);

        return $data;
    }
726282
protected static function parseEdgeRcFile($path)
    {
        if ($path === null) {
            if (isset($_SERVER['HOME']) && file_exists($_SERVER['HOME'] . '/.edgerc')) {
                $path = $_SERVER['HOME'] . '/.edgerc';
            } elseif (file_exists('./.edgerc')) {
                $path = './.edgerc';
            }
        }

        $file = !$path ? false : realpath($path);
        if (!$file) {
            throw new ConfigException("Path to .edgerc file \"$path\" does not exist!");
        }

        if (!is_readable($file)) {
            throw new ConfigException('Unable to read .edgerc file!');
        }

        // Handle : assignments in .edgerc files
        $ini = file_get_contents($file);
        $ini = str_replace(':', '=', $ini);

        $ini = parse_ini_string($ini, true, INI_SCANNER_RAW);

        return $ini;
    }
887250
private function loadIniFile($path)
    {
        $data = parse_ini_file($path, true);
        if ($data === false) {
            throw new UnexpectedValueException(
                sprintf('INI file "%s" is empty or invalid', $path)
            );
        }

        return $data;
    }
325065
protected function collectCoverage(\SimpleXMLElement $file, $path, $filename)
    {
        if ($this->jsonFile->hasSourceFile($path)) {
            $srcFile = $this->jsonFile->getSourceFile($path);
        } else {
            $srcFile = new SourceFile($path, $filename);
        }

        foreach ($file->line as $line) {
            if ((string) $line['type'] === 'stmt') {
                $lineNum = (int) $line['num'];

                if ($lineNum > 0) {
                    $srcFile->addCoverage($lineNum - 1, (int) $line['count']);
                }
            }
        }

        return $srcFile;
    }
972792
public function loadSetupFile($path)
	{
		$result = false;

		if ($path)
		{
			if (!file_exists($path))
			{
				return $result;
			}

			$xml = simplexml_load_file($path);

			if ($params = $xml->params)
			{
				foreach ($params as $param)
				{
					$this->setXML($param);
					$result = true;
				}
			}
		}
		else
		{
			$result = true;
		}

		return $result;
	}
307043
public function getFileAsXML( $path )
	{
		try
		{
			$xml = $this->getFile( $this->getActualUri( $path ) );
			isXml( $xml );
			return simplexml_load_string( $xml );
		}
		catch ( Exception $ex )
		{
			throw XBRL_TaxonomyPackageException::withError( "tpe:invalidMetaDataFile", $ex->getMessage() );
		}
	}
697047
public function value($root, $path)
    {
        if (!is_array($root) && !is_object($root)) {
            return null;
        }

        if (!$this->isNestedKey($path)) {
            return $this->getNode($root, $path);
        }

        return $this->getNestedValue($root, $path);
    }
174639
public static function readConfigFile($path = '')
    {
        $path = str_replace('..', '', $path);
        $realPath = self::$configDir . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $path);
        $cachedFile = self::$cachePath . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $path).'.php';
        if (file_exists($cachedFile) && self::$config['cache'] === true) {
            $conf = require_once($cachedFile);
        } else {
            if (file_exists($realPath)) {
                switch (self::$configExt) {
                    case 'xml':
                        $objConfig = simplexml_load_file($realPath);
                        $conf = json_decode(json_encode($objConfig), true);
                        break;
                    case 'yaml':
                        $conf = Yaml::parse(file_get_contents($realPath));
                        break;
                    default:
                        $conf = require_once $realPath;
                        break;
                }
                if (self::$config['cache'] === true) {
                    touch($cachedFile);
                    $str = "<?php\nreturn ".var_export($conf, true).";\n";
                    file_put_contents($cachedFile, $str);
                }
            }
        }
        return $conf;
    }