From 06b13c35e7d9b863b8947b749fb8b676adbe2f59 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 3 Jun 2021 17:11:29 +0200 Subject: [PATCH] [FrameworkBundle] Deprecate the public `profiler` service to private --- UPGRADE-5.4.md | 1 + UPGRADE-6.0.md | 2 +- .../Bundle/FrameworkBundle/CHANGELOG.md | 1 + .../Bundle/FrameworkBundle/KernelBrowser.php | 20 ++++++++++++------- .../Resources/config/profiling.php | 1 + 5 files changed, 17 insertions(+), 8 deletions(-) diff --git a/UPGRADE-5.4.md b/UPGRADE-5.4.md index 79a26bd52ca84..9c81e39a2f9cd 100644 --- a/UPGRADE-5.4.md +++ b/UPGRADE-5.4.md @@ -5,6 +5,7 @@ FrameworkBundle --------------- * Deprecate the `AdapterInterface` autowiring alias, use `CacheItemPoolInterface` instead + * Deprecate the public `profiler` service to private HttpKernel ---------- diff --git a/UPGRADE-6.0.md b/UPGRADE-6.0.md index 3287fb785633d..30f6f1fa5861f 100644 --- a/UPGRADE-6.0.md +++ b/UPGRADE-6.0.md @@ -82,7 +82,7 @@ FrameworkBundle * `MicroKernelTrait::configureRoutes()` is now always called with a `RoutingConfigurator` * The "framework.router.utf8" configuration option defaults to `true` * Removed `session.attribute_bag` service and `session.flash_bag` service. - * The `form.factory`, `form.type.file`, `translator`, `security.csrf.token_manager`, `serializer`, + * The `form.factory`, `form.type.file`, `profiler`, `translator`, `security.csrf.token_manager`, `serializer`, `cache_clearer`, `filesystem` and `validator` services are now private. * Removed the `lock.RESOURCE_NAME` and `lock.RESOURCE_NAME.store` services and the `lock`, `LockInterface`, `lock.store` and `PersistingStoreInterface` aliases, use `lock.RESOURCE_NAME.factory`, `lock.factory` or `LockFactory` instead. * Remove the `KernelTestCase::$container` property, use `KernelTestCase::getContainer()` instead diff --git a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md index 49ebf8c87dd6d..ee3a172397652 100644 --- a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md +++ b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md @@ -6,6 +6,7 @@ CHANGELOG * Add autowiring alias for `HttpCache\StoreInterface` * Deprecate the `AdapterInterface` autowiring alias, use `CacheItemPoolInterface` instead + * Deprecate the public `profiler` service to private 5.3 --- diff --git a/src/Symfony/Bundle/FrameworkBundle/KernelBrowser.php b/src/Symfony/Bundle/FrameworkBundle/KernelBrowser.php index 23f698d4bca28..c7c32f8e18858 100644 --- a/src/Symfony/Bundle/FrameworkBundle/KernelBrowser.php +++ b/src/Symfony/Bundle/FrameworkBundle/KernelBrowser.php @@ -49,7 +49,9 @@ public function __construct(KernelInterface $kernel, array $server = [], History */ public function getContainer() { - return $this->kernel->getContainer(); + $container = $this->kernel->getContainer(); + + return $container->has('test.service_container') ? $container->get('test.service_container') : $container; } /** @@ -69,11 +71,11 @@ public function getKernel() */ public function getProfile() { - if (null === $this->response || !$this->kernel->getContainer()->has('profiler')) { + if (null === $this->response || !$this->getContainer()->has('profiler')) { return false; } - return $this->kernel->getContainer()->get('profiler')->loadProfileFromResponse($this->response); + return $this->getContainer()->get('profiler')->loadProfileFromResponse($this->response); } /** @@ -83,7 +85,7 @@ public function getProfile() */ public function enableProfiler() { - if ($this->kernel->getContainer()->has('profiler')) { + if ($this->getContainer()->has('profiler')) { $this->profiler = true; } } @@ -123,7 +125,7 @@ public function loginUser($user, string $firewallContext = 'main'): self $token = new TestBrowserToken($user->getRoles(), $user, $firewallContext); $token->setAuthenticated(true); - $container = $this->kernel->getContainer()->get('test.service_container'); + $container = $this->getContainer(); $container->get('security.untracked_token_storage')->setToken($token); if (!$container->has('session') && !$container->has('session_factory')) { @@ -161,7 +163,7 @@ protected function doRequest($request) $this->profiler = false; $this->kernel->boot(); - $this->kernel->getContainer()->get('profiler')->enable(); + $this->getContainer()->get('profiler')->enable(); } return parent::doRequest($request); @@ -220,7 +222,11 @@ protected function getScript($request) $profilerCode = ''; if ($this->profiler) { - $profilerCode = '$kernel->getContainer()->get(\'profiler\')->enable();'; + $profilerCode = <<<'EOF' +$container = $kernel->getContainer(); +$container = $container->has('test.service_container') ? $container->get('test.service_container') : $container; +$container->get('profiler')->enable(); +EOF; } $code = <<public() ->args([service('profiler.storage'), service('logger')->nullOnInvalid()]) ->tag('monolog.logger', ['channel' => 'profiler']) + ->tag('container.private', ['package' => 'symfony/framework-bundle', 'version' => '5.4']) ->set('profiler.storage', FileProfilerStorage::class) ->args([param('profiler.storage.dsn')])