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

Breadcrumb

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

function JsonManipulator::__construct

File

vendor/composer/composer/src/Composer/Json/JsonManipulator.php, line 41

Class

JsonManipulator
@author Jordi Boggiano <j.boggiano@seld.be>

Namespace

Composer\Json

Code

public function __construct(string $contents) {
    $contents = trim($contents);
    if ($contents === '') {
        $contents = '{}';
    }
    if (!Preg::isMatch('#^\\{(.*)\\}$#s', $contents)) {
        throw new \InvalidArgumentException('The json file must be an object ({})');
    }
    $this->newline = false !== strpos($contents, "\r\n") ? "\r\n" : "\n";
    $this->contents = $contents === '{}' ? '{' . $this->newline . '}' : $contents;
    $this->detectIndenting();
}
RSS feed
Powered by Drupal