hassankhan / config

Config is a lightweight configuration file loader that supports PHP, INI, XML, JSON, and YAML files
MIT License
972 stars 136 forks source link

Add support to read from string #108

Closed filips123 closed 6 years ago

filips123 commented 6 years ago

Add support for reading from strings and writing to strings instead of files. This could be done with methodsfromString($format, $data) and toString($format, $data).

Note that the format parameter should be case insensitive.

Example of reading:

$settings = <<<FOOBAR
{
  "application": {
    "name": "configuration",
    "secret": "s3cr3t"
  },
  "host": "localhost",
  "port": 80,
  "servers": [
    "host1",
    "host2",
    "host3"
  ]
}
FOOBAR;
$conf = Config::fromString('JSON', $json);

Example of writing:

$json = $conf->toString('JSON')
$conf->toString('YAML', $yaml);
filips123 commented 6 years ago

I've created pull request #111 for loading from string.