Closed visualcookie closed 8 years ago
Hi @visualcookie, yes YML files are supported too. For example you can do:
// Register provider
$container['config'] = function () {
//Create the configuration
return new \DavidePastore\Slim\Config\Config('config.yml');
};
// Register middleware for all routes
// If you are implementing per-route checks you must not add this
$app->add($container->get('config'));
$app->get('/foo', function ($req, $res, $args) {
//Here you have your configuration
$config = $this->config->getConfig();
$secret = $config->get('application.secret');
});
Your YML file could be:
application:
name: configuration
secret: s3cr3t
host: localhost
port: 80
servers:
- host1
- host2
- host3
Yeey, awesome. Thank you for doing this. Before all I did was creating a PHP Array, where I find YML kinda more readable but wasn't able with my knowledge so far, how to do this. :+1:
I'm happy that my answer has helped you. There is not a lot of magic behind it (it is using https://github.com/symfony/Yaml). I close this issue. Feel free to reopen if you find any issues with this solution.
Hi,
just a question. In the README.md you set the things up with a
config.json
. Can this also be a YML file or has it to be a JSON? If so, would it be easy to add YML as supported config file.