Skip to content

Commit 47fe11e

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 2706a22 + a9f8989 commit 47fe11e

File tree

4 files changed

+49
-2
lines changed

4 files changed

+49
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ CHANGELOG
1313
5.4
1414
---
1515

16+
* Add the ability to enable the profiler using a request query parameter, body parameter or attribute
1617
* Deprecate `AbstractTestSessionListener::getSession` inject a session in the request instead
1718
* Deprecate the `fileLinkFormat` parameter of `DebugHandlersListener`
1819
* Add support for configuring log level, and status code by exception class

CacheWarmer/CacheWarmerAggregate.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ public function warmUp(string $cacheDir): array
104104

105105
if (is_file($this->deprecationLogsFilepath)) {
106106
$previousLogs = unserialize(file_get_contents($this->deprecationLogsFilepath));
107-
$collectedLogs = array_merge($previousLogs, $collectedLogs);
107+
if (\is_array($previousLogs)) {
108+
$collectedLogs = array_merge($previousLogs, $collectedLogs);
109+
}
108110
}
109111

110112
file_put_contents($this->deprecationLogsFilepath, serialize(array_values($collectedLogs)));

EventListener/ProfilerListener.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,14 @@ class ProfilerListener implements EventSubscriberInterface
3636
private ?\Throwable $exception = null;
3737
private \SplObjectStorage $profiles;
3838
private RequestStack $requestStack;
39+
private ?string $collectParameter;
3940
private \SplObjectStorage $parents;
4041

4142
/**
4243
* @param bool $onlyException True if the profiler only collects data when an exception occurs, false otherwise
4344
* @param bool $onlyMainRequests True if the profiler only collects data when the request is the main request, false otherwise
4445
*/
45-
public function __construct(Profiler $profiler, RequestStack $requestStack, RequestMatcherInterface $matcher = null, bool $onlyException = false, bool $onlyMainRequests = false)
46+
public function __construct(Profiler $profiler, RequestStack $requestStack, RequestMatcherInterface $matcher = null, bool $onlyException = false, bool $onlyMainRequests = false, string $collectParameter = null)
4647
{
4748
$this->profiler = $profiler;
4849
$this->matcher = $matcher;
@@ -51,6 +52,7 @@ public function __construct(Profiler $profiler, RequestStack $requestStack, Requ
5152
$this->profiles = new \SplObjectStorage();
5253
$this->parents = new \SplObjectStorage();
5354
$this->requestStack = $requestStack;
55+
$this->collectParameter = $collectParameter;
5456
}
5557

5658
/**
@@ -79,6 +81,10 @@ public function onKernelResponse(ResponseEvent $event)
7981
}
8082

8183
$request = $event->getRequest();
84+
if (null !== $this->collectParameter && null !== $collectParameterValue = $request->get($this->collectParameter)) {
85+
true === $collectParameterValue || filter_var($collectParameterValue, \FILTER_VALIDATE_BOOLEAN) ? $this->profiler->enable() : $this->profiler->disable();
86+
}
87+
8288
$exception = $this->exception;
8389
$this->exception = null;
8490

Tests/EventListener/ProfilerListenerTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,42 @@ public function testKernelTerminate()
5959

6060
$listener->onKernelTerminate(new TerminateEvent($kernel, $mainRequest, $response));
6161
}
62+
63+
/**
64+
* @dataProvider collectRequestProvider
65+
*/
66+
public function testCollectParameter(Request $request, ?bool $enable)
67+
{
68+
$profile = new Profile('token');
69+
70+
$profiler = $this->createMock(Profiler::class);
71+
$profiler->expects($this->once())
72+
->method('collect')
73+
->willReturn($profile);
74+
75+
$profiler
76+
->expects(null === $enable ? $this->never() : $this->once())
77+
->method($enable ? 'enable' : 'disable');
78+
79+
$kernel = $this->createMock(HttpKernelInterface::class);
80+
$response = new Response();
81+
82+
$requestStack = new RequestStack();
83+
$requestStack->push($request);
84+
85+
$listener = new ProfilerListener($profiler, $requestStack, null, false, false, 'profile');
86+
87+
$listener->onKernelResponse(new ResponseEvent($kernel, $request, Kernel::MAIN_REQUEST, $response));
88+
}
89+
90+
public function collectRequestProvider(): iterable
91+
{
92+
yield [Request::create('/'), null];
93+
yield [Request::create('/', 'GET', ['profile' => '1']), true];
94+
yield [Request::create('/', 'GET', ['profile' => '0']), false];
95+
96+
$request = Request::create('/');
97+
$request->attributes->set('profile', true);
98+
yield [$request, true];
99+
}
62100
}

0 commit comments

Comments
 (0)