Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3db2dd6

Browse filesBrowse files
bug symfony#49405 [MonologBridge] FirePHPHandler::onKernelResponse throws PHP 8.1 deprecation when no user agent is set (juagarc4)
This PR was squashed before being merged into the 5.4 branch. Discussion ---------- [MonologBridge] FirePHPHandler::onKernelResponse throws PHP 8.1 deprecation when no user agent is set | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes/no | New feature? no | Deprecations? no | Tickets | Fix symfony#49392 | License | MIT - Add casting to the second parameter to pass always the right type. **PHPstan before:** ------ -------------------------------------------------------------------------------------------------------- Line FirePHPHandler.php ------ -------------------------------------------------------------------------------------------------------- 27 Property Symfony\Bridge\Monolog\Handler\FirePHPHandler::$headers has no type specified. 37 Method Symfony\Bridge\Monolog\Handler\FirePHPHandler::onKernelResponse() has no return type specified. **44 Parameter #2 $subject of function preg_match expects string, string|null given.** 68 If condition is always true. ------ -------------------------------------------------------------------------------------------------------- **PHPstan after:** ------ -------------------------------------------------------------------------------------------------------- Line FirePHPHandler.php ------ -------------------------------------------------------------------------------------------------------- 27 Property Symfony\Bridge\Monolog\Handler\FirePHPHandler::$headers has no type specified. 37 Method Symfony\Bridge\Monolog\Handler\FirePHPHandler::onKernelResponse() has no return type specified. 68 If condition is always true. ------ -------------------------------------------------------------------------------------------------------- Commits ------- 4d84c46 [MonologBridge] FirePHPHandler::onKernelResponse throws PHP 8.1 deprecation when no user agent is set
2 parents 879b5d1 + 4d84c46 commit 3db2dd6
Copy full SHA for 3db2dd6

File tree

Expand file treeCollapse file tree

2 files changed

+41
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+41
-1
lines changed

‎src/Symfony/Bridge/Monolog/Handler/FirePHPHandler.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Monolog/Handler/FirePHPHandler.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function onKernelResponse(ResponseEvent $event)
4141
}
4242

4343
$request = $event->getRequest();
44-
if (!preg_match('{\bFirePHP/\d+\.\d+\b}', $request->headers->get('User-Agent'))
44+
if (!preg_match('{\bFirePHP/\d+\.\d+\b}', $request->headers->get('User-Agent', ''))
4545
&& !$request->headers->has('X-FirePHP-Version')) {
4646
self::$sendHeaders = false;
4747
$this->headers = [];
+40Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
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+
namespace Symfony\Bridge\Monolog\Tests\Handler;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\Monolog\Handler\FirePHPHandler;
16+
use Symfony\Component\HttpFoundation\Request;
17+
use Symfony\Component\HttpFoundation\Response;
18+
use Symfony\Component\HttpKernel\Event\ResponseEvent;
19+
use Symfony\Component\HttpKernel\HttpKernelInterface;
20+
21+
class FirePHPHandlerTest extends TestCase
22+
{
23+
public function testOnKernelResponseShouldNotTriggerDeprecation()
24+
{
25+
$request = Request::create('/');
26+
$request->headers->remove('User-Agent');
27+
28+
$response = new Response('foo');
29+
$event = new ResponseEvent($this->createMock(HttpKernelInterface::class), $request, HttpKernelInterface::MAIN_REQUEST, $response);
30+
31+
$error = null;
32+
set_error_handler(function ($type, $message) use (&$error) { $error = $message; }, \E_DEPRECATED);
33+
34+
$listener = new FirePHPHandler();
35+
$listener->onKernelResponse($event);
36+
restore_error_handler();
37+
38+
$this->assertNull($error);
39+
}
40+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.