Skip to content

[FrameworkBundle] Deprecate the public profiler service to private #41530

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions UPGRADE-5.4.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ FrameworkBundle
---------------

* Deprecate the `AdapterInterface` autowiring alias, use `CacheItemPoolInterface` instead
* Deprecate the public `profiler` service to private

HttpKernel
----------
Expand Down
2 changes: 1 addition & 1 deletion UPGRADE-6.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
---
Expand Down
20 changes: 13 additions & 7 deletions src/Symfony/Bundle/FrameworkBundle/KernelBrowser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -83,7 +85,7 @@ public function getProfile()
*/
public function enableProfiler()
{
if ($this->kernel->getContainer()->has('profiler')) {
if ($this->getContainer()->has('profiler')) {
$this->profiler = true;
}
}
Expand Down Expand Up @@ -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')) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 = <<<EOF
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
->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')])
Expand Down