Failed Conditions
Pull Request — master (#1873)
by Tsuyoshi
273:59 queued 266:59
created

LogServiceProvider::boot()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

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