Skip to content

Commit 6c7a541

Browse files
dunglasfabpot
authored andcommitted
[FrameworkBundle][HttpKernel] Add the ability to enable the profiler using a parameter
1 parent 36b49ce commit 6c7a541

File tree

9 files changed

+56
-0
lines changed

9 files changed

+56
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ CHANGELOG
99
* Add `set_content_language_from_locale` config option to automatically set the `Content-Language` HTTP response header based on the Request locale
1010
* Deprecate the `framework.translator.enabled_locales`, use `framework.enabled_locales` instead
1111
* Add autowiring alias for `HttpCache\StoreInterface`
12+
* Add the ability to enable the profiler using a request query parameter, body parameter or attribute
1213
* Deprecate the `AdapterInterface` autowiring alias, use `CacheItemPoolInterface` instead
1314
* Deprecate the public `profiler` service to private
1415
* Deprecate `get()`, `has()`, `getDoctrine()`, and `dispatchMessage()` in `AbstractController`, use method/constructor injection instead

DependencyInjection/Configuration.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ private function addProfilerSection(ArrayNodeDefinition $rootNode)
315315
->canBeEnabled()
316316
->children()
317317
->booleanNode('collect')->defaultTrue()->end()
318+
->scalarNode('collect_parameter')->defaultNull()->info('The name of the parameter to use to enable or disable collection on a per request basis')->end()
318319
->booleanNode('only_exceptions')->defaultFalse()->end()
319320
->booleanNode('only_main_requests')->defaultFalse()->end()
320321
->booleanNode('only_master_requests')->setDeprecated('symfony/framework-bundle', '5.3', 'Option "%node%" at "%path%" is deprecated, use "only_main_requests" instead.')->defaultFalse()->end()

DependencyInjection/FrameworkExtension.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,9 @@ private function registerProfilerConfiguration(array $config, ContainerBuilder $
770770
$container->getDefinition('profiler')
771771
->addArgument($config['collect'])
772772
->addTag('kernel.reset', ['method' => 'reset']);
773+
774+
$container->getDefinition('profiler_listener')
775+
->addArgument($config['collect_parameter']);
773776
}
774777

775778
private function registerWorkflowConfiguration(array $config, ContainerBuilder $container, PhpFileLoader $loader)

Resources/config/schema/symfony-1.0.xsd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191

9292
<xsd:complexType name="profiler">
9393
<xsd:attribute name="collect" type="xsd:string" />
94+
<xsd:attribute name="collect-parameter" type="xsd:string" />
9495
<xsd:attribute name="only-exceptions" type="xsd:string" />
9596
<xsd:attribute name="only-main-requests" type="xsd:string" />
9697
<xsd:attribute name="only-master-requests" type="xsd:string" />

Tests/DependencyInjection/ConfigurationTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ protected static function getBundleDefaultConfig()
405405
'only_main_requests' => false,
406406
'dsn' => 'file:%kernel.cache_dir%/profiler',
407407
'collect' => true,
408+
'collect_parameter' => null,
408409
],
409410
'translator' => [
410411
'enabled' => !class_exists(FullStack::class),

Tests/Functional/ProfilerTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,27 @@ public function testProfilerIsDisabled($insulate)
3636
$this->assertNull($client->getProfile());
3737
}
3838

39+
/**
40+
* @dataProvider getConfigs
41+
*/
42+
public function testProfilerCollectParameter($insulate)
43+
{
44+
$client = $this->createClient(['test_case' => 'ProfilerCollectParameter', 'root_config' => 'config.yml']);
45+
if ($insulate) {
46+
$client->insulate();
47+
}
48+
49+
$client->request('GET', '/profiler');
50+
$this->assertNull($client->getProfile());
51+
52+
// enable the profiler for the next request
53+
$client->request('GET', '/profiler?profile=1');
54+
$this->assertIsObject($client->getProfile());
55+
56+
$client->request('GET', '/profiler');
57+
$this->assertNull($client->getProfile());
58+
}
59+
3960
public function getConfigs()
4061
{
4162
return [
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
13+
use Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TestBundle;
14+
15+
return [
16+
new FrameworkBundle(),
17+
new TestBundle(),
18+
];
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
imports:
2+
- { resource: ../config/default.yml }
3+
4+
framework:
5+
profiler:
6+
enabled: true
7+
collect: false
8+
collect_parameter: profile
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
_sessiontest_bundle:
2+
resource: '@TestBundle/Resources/config/routing.yml'

0 commit comments

Comments
 (0)