Skip to content

Commit 8ce93b9

Browse files
acasademontandig
authored andcommitted
Clean old resets now being done by the ResetInterface (#144)
1 parent a559879 commit 8ce93b9

File tree

7 files changed

+27
-118
lines changed

7 files changed

+27
-118
lines changed

Diff for: Bootstraps/Symfony.php

+8-109
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
namespace PHPPM\Bootstraps;
44

5-
use PHPPM\Symfony\StrongerNativeSessionStorage;
65
use PHPPM\Utils;
76
use Symfony\Component\HttpFoundation\Request;
87
use Symfony\Component\Config\Resource\FileResource;
98
use Symfony\Contracts\Service\ResetInterface;
109
use 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
}

Diff for: tests/Fixtures/Symfony/Controller/GetController.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22

33
namespace PHPPM\Tests\Fixtures\Symfony\Controller;
44

5-
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
65
use Symfony\Component\HttpFoundation\Response;
76
use Symfony\Component\Routing\Annotation\Route;
87

9-
class GetController extends Controller
8+
class GetController
109
{
1110
/**
1211
* @Route("/get")

Diff for: tests/Fixtures/Symfony/Controller/PostJsonController.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22

33
namespace PHPPM\Tests\Fixtures\Symfony\Controller;
44

5-
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
65
use Symfony\Component\HttpFoundation\Request;
76
use Symfony\Component\HttpFoundation\Response;
87
use Symfony\Component\Routing\Annotation\Route;
98

10-
class PostJsonController extends Controller
9+
class PostJsonController
1110
{
1211
/**
1312
* @Route("/json", methods={"POST"})

Diff for: tests/Fixtures/Symfony/Controller/StreamedController.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22

33
namespace PHPPM\Tests\Fixtures\Symfony\Controller;
44

5-
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
65
use Symfony\Component\HttpFoundation\StreamedResponse;
76
use Symfony\Component\Routing\Annotation\Route;
87

9-
class StreamedController extends Controller
8+
class StreamedController
109
{
1110
/**
1211
* @Route("/streamed")

Diff for: tests/Fixtures/Symfony/Controller/UploadController.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22

33
namespace PHPPM\Tests\Fixtures\Symfony\Controller;
44

5-
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
65
use Symfony\Component\HttpFoundation\Request;
76
use Symfony\Component\HttpFoundation\Response;
87
use Symfony\Component\Routing\Annotation\Route;
98

10-
class UploadController extends Controller
9+
class UploadController
1110
{
1211
/**
1312
* @Route("/upload", methods={"POST"})

Diff for: tests/Fixtures/Symfony/config/bundles.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
22

33
return [
4-
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
4+
\Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
55
];

Diff for: tests/Fixtures/Symfony/config/services.yaml

+14
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
11
services:
2+
# default configuration for services in *this* file
3+
_defaults:
4+
autowire: true # Automatically injects dependencies in your services.
5+
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
6+
public: false # Allows optimizing the container by removing unused services; this also means
7+
# fetching services directly from the container via $container->get() won't work.
8+
# The best practice is to be explicit about your dependencies anyway.
9+
10+
# makes classes in src/ available to be used as services
11+
# this creates a service per class whose id is the fully-qualified class name
12+
PHPPM\Tests\Fixtures\Symfony\Controller\:
13+
resource: '../Controller/*'
14+
tags: ['controller.service_arguments']
15+
216
framework:
317
secret: foobar

0 commit comments

Comments
 (0)