Failed Conditions
Push — master ( 3ed8ee...0f3867 )
by Kentaro
19:22
created

DebugServiceProvider   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 7

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 7
dl 0
loc 69
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B register() 0 53 4
A boot() 0 12 1
1
<?php
2
/*
3
 * This file is part of EC-CUBE
4
 *
5
 * Copyright(c) 2000-2015 LOCKON CO.,LTD. All Rights Reserved.
6
 *
7
 * http://www.lockon.co.jp/
8
 *
9
 * This program is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU General Public License
11
 * as published by the Free Software Foundation; either version 2
12
 * of the License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, write to the Free Software
21
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
 */
23
24
25
namespace Eccube\ServiceProvider;
26
27
use Silex\Application;
28
use Silex\ServiceProviderInterface;
29
use Symfony\Bridge\Twig\Extension\DumpExtension;
30
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
31
use Symfony\Component\HttpKernel\DataCollector\DumpDataCollector;
32
use Symfony\Component\HttpKernel\EventListener\DumpListener;
33
use Symfony\Component\VarDumper\Cloner\VarCloner;
34
use Symfony\Component\VarDumper\Dumper\CliDumper;
35
use Symfony\Component\VarDumper\VarDumper;
36
37
/**
38
 * Debug Dump
39
 *
40
 * The MIT License (MIT)
41
 *
42
 * Copyright (c) 2014 Jérôme Macias
43
 *
44
 * Permission is hereby granted, free of charge, to any person obtaining a copy
45
 * of this software and associated documentation files (the "Software"), to deal
46
 * in the Software without restriction, including without limitation the rights
47
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
48
 * copies of the Software, and to permit persons to whom the Software is
49
 * furnished to do so, subject to the following conditions:
50
 *
51
 * The above copyright notice and this permission notice shall be included in all
52
 * copies or substantial portions of the Software.
53
 *
54
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
55
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
56
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
57
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
58
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
59
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
60
 * SOFTWARE.
61
 *
62
 * @see https://github.com/jeromemacias/Silex-Debug/tree/1.0
63
 *
64
 */
65
class DebugServiceProvider implements ServiceProviderInterface
66
{
67
    public function register(Application $app)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
68
    {
69
        $app['var_dumper.cloner'] = $app->share(function ($app) {
70
            $cloner = new VarCloner();
71
72
            if (isset($app['debug.max_items'])) {
73
                $cloner->setMaxItems($app['debug.max_items']);
74
            }
75
76
            if (isset($app['debug.max_string_length'])) {
77
                $cloner->setMaxString($app['debug.max_string_length']);
78
            }
79
80
            return $cloner;
81
        });
82
83
        $app['data_collector.templates'] = array_merge(
84
            $app['data_collector.templates'],
85
            array(array('dump', '@Debug/Profiler/dump.html.twig'))
86
        );
87
88
        $app['data_collector.dump'] = $app->share(function ($app) {
89
            return new DumpDataCollector($app['stopwatch'], $app['code.file_link_format']);
90
        });
91
92
        $app['data_collectors'] = $app->share($app->extend('data_collectors', function ($collectors, $app) {
93
            $collectors['dump'] = $app->share(function ($app) {
94
                return $app['data_collector.dump'];
95
            });
96
97
            return $collectors;
98
        }));
99
100
        $app['twig'] = $app->share($app->extend('twig', function ($twig, $app) {
101
            if (class_exists('\Symfony\Bridge\Twig\Extension\DumpExtension')) {
102
                $twig->addExtension(new DumpExtension($app['var_dumper.cloner']));
103
            }
104
105
            return $twig;
106
        }));
107
108
        $app['twig.loader.filesystem'] = $app->share($app->extend('twig.loader.filesystem', function ($loader, $app) {
109
            $loader->addPath($app['debug.templates_path'], 'Debug');
110
111
            return $loader;
112
        }));
113
114
        $app['debug.templates_path'] = function () {
115
            $r = new \ReflectionClass('Symfony\Bundle\DebugBundle\DependencyInjection\Configuration');
116
117
            return dirname(dirname($r->getFileName())).'/Resources/views';
118
        };
119
    }
120
121
    public function boot(Application $app)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
122
    {
123
        // This code is here to lazy load the dump stack. This default
124
        // configuration for CLI mode is overridden in HTTP mode on
125
        // 'kernel.request' event
126
        VarDumper::setHandler(function ($var) use ($app) {
127
            $dumper = new CliDumper();
128
            $dumper->dump($app['var_dumper.cloner']->cloneVar($var));
129
        });
130
131
        $app['dispatcher']->addSubscriber(new DumpListener($app['var_dumper.cloner'], $app['data_collector.dump']));
132
    }
133
}
134