|
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\Dumper\HtmlDumper; |
|
36
|
|
|
use Symfony\Component\VarDumper\VarDumper; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Debug Dump |
|
40
|
|
|
* |
|
41
|
|
|
* The MIT License (MIT) |
|
42
|
|
|
* |
|
43
|
|
|
* Copyright (c) 2014 Jérôme Macias |
|
44
|
|
|
* |
|
45
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
|
46
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
|
47
|
|
|
* in the Software without restriction, including without limitation the rights |
|
48
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
49
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
|
50
|
|
|
* furnished to do so, subject to the following conditions: |
|
51
|
|
|
* |
|
52
|
|
|
* The above copyright notice and this permission notice shall be included in all |
|
53
|
|
|
* copies or substantial portions of the Software. |
|
54
|
|
|
* |
|
55
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
56
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
57
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
58
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
59
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
60
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
|
61
|
|
|
* SOFTWARE. |
|
62
|
|
|
* |
|
63
|
|
|
* @see https://github.com/jeromemacias/Silex-Debug/tree/1.0 |
|
64
|
|
|
* |
|
65
|
|
|
*/ |
|
66
|
|
|
class DebugServiceProvider implements ServiceProviderInterface |
|
67
|
|
|
{ |
|
68
|
|
|
public function register(Application $app) |
|
|
|
|
|
|
69
|
|
|
{ |
|
70
|
|
|
$app['var_dumper.cloner'] = $app->share(function ($app) { |
|
71
|
|
|
$cloner = new VarCloner(); |
|
72
|
|
|
|
|
73
|
|
|
if (isset($app['debug.max_items'])) { |
|
74
|
|
|
$cloner->setMaxItems($app['debug.max_items']); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
if (isset($app['debug.max_string_length'])) { |
|
78
|
|
|
$cloner->setMaxString($app['debug.max_string_length']); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
return $cloner; |
|
82
|
|
|
}); |
|
83
|
|
|
|
|
84
|
|
|
$app['data_collector.templates'] = $app->share($app->extend('data_collector.templates', function ($templates) { |
|
85
|
|
|
return array_merge($templates, 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'], null, null, new HtmlDumper()); |
|
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) |
|
|
|
|
|
|
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 = $app['data_collector.dump']; |
|
128
|
|
|
$cloner = $app['var_dumper.cloner']; |
|
129
|
|
|
|
|
130
|
|
|
$handler = function ($var) use ($dumper, $cloner) { |
|
131
|
|
|
$dumper->dump($cloner->cloneVar($var)); |
|
132
|
|
|
}; |
|
133
|
|
|
|
|
134
|
|
|
VarDumper::setHandler($handler); |
|
135
|
|
|
$handler($var); |
|
136
|
|
|
}); |
|
137
|
|
|
|
|
138
|
|
|
$app['dispatcher']->addSubscriber(new DumpListener($app['var_dumper.cloner'], $app['data_collector.dump'])); |
|
139
|
|
|
} |
|
140
|
|
|
} |
|
141
|
|
|
|