Skip to content

Commit 3560b7d

Browse files
committed
Symfony bootstrap cleanup, the new 'kernel.reset' tag should do the job
1 parent f6d1250 commit 3560b7d

File tree

1 file changed

+1
-63
lines changed

1 file changed

+1
-63
lines changed

Bootstraps/Symfony.php

+1-63
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace PHPPM\Bootstraps;
44

5-
use PHPPM\Symfony\StrongerNativeSessionStorage;
65
use PHPPM\Utils;
76
use Symfony\Component\HttpFoundation\Request;
87
use function PHPPM\register_file;
@@ -63,30 +62,8 @@ public function getApplication()
6362
throw new \Exception("Symfony Kernel class was not found in the configured locations. Given: '$class'");
6463
}
6564

66-
//since we need to change some services, we need to manually change some services
6765
$app = new $class($this->appenv, $this->debug);
6866

69-
// We need to change some services, before the boot, because they would
70-
// otherwise be instantiated and passed to other classes which makes it
71-
// impossible to replace them.
72-
73-
Utils::bindAndCall(function () use ($app) {
74-
// init bundles
75-
$app->initializeBundles();
76-
77-
// init container
78-
$app->initializeContainer();
79-
}, $app);
80-
81-
Utils::bindAndCall(function () use ($app) {
82-
foreach ($app->getBundles() as $bundle) {
83-
$bundle->setContainer($app->container);
84-
$bundle->boot();
85-
}
86-
87-
$app->booted = true;
88-
}, $app);
89-
9067
if ($trustedProxies = getenv('TRUSTED_PROXIES')) {
9168
Request::setTrustedProxies(explode(',', $trustedProxies), Request::HEADER_X_FORWARDED_ALL ^ Request::HEADER_X_FORWARDED_HOST);
9269
}
@@ -119,8 +96,6 @@ protected function getVendorDir()
11996
*/
12097
public function preHandle($app)
12198
{
122-
//resets Kernels startTime, so Symfony can correctly calculate the execution time
123-
Utils::hijackProperty($app, 'startTime', microtime(true));
12499
}
125100

126101
/**
@@ -133,7 +108,7 @@ public function postHandle($app)
133108
$container = $app->getContainer();
134109

135110
if ($container->has('doctrine')) {
136-
$doctrineRegistry = $container->get("doctrine");
111+
$doctrineRegistry = $container->get('doctrine');
137112
foreach ($doctrineRegistry->getManagers() as $curManagerName => $curManager) {
138113
if (!$curManager->isOpen()) {
139114
$doctrineRegistry->resetManager($curManagerName);
@@ -143,11 +118,6 @@ public function postHandle($app)
143118
}
144119
}
145120

146-
//resets stopwatch, so it can correctly calculate the execution time
147-
if ($container->has('debug.stopwatch')) {
148-
$container->get('debug.stopwatch')->__construct();
149-
}
150-
151121
//Symfony\Bundle\TwigBundle\Loader\FilesystemLoader
152122
//->Twig_Loader_Filesystem
153123
if ($container->has('twig.loader')) {
@@ -161,44 +131,12 @@ public function postHandle($app)
161131

162132
//reset all profiler stuff currently supported
163133
if ($container->has('profiler')) {
164-
$profiler = $container->get('profiler');
165-
166-
// since Symfony does not reset Profiler::disable() calls after each request, we need to do it,
167-
// so the profiler bar is visible after the second request as well.
168-
$profiler->enable();
169-
170134
//PropelLogger
171135
if ($container->has('propel.logger')) {
172136
$propelLogger = $container->get('propel.logger');
173137
Utils::hijackProperty($propelLogger, 'queries', []);
174138
}
175139

176-
//Doctrine
177-
//Doctrine\Bundle\DoctrineBundle\DataCollector\DoctrineDataCollector
178-
if ($profiler->has('db')) {
179-
Utils::bindAndCall(function () {
180-
//$logger: \Doctrine\DBAL\Logging\DebugStack
181-
foreach ($this->loggers as $logger) {
182-
Utils::hijackProperty($logger, 'queries', []);
183-
}
184-
}, $profiler->get('db'), null, 'Symfony\Bridge\Doctrine\DataCollector\DoctrineDataCollector');
185-
}
186-
187-
//EventDataCollector
188-
if ($profiler->has('events')) {
189-
Utils::hijackProperty($profiler->get('events'), 'data', [
190-
'called_listeners' => [],
191-
'not_called_listeners' => [],
192-
]);
193-
}
194-
195-
//TwigDataCollector
196-
if ($profiler->has('twig')) {
197-
Utils::bindAndCall(function () {
198-
Utils::hijackProperty($this->profile, 'profiles', []);
199-
}, $profiler->get('twig'));
200-
}
201-
202140
//Logger
203141
if ($container->has('logger')) {
204142
$logger = $container->get('logger');

0 commit comments

Comments
 (0)