22
33namespace PHPPM \Bootstraps ;
44
5- use PHPPM \Symfony \StrongerNativeSessionStorage ;
65use PHPPM \Utils ;
76use Symfony \Component \HttpFoundation \Request ;
87use Symfony \Component \Config \Resource \FileResource ;
98use Symfony \Contracts \Service \ResetInterface ;
109use function PHPPM \register_file ;
10+ use Symfony \Component \HttpKernel \KernelInterface ;
1111
1212/**
1313 * A default bootstrap for the Symfony framework
@@ -39,7 +39,7 @@ public function initialize($appenv, $debug)
3939 /**
4040 * Create a Symfony application
4141 *
42- * @return \AppKernel
42+ * @return KernelInterface
4343 * @throws \Exception
4444 */
4545 public function getApplication ()
@@ -68,27 +68,6 @@ public function getApplication()
6868 //since we need to change some services, we need to manually change some services
6969 $ app = new $ class ($ this ->appenv , $ this ->debug );
7070
71- // We need to change some services, before the boot, because they would
72- // otherwise be instantiated and passed to other classes which makes it
73- // impossible to replace them.
74-
75- Utils::bindAndCall (function () use ($ app ) {
76- // init bundles
77- $ app ->initializeBundles ();
78-
79- // init container
80- $ app ->initializeContainer ();
81- }, $ app );
82-
83- Utils::bindAndCall (function () use ($ app ) {
84- foreach ($ app ->getBundles () as $ bundle ) {
85- $ bundle ->setContainer ($ app ->container );
86- $ bundle ->boot ();
87- }
88-
89- $ app ->booted = true ;
90- }, $ app );
91-
9271 if ($ this ->debug ) {
9372 Utils::bindAndCall (function () use ($ app ) {
9473 $ container = $ app ->container ;
@@ -149,25 +128,23 @@ protected function getVendorDir()
149128 /**
150129 * Does some necessary preparation before each request.
151130 *
152- * @param \AppKernel $app
131+ * @param KernelInterface $app
153132 */
154133 public function preHandle ($ app )
155134 {
156- //resets Kernels startTime, so Symfony can correctly calculate the execution time
157- Utils::hijackProperty ($ app , 'startTime ' , microtime (true ));
158135 }
159136
160137 /**
161138 * Does some necessary clean up after each request.
162139 *
163- * @param \AppKernel $app
140+ * @param KernelInterface $app
164141 */
165142 public function postHandle ($ app )
166143 {
167144 $ container = $ app ->getContainer ();
168145
169146 if ($ container ->has ('doctrine ' )) {
170- $ doctrineRegistry = $ container ->get (" doctrine " );
147+ $ doctrineRegistry = $ container ->get (' doctrine ' );
171148 if (!$ doctrineRegistry instanceof ResetInterface) {
172149 foreach ($ doctrineRegistry ->getManagers () as $ curManagerName => $ curManager ) {
173150 if (!$ curManager ->isOpen ()) {
@@ -179,11 +156,6 @@ public function postHandle($app)
179156 }
180157 }
181158
182- //resets stopwatch, so it can correctly calculate the execution time
183- if ($ container ->has ('debug.stopwatch ' )) {
184- $ container ->get ('debug.stopwatch ' )->__construct ();
185- }
186-
187159 //Symfony\Bundle\TwigBundle\Loader\FilesystemLoader
188160 //->Twig_Loader_Filesystem
189161 if ($ this ->debug && $ container ->has ('twig.loader ' )) {
@@ -195,83 +167,10 @@ public function postHandle($app)
195167 }, $ twigLoader );
196168 }
197169
198- //reset Webpack Encore file list
199- Utils::bindAndCall (function () use ($ container ) {
200- if (isset ($ container ->privates ['webpack_encore.entrypoint_lookup ' ])) {
201- $ container ->privates ['webpack_encore.entrypoint_lookup ' ]->reset ();
202- }
203- }, $ container );
204-
205170 //reset all profiler stuff currently supported
206- if ($ container ->has ('profiler ' )) {
207- $ profiler = $ container ->get ('profiler ' );
208-
209- // since Symfony does not reset Profiler::disable() calls after each request, we need to do it,
210- // so the profiler bar is visible after the second request as well.
211- $ profiler ->enable ();
212-
213- //PropelLogger
214- if ($ container ->has ('propel.logger ' )) {
215- $ propelLogger = $ container ->get ('propel.logger ' );
216- Utils::hijackProperty ($ propelLogger , 'queries ' , []);
217- }
218-
219- //Doctrine
220- //Doctrine\Bundle\DoctrineBundle\DataCollector\DoctrineDataCollector
221- if ($ profiler ->has ('db ' )) {
222- Utils::bindAndCall (function () {
223- //$logger: \Doctrine\DBAL\Logging\DebugStack
224- foreach ($ this ->loggers as $ logger ) {
225- Utils::hijackProperty ($ logger , 'queries ' , []);
226- }
227- }, $ profiler ->get ('db ' ), null , 'Symfony\Bridge\Doctrine\DataCollector\DoctrineDataCollector ' );
228- }
229-
230- //EventDataCollector
231- if ($ profiler ->has ('events ' )) {
232- Utils::hijackProperty ($ profiler ->get ('events ' ), 'data ' , [
233- 'called_listeners ' => [],
234- 'not_called_listeners ' => [],
235- ]);
236- }
237-
238- //TwigDataCollector
239- if ($ profiler ->has ('twig ' )) {
240- Utils::bindAndCall (function () {
241- Utils::hijackProperty ($ this ->profile , 'profiles ' , []);
242- }, $ profiler ->get ('twig ' ));
243- }
244-
245- //Logger
246- if ($ container ->has ('logger ' )) {
247- $ logger = $ container ->get ('logger ' );
248- Utils::bindAndCall (function () {
249- if (\method_exists ($ this , 'getDebugLogger ' ) && $ debugLogger = $ this ->getDebugLogger ()) {
250- //DebugLogger
251- Utils::hijackProperty ($ debugLogger , 'records ' , []);
252- }
253- }, $ logger );
254- }
255-
256- //SwiftMailer logger
257- //Symfony\Bundle\SwiftmailerBundle\DataCollector\MessageDataCollector
258- if ($ container ->hasParameter ('swiftmailer.mailers ' )) {
259- $ mailers = $ container ->getParameter ('swiftmailer.mailers ' );
260- foreach ($ mailers as $ name => $ mailer ) {
261- $ loggerName = sprintf ('swiftmailer.mailer.%s.plugin.messagelogger ' , $ name );
262- if ($ container ->has ($ loggerName )) {
263- /** @var \Swift_Plugins_MessageLogger $logger */
264- $ logger = $ container ->get ($ loggerName );
265- $ logger ->clear ();
266- }
267- }
268- }
269-
270- //Symfony\Bridge\Swiftmailer\DataCollector\MessageDataCollector
271- if ($ container ->has ('swiftmailer.plugin.messagelogger ' )) {
272- $ logger = $ container ->get ('swiftmailer.plugin.messagelogger ' );
273- $ logger ->clear ();
274- }
171+ if ($ container ->has ('propel.logger ' )) {
172+ $ propelLogger = $ container ->get ('propel.logger ' );
173+ Utils::hijackProperty ($ propelLogger , 'queries ' , []);
275174 }
276175 }
277176}
0 commit comments