-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.php
71 lines (58 loc) · 1.89 KB
/
index.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
66
67
68
69
70
71
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2019/9/19
* Time: 14:56
*/
use DI\ContainerBuilder;
use Psr\Log\LoggerInterface;
use Psr\Container\ContainerInterface;
use Monolog\Logger;
use Monolog\Processor\UidProcessor;
use Monolog\Handler\StreamHandler;
use Rrclic\App;
use Rrclic\Service\ConsoleFormatOutput;
use Rrclic\Service\HtmlFormatOutput;
use Rrclic\Service\MarketValueFromEastMoney;
use Rrclic\Service\MoneyExchangeFromSina;
use Rrclic\Contract\FormatOutput;
use Rrclic\Contract\MarketValue;
use Rrclic\Contract\MoneyExchange;
const APP_PATH = __DIR__;
require APP_PATH . '/vendor/autoload.php';
$builder = new ContainerBuilder();
$builder->addDefinitions(
[
'config' => require APP_PATH . '/config/config.php',
'database' => require APP_PATH . '/config/database.php',
LoggerInterface::class => DI\factory(function (ContainerInterface $c) {
$loggerSetting = $c->get('config')['logger'];
$logger = new Logger($loggerSetting['name']);
$processor = new UidProcessor();
$logger->pushProcessor($processor);
$handler = new StreamHandler($loggerSetting['path'], $loggerSetting['level']);
$logger->pushHandler($handler);
return $logger;
}),
MarketValue::class => DI\create(MarketValueFromEastMoney::class),
MoneyExchange::class => DI\create(MoneyExchangeFromSina::class),
]
);
if (PHP_SAPI === 'cli') {
$builder->addDefinitions(
[
FormatOutput::class => DI\create(ConsoleFormatOutput::class),
]
);
} else {
$builder->addDefinitions(
[
FormatOutput::class => DI\autowire(HtmlFormatOutput::class),
]
);
}
$container = $builder->build();
App::setContainer($container);
$app = $container->get(App::class);
$app->run();