LogServiceProvider::boot()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
ccs 3
cts 3
cp 1
crap 1
1
<?php
2
3
namespace Eccube\ServiceProvider;
4
5
use Eccube\EventListener\LogListener;
6
use Eccube\Log\Logger;
7
use Eccube\Log\Monolog\Helper\LogHelper;
8
use Silex\Application;
9
use Silex\ServiceProviderInterface;
10
11
/**
12
 * Class LogServiceProvider
13
 *
14
 * @package Eccube\ServiceProvider
15
 */
16
class LogServiceProvider implements ServiceProviderInterface
17
{
18 1234
    public function register(Application $app)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
19
    {
20 1234
        $app->register(new \Silex\Provider\MonologServiceProvider());
21
22
        // Log
23
        $app['eccube.logger'] = $app->share(function ($app) {
24 1232
            return new Logger($app);
25 1234
        });
26
27
        // ヘルパー作成
28
        $app['eccube.monolog.helper'] = $app->share(function ($app) {
29 1232
            return new LogHelper($app);
30 1234
        });
31
32
        // ログクラス作成ファクトリー
33
        $app['eccube.monolog.factory'] = $app->protect(function (array $channelValues) use ($app) {
34
35 599
            $log = new $app['monolog.logger.class']($channelValues['name']);
0 ignored issues
show
introduced by
Use parentheses when instantiating classes
Loading history...
36
37
            // EccubeMonologHelper内でHandlerを設定している
38 599
            $log->pushHandler($app['eccube.monolog.helper']->getHandler($channelValues));
39
40 599
            return $log;
41 1234
        });
42
43
        // チャネルに応じてログを作成し、フロント、管理、プラグイン用のログ出力クラスを作成
44 1234
        $channels = $app['config']['log']['channel'];
45
        // monologの設定は除外
46 1234
        unset($channels['monolog']);
47 1234
        foreach ($channels as $channel => $channelValues) {
48
            $app['monolog.logger.'.$channel] = $app->share(function ($app) use ($channelValues) {
49 599
                return $app['eccube.monolog.factory']($channelValues);
50 1234
            });
51
        }
52
53
        // MonologServiceProviderで定義されているmonolog.handlerの置換
54 1234
        $channelValues = $app['config']['log']['channel']['monolog'];
55 1234
        $app['monolog.name'] = $channelValues['name'];
56
        $app['monolog.handler'] = $app->share(function ($app) use ($channelValues) {
57 1232
            return $app['eccube.monolog.helper']->getHandler($channelValues);
58 1234
        });
59
60
        $app['eccube.monolog.listener'] = $app->share(function () use ($app) {
61 1232
            return new LogListener($app['eccube.logger']);
62 1234
        });
63
64 1234
        $app['listener.requestdump'] = $app->share(function ($app) {
65 1232
            return new \Eccube\EventListener\RequestDumpListener($app);
66 1234
        });
67
    }
68
69 1232
    public function boot(Application $app)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
70
    {
71 1232
        $app['dispatcher']->addSubscriber($app['listener.requestdump']);
72 1232
        $app['dispatcher']->addSubscriber($app['eccube.monolog.listener']);
73
    }
74
}
75