Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
dependencies.php Rest API Dengan JSON Web Token Slim 3
use Slim\App;
return function (App $app) {
$container = $app->getContainer();
// view renderer
$container['renderer'] = function ($c) {
$settings = $c->get('settings')['renderer'];
return new \Slim\Views\PhpRenderer($settings['template_path']);
// monolog
$container['logger'] = function ($c) {
$settings = $c->get('settings')['logger'];
$logger = new \Monolog\Logger($settings['name']);
$logger->pushProcessor(new \Monolog\Processor\UidProcessor());
$logger->pushHandler(new \Monolog\Handler\StreamHandler($settings['path'], $settings['level']));
return $logger;
// database
$container['db'] = function ($c){
$settings = $c->get('settings')['db'];
$server = $settings['driver'].":host=".$settings['host'].";dbname=".$settings['dbname'];
$conn = new PDO($server, $settings["user"], $settings["pass"]);
return $conn;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment