Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/connrs/JsonReader
JsonReader to extend CakePHP 2 Configure class
https://github.com/connrs/JsonReader
Last synced: 3 months ago
JSON representation
JsonReader to extend CakePHP 2 Configure class
- Host: GitHub
- URL: https://github.com/connrs/JsonReader
- Owner: connrs
- License: wtfpl
- Archived: true
- Created: 2011-11-03T16:33:19.000Z (about 13 years ago)
- Default Branch: master
- Last Pushed: 2011-11-06T10:09:50.000Z (about 13 years ago)
- Last Synced: 2024-05-29T08:11:42.716Z (6 months ago)
- Language: PHP
- Homepage:
- Size: 93.8 KB
- Stars: 4
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# JsonReader
A simple JsonReader for CakePHP 2 configuration.##Installation
1. Simply place this plugin in your plugin dir (`root/plugins` or `root/app/Plugin`).
2. In `app/Config/bootstrap.php`:App::uses('JsonReader', 'JsonReader.Configure');
Configure::config('jsonReader', new JsonReader); // optionally add a path: new JsonReader($path)
Then:Configure::load('config_filename_with_no_extension', 'jsonReader');
3. You can now access configuration information via `Configure::read('variable')`## Limitations
Due to how Configure works, and how JSON is represented when decoded by PHP, you will need to make the root of your JSON file an object:
{
"foo": "bar"
}This allows you to do `Configure::read('foo')`
### Possible workaround of the limitation
I have plans to perhaps add a configuration option to apply a key to a JSON config file such that you could use the following JSON:
Config/config.json
[
{"foo": 0},
{"bar": 1}
]And in the bootstrap:
Configure::config('jsonReader', new JsonReader(null, 'Raboof')
Configure::load('config', 'jsonReader);
$x = Configure::read('Raboof');
// x => array(
// array('foo' => 0),
// array('bar' => 1)
// )But that's for future consideration if there's a use case for it.