function JsonFile::read
Reads json file.
Return value
mixed
Throws
\RuntimeException
File
-
vendor/
composer/ composer/ src/ Composer/ Json/ JsonFile.php, line 97
Class
- JsonFile
- Reads/writes json files.
Namespace
Composer\JsonCode
public function read() {
try {
if ($this->httpDownloader) {
$json = $this->httpDownloader
->get($this->path)
->getBody();
}
else {
if (!Filesystem::isReadable($this->path)) {
throw new \RuntimeException('The file "' . $this->path . '" is not readable.');
}
if ($this->io && $this->io
->isDebug()) {
$realpathInfo = '';
$realpath = realpath($this->path);
if (false !== $realpath && $realpath !== $this->path) {
$realpathInfo = ' (' . $realpath . ')';
}
$this->io
->writeError('Reading ' . $this->path . $realpathInfo);
}
$json = file_get_contents($this->path);
}
} catch (TransportException $e) {
throw new \RuntimeException($e->getMessage(), 0, $e);
} catch (\Exception $e) {
throw new \RuntimeException('Could not read ' . $this->path . "\n\n" . $e->getMessage());
}
if ($json === false) {
throw new \RuntimeException('Could not read ' . $this->path);
}
$this->indent = self::detectIndenting($json);
return static::parseJson($json, $this->path);
}