-
Notifications
You must be signed in to change notification settings - Fork 1
/
dependencies.php
31 lines (26 loc) · 1.06 KB
/
dependencies.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php
// DIC configuration
use RedBeanPHP\R;
$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;
};
$container['db'] = function($c) {
$settings = $c->get('settings')['db'];
$pdo = new PDO("mysql:host=".$settings['host'] . ";dbname=".$settings['dbname'], $settings['user'], $settings['pass']);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
return $pdo;
};
$dbset = $settings['settings']['db'];
R::setup( 'mysql:host='.$dbset['host'].';dbname='.$dbset['dbname'], $dbset['user'], $dbset['pass']);