Composer API
Class

Composer\Json\JsonFile

class JsonFile

Reads/writes json files.

Constants

LAX_SCHEMA

STRICT_SCHEMA

JSON_UNESCAPED_SLASHES

JSON_PRETTY_PRINT

JSON_UNESCAPED_UNICODE

Methods

__construct(string $path, RemoteFilesystem $rfs = null, IOInterface $io = null)

Initializes json file reader/parser.

string getPath()

bool exists()

Checks whether json file exists.

mixed read()

Reads json file.

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

Writes json file.

bool validateSchema(int $schema = self::STRICT_SCHEMA)

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

static string encode(mixed $data, int $options = 448)

Encodes an array into (optionally pretty-printed) JSON

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

Parses json string and returns hash.

Details

at line 49
public __construct(string $path, RemoteFilesystem $rfs = null, IOInterface $io = null)

Initializes json file reader/parser.

Parameters

string $path path to a lockfile
RemoteFilesystem $rfs required for loading http/https json files
IOInterface $io

Exceptions

InvalidArgumentException

at line 63
public string getPath()

Return Value

string

at line 73
public bool exists()

Checks whether json file exists.

Return Value

bool

at line 84
public mixed read()

Reads json file.

Return Value

mixed

Exceptions

RuntimeException

at line 111
public write(array $hash, int $options = 448)

Writes json file.

Parameters

array $hash writes hash into json file
int $options jsonencode options (defaults to JSONUNESCAPEDSLASHES | JSONPRETTYPRINT | JSONUNESCAPED_UNICODE)

Exceptions

Exception

at line 150
public bool validateSchema(int $schema = self::STRICT_SCHEMA)

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

Parameters

int $schema a JsonFile::*_SCHEMA constant

Return Value

bool true on success

Exceptions

JsonValidationException

at line 196
static public string encode(mixed $data, int $options = 448)

Encodes an array into (optionally pretty-printed) JSON

Parameters

mixed $data Data to encode into a formatted JSON string
int $options jsonencode options (defaults to JSONUNESCAPEDSLASHES | JSONPRETTYPRINT | JSONUNESCAPED_UNICODE)

Return Value

string Encoded json

at line 265
static public mixed parseJson(string $json, string $file = null)

Parses json string and returns hash.

Parameters

string $json json string
string $file the json file

Return Value

mixed