function JsonFile::encode
Encodes an array into (optionally pretty-printed) JSON
Parameters
mixed $data Data to encode into a formatted JSON string:
int $options json_encode options (defaults to JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE):
string $indent Indentation string:
Return value
string Encoded json
23 calls to JsonFile::encode()
- Auditor::audit in vendor/
composer/ composer/ src/ Composer/ Advisory/ Auditor.php - CheckPlatformReqsCommand::printTable in vendor/
composer/ composer/ src/ Composer/ Command/ CheckPlatformReqsCommand.php - ComposerRepository::asyncFetchFile in vendor/
composer/ composer/ src/ Composer/ Repository/ ComposerRepository.php - @phpstan-return PromiseInterface<array<mixed>|true> true if the response was a 304 and the cache is fresh, otherwise it returns the decoded json
- ComposerRepository::fetchFile in vendor/
composer/ composer/ src/ Composer/ Repository/ ComposerRepository.php - ComposerRepository::fetchFileIfLastModified in vendor/
composer/ composer/ src/ Composer/ Repository/ ComposerRepository.php
File
-
vendor/
composer/ composer/ src/ Composer/ Json/ JsonFile.php, line 280
Class
- JsonFile
- Reads/writes json files.
Namespace
Composer\JsonCode
public static function encode($data, int $options = 448, string $indent = self::INDENT_DEFAULT) : string {
$json = json_encode($data, $options);
if (false === $json) {
self::throwEncodeError(json_last_error());
}
if (($options & JSON_PRETTY_PRINT) > 0 && $indent !== self::INDENT_DEFAULT) {
// Pretty printing and not using default indentation
return Preg::replaceCallback('#^ {4,}#m', static function ($match) use ($indent) : string {
return str_repeat($indent, (int) (strlen($match[0]) / 4));
}, $json);
}
return $json;
}