1. Go to this page and download the library: Download davidepastore/slim-config library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
davidepastore / slim-config example snippets
$app = new \Slim\App();
// Fetch DI Container
$container = $app->getContainer();
// Register provider
$container['config'] = function () {
//Create the configuration
return new \DavidePastore\Slim\Config\Config('config.json');
};
$app->get('/api/myEndPoint',function ($req, $res, $args) {
//Here you have your configuration
$config = $this->config->getConfig();
$secret = $config->get('security.secret');
})->add($container->get('config'));
$app->run();
$app = new \Slim\App();
// Fetch DI Container
$container = $app->getContainer();
// Register provider
$container['config'] = function () {
//Create the configuration
return new \DavidePastore\Slim\Config\Config('config.json');
};
// 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('security.secret');
});
$app->post('/bar', function ($req, $res, $args) {
//Here you have your configuration
$config = $this->config->getConfig();
$ttl = $config->get('app.timeout', 3000);
});
$app->run();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.