forked from gothinkster/slim-php-realworld-example-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdependencies.php
65 lines (46 loc) · 1.63 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
// DIC configuration
/** @var Pimple\Container $container */
use Conduit\Middleware\OptionalAuth;
use League\Fractal\Manager;
use League\Fractal\Serializer\ArraySerializer;
$container = $app->getContainer();
// Error Handler
$container['errorHandler'] = function ($c) {
return new \Conduit\Exceptions\ErrorHandler($c['settings']['displayErrorDetails']);
};
// App Service Providers
$container->register(new \Conduit\Services\Database\EloquentServiceProvider());
$container->register(new \Conduit\Services\Auth\AuthServiceProvider());
// 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;
};
// Jwt Middleware
$container['jwt'] = function ($c) {
$jws_settings = $c->get('settings')['jwt'];
return new \Slim\Middleware\JwtAuthentication($jws_settings);
};
$container['optionalAuth'] = function ($c) {
return new OptionalAuth($c);
};
// Request Validator
$container['validator'] = function ($c) {
\Respect\Validation\Validator::with('\\Conduit\\Validation\\Rules');
return new \Conduit\Validation\Validator();
};
// Fractal
$container['fractal'] = function ($c) {
$manager = new Manager();
$manager->setSerializer(new ArraySerializer());
return $manager;
};