Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
dependencies.php Rest API Dengan JSON Web Token Slim 3
<?php
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"]);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$conn->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
return $conn;
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.