Skip to content

Commit f712fce

Browse files
committed
Merge branch '5.4' into 6.0
* 5.4: [FrameworkBundle][HttpKernel] Add the ability to enable the profiler using a parameter [FrameworkBundle] Trigger deprecations on stderr instead of using trigger_deprecation call Add PhpStanExtractor [Messenger] allow processing messages in batches [Console] Fix backslash escaping in bash completion Add missing validators translation add suggestions for debug:firewall, debug:form, debug:messenger, debug:router [SecurityBundle] Deprecate not configuring explicitly a provider for custom_authenticators when there is more than one registered provider [Inflector] Fix inflector for "zombies" [Config] Add some cache on SelfCheckingResourceChecker fix AJAX request unit spacing fix ErrorExcception in CacheWarmerAggregate Prevent FormLoginAuthenticator from responding to requests that should be handled by JsonLoginAuthenticator Fix wait duration for fixed window policy Add exact command used to trigger invocation to the completion debug log [Translation] correctly handle intl domains with TargetOperation Allow using param as connection atribute in `*.event_subscriber` and `*.event_listener` tags
2 parents c15274a + da6fd64 commit f712fce

File tree

11 files changed

+116
-1
lines changed

11 files changed

+116
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ CHANGELOG
3030
* Add `set_content_language_from_locale` config option to automatically set the `Content-Language` HTTP response header based on the Request locale
3131
* Deprecate the `framework.translator.enabled_locales`, use `framework.enabled_locales` instead
3232
* Add autowiring alias for `HttpCache\StoreInterface`
33+
* Add the ability to enable the profiler using a request query parameter, body parameter or attribute
3334
* Deprecate the `AdapterInterface` autowiring alias, use `CacheItemPoolInterface` instead
3435
* Deprecate the public `profiler` service to private
3536
* Deprecate `get()`, `has()`, `getDoctrine()`, and `dispatchMessage()` in `AbstractController`, use method/constructor injection instead
@@ -40,6 +41,7 @@ CHANGELOG
4041
* Bind the `default_context` parameter onto serializer's encoders and normalizers
4142
* Add support for `statusCode` default parameter when loading a template directly from route using the `Symfony\Bundle\FrameworkBundle\Controller\TemplateController` controller
4243
* Deprecate `translation:update` command, use `translation:extract` instead
44+
* Add `PhpStanExtractor` support for the PropertyInfo component
4345

4446
5.3
4547
---

Command/RouterDebugCommand.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
use Symfony\Bundle\FrameworkBundle\Console\Helper\DescriptorHelper;
1515
use Symfony\Component\Console\Attribute\AsCommand;
1616
use Symfony\Component\Console\Command\Command;
17+
use Symfony\Component\Console\Completion\CompletionInput;
18+
use Symfony\Component\Console\Completion\CompletionSuggestions;
1719
use Symfony\Component\Console\Exception\InvalidArgumentException;
1820
use Symfony\Component\Console\Input\InputArgument;
1921
use Symfony\Component\Console\Input\InputInterface;
@@ -130,4 +132,18 @@ private function findRouteNameContaining(string $name, RouteCollection $routes):
130132

131133
return $foundRoutesNames;
132134
}
135+
136+
public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void
137+
{
138+
if ($input->mustSuggestArgumentValuesFor('name')) {
139+
$suggestions->suggestValues(array_keys($this->router->getRouteCollection()->all()));
140+
141+
return;
142+
}
143+
144+
if ($input->mustSuggestOptionValuesFor('format')) {
145+
$helper = new DescriptorHelper();
146+
$suggestions->suggestValues($helper->getFormats());
147+
}
148+
}
133149
}

DependencyInjection/Configuration.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ private function addProfilerSection(ArrayNodeDefinition $rootNode)
301301
->canBeEnabled()
302302
->children()
303303
->booleanNode('collect')->defaultTrue()->end()
304+
->scalarNode('collect_parameter')->defaultNull()->info('The name of the parameter to use to enable or disable collection on a per request basis')->end()
304305
->booleanNode('only_exceptions')->defaultFalse()->end()
305306
->booleanNode('only_main_requests')->defaultFalse()->end()
306307
->scalarNode('dsn')->defaultValue('file:%kernel.cache_dir%/profiler')->end()

DependencyInjection/FrameworkExtension.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Doctrine\Common\Annotations\Reader;
1616
use Http\Client\HttpClient;
1717
use phpDocumentor\Reflection\DocBlockFactoryInterface;
18+
use PHPStan\PhpDocParser\Parser\PhpDocParser;
1819
use Psr\Cache\CacheItemPoolInterface;
1920
use Psr\Container\ContainerInterface as PsrContainerInterface;
2021
use Psr\EventDispatcher\EventDispatcherInterface as PsrEventDispatcherInterface;
@@ -158,6 +159,7 @@
158159
use Symfony\Component\Notifier\Recipient\Recipient;
159160
use Symfony\Component\Notifier\Transport\TransportFactoryInterface as NotifierTransportFactoryInterface;
160161
use Symfony\Component\PropertyAccess\PropertyAccessor;
162+
use Symfony\Component\PropertyInfo\Extractor\PhpStanExtractor;
161163
use Symfony\Component\PropertyInfo\PropertyAccessExtractorInterface;
162164
use Symfony\Component\PropertyInfo\PropertyDescriptionExtractorInterface;
163165
use Symfony\Component\PropertyInfo\PropertyInfoExtractorInterface;
@@ -766,6 +768,9 @@ private function registerProfilerConfiguration(array $config, ContainerBuilder $
766768
$container->getDefinition('profiler')
767769
->addArgument($config['collect'])
768770
->addTag('kernel.reset', ['method' => 'reset']);
771+
772+
$container->getDefinition('profiler_listener')
773+
->addArgument($config['collect_parameter']);
769774
}
770775

771776
private function registerWorkflowConfiguration(array $config, ContainerBuilder $container, PhpFileLoader $loader)
@@ -1771,7 +1776,15 @@ private function registerPropertyInfoConfiguration(ContainerBuilder $container,
17711776

17721777
$loader->load('property_info.php');
17731778

1774-
if (ContainerBuilder::willBeAvailable('phpdocumentor/reflection-docblock', DocBlockFactoryInterface::class, ['symfony/framework-bundle', 'symfony/property-info'])) {
1779+
if (
1780+
ContainerBuilder::willBeAvailable('phpstan/phpdoc-parser', PhpDocParser::class, ['symfony/framework-bundle', 'symfony/property-info'])
1781+
&& ContainerBuilder::willBeAvailable('phpdocumentor/type-resolver', PhpDocParser::class, ['symfony/framework-bundle', 'symfony/property-info'])
1782+
) {
1783+
$definition = $container->register('property_info.phpstan_extractor', PhpStanExtractor::class);
1784+
$definition->addTag('property_info.type_extractor', ['priority' => -1000]);
1785+
}
1786+
1787+
if (ContainerBuilder::willBeAvailable('phpdocumentor/reflection-docblock', DocBlockFactoryInterface::class, ['symfony/framework-bundle', 'symfony/property-info'], true)) {
17751788
$definition = $container->register('property_info.php_doc_extractor', 'Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor');
17761789
$definition->addTag('property_info.description_extractor', ['priority' => -1000]);
17771790
$definition->addTag('property_info.type_extractor', ['priority' => -1001]);

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
@@ -403,6 +403,7 @@ protected static function getBundleDefaultConfig()
403403
'only_main_requests' => false,
404404
'dsn' => 'file:%kernel.cache_dir%/profiler',
405405
'collect' => true,
406+
'collect_parameter' => null,
406407
],
407408
'translator' => [
408409
'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 [

Tests/Functional/RouterDebugCommandTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional;
1313

1414
use Symfony\Bundle\FrameworkBundle\Console\Application;
15+
use Symfony\Component\Console\Tester\CommandCompletionTester;
1516
use Symfony\Component\Console\Tester\CommandTester;
1617

1718
/**
@@ -69,6 +70,37 @@ public function testSearchWithThrow()
6970
$tester->execute(['name' => 'gerard'], ['interactive' => true]);
7071
}
7172

73+
/**
74+
* @dataProvider provideCompletionSuggestions
75+
*/
76+
public function testComplete(array $input, array $expectedSuggestions)
77+
{
78+
if (!class_exists(CommandCompletionTester::class)) {
79+
$this->markTestSkipped('Test command completion requires symfony/console 5.4+.');
80+
}
81+
82+
$tester = new CommandCompletionTester($this->application->get('debug:router'));
83+
$this->assertSame($expectedSuggestions, $tester->complete($input));
84+
}
85+
86+
public function provideCompletionSuggestions()
87+
{
88+
yield 'option --format' => [
89+
['--format', ''],
90+
['txt', 'xml', 'json', 'md'],
91+
];
92+
93+
yield 'route_name' => [
94+
[''],
95+
[
96+
'routerdebug_session_welcome',
97+
'routerdebug_session_welcome_name',
98+
'routerdebug_session_logout',
99+
'routerdebug_test',
100+
],
101+
];
102+
}
103+
72104
private function createCommandTester(): CommandTester
73105
{
74106
$command = $this->application->get('debug:router');
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

0 commit comments

Comments
 (0)