Documentation / JSON
Readers for JSON input.
The JsonReader
$reader = new JsonReader();
// Read from JSON string
$configuration = $reader->createConfiguration('{"a": 1}');
Constructor options
public function __construct(
string $class = Configuration::class,
);
class
- An instance of any class implementingConfigurationInterface
to be returned (defaultConfiguration
).
createConfiguration options
public function createConfiguration(
string $json = '{}',
): ConfigurationInterface;
json
- JSON string to parse.
The JsonFileReader
$reader = new JsonFileReader();
// Read from file
$configuration = $reader->createConfiguration(path: 'path/to/file.json');
Constructor options
public function __construct(
string $class = Configuration::class,
string $prefix = '',
bool $optional = false,
);
class
- An instance of any class implementingConfigurationInterface
to be returned (defaultConfiguration
).prefix
- File path prefix.optional
- If true, reader will return empty configuration if file is missing.
createConfiguration options
public function createConfiguration(
string $path = 'config.json',
): ConfigurationInterface;
path
- File to be read.