Class JsonConfig
JSON engine allows Configure to load configuration values from files containing JSON strings.
An example JSON file would look like::
{
"debug": false,
"App": {
"namespace": "MyApp"
},
"Security": {
"salt": "its-secret"
}
}
Property Summary
-
$_extension protected
stringFile extension.
-
$_path protected
stringThe path this engine finds files on.
Method Summary
-
__construct() public
Constructor for JSON Config file reading.
-
_getFilePath() protected
Get file path
-
dump() public
Converts the provided $data into a JSON string that can be used saved into a file and loaded later.
-
read() public
Read a config file and return its contents.
Method Detail
__construct() ¶ public
__construct(string|null $path = null)
Constructor for JSON Config file reading.
Parameters
-
string|null$path optional The path to read config files from. Defaults to CONFIG.
_getFilePath() ¶ protected
_getFilePath(string $key, bool $checkExists = false): string
Get file path
Parameters
-
string$key The identifier to write to. If the key has a . it will be treated as a plugin prefix.
-
bool$checkExists optional Whether to check if file exists. Defaults to false.
Returns
stringThrows
Cake\Core\Exception\CakeExceptionWhen files don't exist or when files contain '..' as this could lead to abusive reads.
dump() ¶ public
dump(string $key, array $data): bool
Converts the provided $data into a JSON string that can be used saved into a file and loaded later.
Parameters
-
string$key The identifier to write to. If the key has a . it will be treated as a plugin prefix.
-
array$data Data to dump.
Returns
boolread() ¶ public
read(string $key): array
Read a config file and return its contents.
Files with . in the name will be treated as values in plugins. Instead of
reading from the initialized path, plugin keys will be located using Plugin::path().
Parameters
-
string$key The identifier to read from. If the key has a . it will be treated as a plugin prefix.
Returns
arrayThrows
Cake\Core\Exception\CakeExceptionWhen files don't exist or when files contain '..' (as this could lead to abusive reads) or when there is an error parsing the JSON string.