Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. JsonFile.php

function JsonFile::read

Reads json file.

Return value

mixed

Throws

ParsingException

\RuntimeException

File

vendor/composer/composer/src/Composer/Json/JsonFile.php, line 97

Class

JsonFile
Reads/writes json files.

Namespace

Composer\Json

Code

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);
}
RSS feed
Powered by Drupal