2
2
3
3
namespace PHPPM \Bootstraps ;
4
4
5
+ use PHPPM \Utils ;
5
6
use Symfony \Component \HttpFoundation \Request ;
6
7
7
8
/**
@@ -59,6 +60,7 @@ public function getApplication()
59
60
$ request = new Request ();
60
61
$ request ->setMethod (Request::METHOD_HEAD );
61
62
$ app ->handle ($ request );
63
+ $ this ->postHandle ($ app );
62
64
63
65
return $ app ;
64
66
}
@@ -71,14 +73,7 @@ public function getApplication()
71
73
public function preHandle ($ app )
72
74
{
73
75
//resets Kernels startTime, so Symfony can correctly calculate the execution time
74
- $ func = \Closure::bind (
75
- function () {
76
- $ this ->startTime = microtime (true );
77
- },
78
- $ app ,
79
- 'AppKernel '
80
- );
81
- $ func ($ app );
76
+ Utils::hijackProperty ($ app , 'startTime ' , microtime (true ));
82
77
}
83
78
84
79
/**
@@ -88,15 +83,84 @@ function () {
88
83
*/
89
84
public function postHandle ($ app )
90
85
{
86
+ $ container = $ app ->getContainer ();
87
+
91
88
//resets stopwatch, so it can correctly calculate the execution time
92
- if ($ app -> getContainer () ->has ('debug.stopwatch ' )) {
93
- $ app -> getContainer () ->get ('debug.stopwatch ' )->__construct ();
89
+ if ($ container ->has ('debug.stopwatch ' )) {
90
+ $ container ->get ('debug.stopwatch ' )->__construct ();
94
91
}
95
92
96
- if ($ app ->getContainer ()->has ('profiler ' )) {
93
+ //reset all profiler stuff currently supported
94
+ if ($ container ->has ('profiler ' )) {
95
+ $ profiler = $ container ->get ('profiler ' );
96
+
97
97
// since Symfony does not reset Profiler::disable() calls after each request, we need to do it,
98
98
// so the profiler bar is visible after the second request as well.
99
- $ app ->getContainer ()->get ('profiler ' )->enable ();
99
+ $ profiler ->enable ();
100
+
101
+ //PropelLogger
102
+ if ($ container ->has ('propel.logger ' )) {
103
+ $ propelLogger = $ container ->get ('propel.logger ' );
104
+ Utils::hijackProperty ($ propelLogger , 'queries ' , []);
105
+ }
106
+
107
+ //Doctrine
108
+ //Doctrine\Bundle\DoctrineBundle\DataCollector\DoctrineDataCollector
109
+ if ($ profiler ->has ('db ' )) {
110
+ Utils::bindAndCall (function () {
111
+ //$logger: \Doctrine\DBAL\Logging\DebugStack
112
+ foreach ($ this ->loggers as $ logger ){
113
+ Utils::hijackProperty ($ logger , 'queries ' , []);
114
+ }
115
+ }, $ profiler ->get ('db ' ), null , 'Symfony\Bridge\Doctrine\DataCollector\DoctrineDataCollector ' );
116
+ }
117
+
118
+ //ExceptionDataCollector
119
+ if ($ profiler ->has ('events ' )) {
120
+ Utils::hijackProperty ($ profiler ->get ('events ' ), 'data ' , array (
121
+ 'called_listeners ' => array (),
122
+ 'not_called_listeners ' => array (),
123
+ ));
124
+ }
125
+
126
+ //TwigDataCollector
127
+ if ($ profiler ->has ('twig ' )) {
128
+ Utils::bindAndCall (function () {
129
+ Utils::hijackProperty ($ this ->profile , 'profiles ' , []);
130
+ }, $ profiler ->get ('twig ' ));
131
+ }
132
+
133
+ //Logger
134
+ if ($ container ->has ('logger ' )) {
135
+ $ logger = $ container ->get ('logger ' );
136
+ Utils::bindAndCall (function () {
137
+ if ($ debugLogger = $ this ->getDebugLogger ()) {
138
+ //DebugLogger
139
+ Utils::hijackProperty ($ debugLogger , 'records ' , []);
140
+ }
141
+ }, $ logger );
142
+ }
143
+
144
+ //SwiftMailer logger
145
+ //Symfony\Bundle\SwiftmailerBundle\DataCollector\MessageDataCollector
146
+ if ($ container ->hasParameter ('swiftmailer.mailers ' )) {
147
+ $ mailers = $ container ->getParameter ('swiftmailer.mailers ' );
148
+ foreach ($ mailers as $ name => $ mailer ) {
149
+ $ loggerName = sprintf ('swiftmailer.mailer.%s.plugin.messagelogger ' , $ name );
150
+ if ($ container ->has ($ loggerName )) {
151
+ /** @var \Swift_Plugins_MessageLogger $logger */
152
+ $ logger = $ container ->get ($ loggerName );
153
+ $ logger ->clear ();
154
+ }
155
+ }
156
+ }
157
+
158
+ //Symfony\Bridge\Swiftmailer\DataCollector\MessageDataCollector
159
+ if ($ container ->has ('swiftmailer.plugin.messagelogger ' )) {
160
+ $ logger = $ container ->get ('swiftmailer.plugin.messagelogger ' );
161
+ $ logger ->clear ();
162
+ }
100
163
}
164
+
101
165
}
102
166
}
0 commit comments