-
Notifications
You must be signed in to change notification settings - Fork 23
/
container.php
58 lines (44 loc) · 2.42 KB
/
container.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
<?php
use CropTool\Auth\AuthServiceInterface;
use CropTool\Auth\OAuthConsumer;
use CropTool\File\FileRepository;
use Psr\Container\ContainerInterface;
use Monolog\Formatter\LineFormatter;
use Monolog\Logger;
use Monolog\Level;
use Monolog\ErrorHandler;
use Monolog\Handler\RotatingFileHandler;
use Monolog\Processor\PsrLogMessageProcessor;
use Psr\Log\LoggerInterface;
$hasToolsDataDir = getenv('TOOL_DATA_DIR') != '';
return [
'root_directory' => ROOT_PATH,
'host' => function (ContainerInterface $container) {
return $container->get(\CropTool\Config::class)->get('hostname');
},
\CropTool\ApiService::class => \DI\autowire(),
LoggerInterface::class => \DI\factory(function () use ($hasToolsDataDir) {
$formatter = new LineFormatter("[%datetime%] %channel%.%level_name%: %message% %extra%\n", null, false, true);
$streamHandler = new RotatingFileHandler( ($hasToolsDataDir ? getenv('TOOL_DATA_DIR') : ROOT_PATH) . '/logs/croptool.log', 30, Level::Info);
$streamHandler->setFormatter($formatter);
$handlers = [$streamHandler];
$processors = [new PsrLogMessageProcessor()];
$logger = new Logger('croptool', $handlers, $processors);
// IntrospectionProcessor adds filename, class, line to %extra%
// $streamHandler->pushProcessor(new IntrospectionProcessor(Logger::ERROR));
ErrorHandler::register($logger);
return $logger;
}),
\CropTool\Config::class => \DI\create()
->constructor(\DI\string(($hasToolsDataDir ? getenv('TOOL_DATA_DIR') : '{root_directory}') . '/config.ini')),
FileRepository::class => \DI\autowire()
->constructor(\DI\string( '{root_directory}/public_html')),
OAuthConsumer::class => \DI\autowire()
->constructorParameter('keyFile', \DI\string('{root_directory}/croptool-secret-key.txt'))
->constructorParameter('callbackUrl', \DI\string('https://{host}/api/auth/callback')), // https://tools.wmflabs.org/croptool/api/auth/callback'),
AuthServiceInterface::class => \DI\autowire(OAuthConsumer::class)
->constructorParameter('keyFile', \DI\string('{root_directory}/croptool-secret-key.txt'))
->constructorParameter('callbackUrl', \DI\string('https://{host}/api/auth/callback')), // https://tools.wmflabs.org/croptool/api/auth/callback'),,
\CropTool\SessionInterface::class => \DI\autowire(\CropTool\Session::class),
\CropTool\WikiPageService::class => \DI\autowire()
];