Constants

LAX_SCHEMA

LAX_SCHEMA = 1

STRICT_SCHEMA

STRICT_SCHEMA = 2

JSON_UNESCAPED_SLASHES

JSON_UNESCAPED_SLASHES = 64

JSON_PRETTY_PRINT

JSON_PRETTY_PRINT = 128

JSON_UNESCAPED_UNICODE

JSON_UNESCAPED_UNICODE = 256

Properties

$path

$path : 

Type

$rfs

$rfs : 

Type

$io

$io : 

Type

Methods

__construct()

__construct(string  $path, \Composer\Util\RemoteFilesystem  $rfs = null, \Composer\IO\IOInterface  $io = null) 

Initializes json file reader/parser.

Parameters

string $path

path to a lockfile

\Composer\Util\RemoteFilesystem $rfs

required for loading http/https json files

\Composer\IO\IOInterface $io

Throws

\InvalidArgumentException

getPath()

getPath() : string

Returns

string

exists()

exists() : boolean

Checks whether json file exists.

Returns

boolean

read()

read() : mixed

Reads json file.

Throws

\RuntimeException

Returns

mixed

write()

write(array  $hash, integer  $options = 448) 

Writes json file.

Parameters

array $hash

writes hash into json file

integer $options

json_encode options (defaults to JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)

Throws

\UnexpectedValueException|\Exception

validateSchema()

validateSchema(integer  $schema = self::STRICT_SCHEMA) : boolean

Validates the schema of the current json file according to composer-schema.json rules

Parameters

integer $schema

a JsonFile::*_SCHEMA constant

Throws

\Composer\Json\JsonValidationException

Returns

boolean —

true on success

encode()

encode(mixed  $data, integer  $options = 448) : string

Encodes an array into (optionally pretty-printed) JSON

Parameters

mixed $data

Data to encode into a formatted JSON string

integer $options

json_encode options (defaults to JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)

Returns

string —

Encoded json

parseJson()

parseJson(string  $json, string  $file = null) : mixed

Parses json string and returns hash.

Parameters

string $json

json string

string $file

the json file

Returns

mixed

validateSyntax()

validateSyntax(string  $json, string  $file = null) : boolean

Validates the syntax of a JSON string

Parameters

string $json
string $file

Throws

\UnexpectedValueException
\Seld\JsonLint\ParsingException

Returns

boolean —

true on success

throwEncodeError()

throwEncodeError(integer  $code) 

Throws an exception according to a given code with a customized message

Parameters

integer $code

return code of json_last_error function

Throws

\RuntimeException