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\JsonCode
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();
}