Skip to content

Commit 836c76c

Browse files
ymorocuttiYoann MOROCUTTI
andauthored
PHP 8 - Symfony 6.4 (#64)
* feat: Remove deprecated serializers that will no longer work with Symfony 7 [symfony-6] * feat: Define route using attribute instead of annotation (require Symfony 5.2) [symfony-6] * refactor: Type hint classes and migrate code to be PHP 8 friendly [symfony-6] * build: Update symfony/routing requirement to be at least 5.4 [symfony-6] --------- Co-authored-by: Yoann MOROCUTTI <Yoann.MOROCUTTI@boursorama.fr>
1 parent bb0b224 commit 836c76c

8 files changed

Lines changed: 1360 additions & 973 deletions

File tree

Controller/ReplayController.php

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
11
<?php
2-
/**
3-
* Created by PhpStorm.
4-
* User: sroussel
5-
* Date: 03/02/2016
6-
* Time: 16:30
7-
*/
82

93
namespace evaisse\SimpleHttpBundle\Controller;
104

@@ -20,22 +14,11 @@
2014
*/
2115
class ReplayController extends AbstractController
2216
{
23-
/** @var Helper $serviceHelper */
24-
protected $serviceHelper;
25-
26-
/**
27-
* @param Helper $serviceHelper
28-
*/
29-
public function __construct(Helper $serviceHelper)
17+
public function __construct(protected Helper $serviceHelper)
3018
{
31-
$this->serviceHelper = $serviceHelper;
3219
}
3320

34-
/**
35-
* @Route("/http-replay", name="simple_http.replay_request")
36-
* @param Request $request
37-
* @return Response
38-
*/
21+
#[Route('/http-replay', name: 'simple_http.replay_request')]
3922
public function replayRequestAction(Request $request): Response
4023
{
4124
$request = json_decode($request->request->get('request'));

DataCollector/ProfilerDataCollector.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
namespace evaisse\SimpleHttpBundle\DataCollector;
44

55
use evaisse\SimpleHttpBundle\Http\StatementEventMap;
6-
use evaisse\SimpleHttpBundle\Serializer\RequestNormalizer;
76
use Symfony\Component\HttpFoundation\Request;
87
use Symfony\Component\HttpFoundation\Response;
98
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
109
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
1110
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
1211
use Symfony\Component\HttpKernel\Event\RequestEvent;
1312
use Symfony\Component\HttpKernel\Event\ResponseEvent;
13+
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
14+
use Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer;
1415
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
1516
use Symfony\Component\Serializer\Serializer;
1617
use Symfony\Component\Serializer\Encoder\JsonEncoder;
@@ -280,7 +281,11 @@ public function fetchTransferInfos(array $call): array
280281

281282
public function fetchRequestInfos(Request $request): array
282283
{
283-
$normalizers = array(new RequestNormalizer(), new ObjectNormalizer());
284+
$normalizers = array(new GetSetMethodNormalizer(defaultContext: [
285+
AbstractNormalizer::IGNORED_ATTRIBUTES => [
286+
'session',
287+
]
288+
]), new ObjectNormalizer());
284289
$encoders = array(new JsonEncoder());
285290
$serializer = new Serializer($normalizers, $encoders);
286291

Serializer/CustomGetSetNormalizer.php

Lines changed: 0 additions & 46 deletions
This file was deleted.

Serializer/RequestNormalizer.php

Lines changed: 0 additions & 21 deletions
This file was deleted.

Service/Helper.php

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,10 @@
1414

1515
class Helper
1616
{
17-
/** @var Kernel */
18-
protected $httpKernel;
19-
20-
/** @var EventDispatcherInterface */
21-
protected $eventDispatcher;
22-
23-
/**
24-
* Helper constructor.
25-
* @param Kernel $httpKernel
26-
* @param EventDispatcherInterface $eventDispatcher
27-
*/
28-
public function __construct(Kernel $httpKernel, EventDispatcherInterface $eventDispatcher)
17+
public function __construct(protected Kernel $httpKernel, protected EventDispatcherInterface $eventDispatcher)
2918
{
30-
$this->httpKernel = $httpKernel;
31-
$this->eventDispatcher = $eventDispatcher;
3219
}
3320

34-
/**
35-
*
36-
* @return CookieJar
37-
*/
3821
public function getDefaultCookieJar(): SessionCookieJar|CookieJar
3922
{
4023
return $this->createCookieJar();
@@ -60,12 +43,10 @@ public function createCookieJar(?SessionInterface $session = null): SessionCooki
6043
*/
6144
public function execute(array $servicesList, ?SessionCookieJar $cookieJar = null, ?Kernel $client = null): static
6245
{
63-
$httpClient = $client ? $client : $this->httpKernel;
46+
$client = $client ?: $this->httpKernel;
6447

65-
/*
66-
Fetch Cookie jar from session
67-
*/
68-
$cookieJar = $cookieJar ? $cookieJar : $this->getDefaultCookieJar();
48+
/** Fetch Cookie jar from session */
49+
$cookieJar = $cookieJar ?: $this->getDefaultCookieJar();
6950

7051
foreach ($servicesList as $service) {
7152
$sessionCookies = $cookieJar->allValues($service->getRequest()->getUri());
@@ -74,13 +55,10 @@ public function execute(array $servicesList, ?SessionCookieJar $cookieJar = null
7455
}
7556
}
7657

77-
$httpClient->execute($servicesList);
58+
$client->execute($servicesList);
7859

79-
/*
80-
Persist cookies
81-
*/
60+
/** Persist cookies */
8261
foreach ($servicesList as $service) {
83-
8462
if (!$service->getResponse()) {
8563
continue;
8664
}
@@ -246,6 +224,4 @@ public function DELETE($url, array $parameters = array()): mixed
246224
{
247225
return $this->fire('DELETE', $url, $parameters);
248226
}
249-
250-
251227
}

Twig/Extension.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,11 @@ public function __construct(protected LoaderInterface $loader)
1616
{
1717
}
1818

19-
/**
20-
* @return string
21-
*/
2219
public function getName(): string
2320
{
2421
return 'simple_http_extension';
2522
}
2623

27-
2824
public function getFilters(): array
2925
{
3026
$safe = array('is_safe' => array('html'));
@@ -41,7 +37,6 @@ public function getFilters(): array
4137
];
4238
}
4339

44-
4540
public function getFunctions(): array
4641
{
4742
$safe = array('is_safe' => array('html'));
@@ -60,11 +55,7 @@ public function numberFormat(int|float $number, int $decimals = 0): string
6055
return number_format($number, $decimals, $locale['decimal_point'], $locale['thousands_sep']);
6156
}
6257

63-
/**
64-
* @param $ms
65-
* @return string
66-
*/
67-
public function formatMilliseconds($ms): string
58+
public function formatMilliseconds(float|int $ms): string
6859
{
6960
if ($ms >= 1) {
7061
return $this->numberFormat($ms, 1) . ' s';

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"symfony/serializer": "^5.4 || ^6.0",
2222
"symfony/http-kernel": "^5.4 || ^6.0",
2323
"symfony/stopwatch": "^5.4 || ^6.0",
24+
"symfony/routing": "^5.4 || ^6.0",
2425
"symfony/config": "^5.4 || ^6.0",
2526
"symfony/dependency-injection": "^5.4 || ^6.0",
2627
"symfony/security-http": "^5.4 || ^6.0",

0 commit comments

Comments
 (0)