Skip to content

Commit 188ea5a

Browse files
authored
Merge pull request #573 from FriendsOfSymfony/sf6
Sf6
2 parents 2ac2b93 + 1939c04 commit 188ea5a

36 files changed

+413
-144
lines changed

.github/workflows/php.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,19 @@ jobs:
2020
- php-version: '7.3'
2121
- php-version: '7.4'
2222
- php-version: '8.0'
23+
- php-version: '7.4'
24+
symfony-version: '4.*'
25+
- php-version: '7.4'
26+
symfony-version: '5.*'
2327
- php-version: '8.0'
24-
symfony-version: '^4'
25-
- php-version: '8.0'
26-
symfony-version: '^5'
28+
symfony-version: '6.*'
2729
# Minimum supported dependencies with the oldest PHP version
2830
- php-version: '7.3'
2931
composer-flag: '--prefer-stable --prefer-lowest'
3032
symfony-version: '4.4'
3133
# Test latest unreleased versions
3234
- php-version: '8.0'
33-
symfony-version: '^5'
35+
symfony-version: '6.*'
3436
stability: 'dev'
3537
name: PHP ${{ matrix.php-version }} Test on Symfony ${{ matrix.symfony-version }} ${{ matrix.dependencies}} ${{ matrix.stability }} ${{ matrix.composer-flag }}
3638
steps:

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
Changelog
22
=========
33

4-
unreleased
5-
----------
4+
(unreleased)
5+
------------
66

7+
* Support Symfony 6
78
* Drop support for Symfony 3 and 4.3 (keep using 2.11.* for legacy projects).
89

910
2.11.2

composer.json

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
"require": {
2424
"php": "^7.3 || ^8.0",
2525
"friendsofsymfony/http-cache": "^2.6",
26-
"symfony/framework-bundle": "^4.4.0 || ^5.0",
27-
"symfony/http-foundation": "^4.4.0 || ^5.0",
28-
"symfony/http-kernel": "^4.4.0 || ^5.0"
26+
"symfony/framework-bundle": "^4.4.0 || ^5.0 || ^6.0",
27+
"symfony/http-foundation": "^4.4.0 || ^5.0 || ^6.0",
28+
"symfony/http-kernel": "^4.4.0 || ^5.0 || ^6.0"
2929
},
3030
"require-dev": {
3131
"php-http/guzzle7-adapter": "^0.1.1",
@@ -35,20 +35,20 @@
3535
"guzzlehttp/guzzle": "^7.2",
3636
"mockery/mockery": "^1.3.2",
3737
"monolog/monolog": "*",
38-
"sensio/framework-extra-bundle": "^4.0 || ^5.5.1",
38+
"sensio/framework-extra-bundle": "^4.0 || ^5.5.1 || ^6.0",
3939
"doctrine/annotations": "^1.11",
40-
"symfony/browser-kit": "^4.4 || ^5.0",
41-
"symfony/console": "^4.4 || ^5.0",
42-
"symfony/finder": "^4.4 || ^5.0",
40+
"symfony/browser-kit": "^4.4 || ^5.0 || ^6.0",
41+
"symfony/console": "^4.4 || ^5.0 || ^6.0",
42+
"symfony/finder": "^4.4 || ^5.0 || ^6.0",
4343
"symfony/phpunit-bridge": "v5.3.7",
44-
"symfony/security-bundle": "^4.4 || ^5.0",
45-
"symfony/twig-bundle": "^4.4 || ^5.0",
44+
"symfony/security-bundle": "^4.4 || ^5.0 || ^6.0",
45+
"symfony/twig-bundle": "^4.4 || ^5.0 || ^6.0",
4646
"twig/twig": "^2.13",
47-
"symfony/yaml": "^4.4 || ^5.0",
48-
"symfony/css-selector": "^4.4 || ^5.0",
49-
"symfony/expression-language": "^4.4 || ^5.0",
47+
"symfony/yaml": "^4.4 || ^5.0 || ^6.0",
48+
"symfony/css-selector": "^4.4 || ^5.0 || ^6.0",
49+
"symfony/expression-language": "^4.4 || ^5.0 || ^6.0",
5050
"symfony/monolog-bundle": "^3.0",
51-
"symfony/routing": "^4.4 || ^5.0",
51+
"symfony/routing": "^4.4 || ^5.0 || ^6.0",
5252
"matthiasnoback/symfony-dependency-injection-test": "^4.0",
5353
"sebastian/exporter": "^2.0"
5454
},

src/DependencyInjection/FOSHttpCacheExtension.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
2727
use Symfony\Component\DependencyInjection\Reference;
2828
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
29+
use Symfony\Component\HttpKernel\Kernel;
2930
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
3031

3132
/**
@@ -280,6 +281,12 @@ private function loadUserContext(ContainerBuilder $container, XmlFileLoader $loa
280281
}
281282

282283
$loader->load('user_context.xml');
284+
// TODO: Remove this service file when going to version 3 of the bundle
285+
if (Kernel::MAJOR_VERSION >= 6) {
286+
$loader->load('user_context_legacy_sf6.xml');
287+
} else {
288+
$loader->load('user_context_legacy.xml');
289+
}
283290

284291
$container->getDefinition('fos_http_cache.user_context.request_matcher')
285292
->replaceArgument(0, $config['match']['accept'])

src/EventListener/FlashMessageListener.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use Symfony\Component\HttpFoundation\Session\Session;
1818
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
1919
use Symfony\Component\HttpKernel\Event\ResponseEvent;
20-
use Symfony\Component\HttpKernel\HttpKernel;
2120
use Symfony\Component\HttpKernel\Kernel;
2221
use Symfony\Component\HttpKernel\KernelEvents;
2322
use Symfony\Component\OptionsResolver\OptionsResolver;
@@ -41,12 +40,14 @@ final class FlashMessageListener implements EventSubscriberInterface
4140
private $options;
4241

4342
/**
44-
* @var Session
43+
* For legacy support. If not set, we take the session from the request on the event.
44+
*
45+
* @var Session|null
4546
*/
4647
private $session;
4748

4849
/**
49-
* @param Session $session A session instance
50+
* @param Session|null $session
5051
*/
5152
public function __construct($session, array $options = [])
5253
{
@@ -76,18 +77,24 @@ public static function getSubscribedEvents()
7677
*/
7778
public function onKernelResponse(FlashMessageResponseEvent $event)
7879
{
79-
if (HttpKernel::MASTER_REQUEST !== $event->getRequestType()) {
80+
// BC for symfony < 5.3
81+
if (method_exists($event, 'isMainRequest') ? !$event->isMainRequest() : !$event->isMasterRequest()) {
82+
return;
83+
}
84+
85+
$session = $this->session ?: $event->getRequest()->getSession();
86+
if (null === $session) {
8087
return;
8188
}
8289

8390
// Flash messages are stored in the session. If there is none, there
8491
// can't be any flash messages in it. $session->getFlashBag() would
8592
// create a session, we need to avoid that.
86-
if (!$this->session->isStarted()) {
93+
if (!$session->isStarted()) {
8794
return;
8895
}
8996

90-
$flashBag = $this->session->getFlashBag();
97+
$flashBag = $session->getFlashBag();
9198
$flashes = $flashBag->all();
9299

93100
if (empty($flashes)) {

src/EventListener/TagListener.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
use Symfony\Component\HttpFoundation\Request;
2121
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
2222
use Symfony\Component\HttpKernel\Event\ResponseEvent;
23-
use Symfony\Component\HttpKernel\HttpKernelInterface;
2423
use Symfony\Component\HttpKernel\Kernel;
2524
use Symfony\Component\HttpKernel\KernelEvents;
2625

@@ -110,7 +109,8 @@ public function onKernelResponse(TagResponseEvent $event)
110109
if ($this->cacheableRule->matches($request, $response)) {
111110
// For safe requests (GET and HEAD), set cache tags on response
112111
$this->symfonyResponseTagger->addTags($tags);
113-
if (HttpKernelInterface::MASTER_REQUEST === $event->getRequestType()) {
112+
// BC for symfony < 5.3
113+
if (method_exists($event, 'isMainRequest') ? $event->isMainRequest() : $event->isMasterRequest()) {
114114
$this->symfonyResponseTagger->tagSymfonyResponse($response);
115115
}
116116
} elseif (count($tags)

src/EventListener/UserContextListener.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ public function __construct(
132132
*/
133133
public function onKernelRequest(UserContextRequestEvent $event)
134134
{
135-
if (HttpKernelInterface::MASTER_REQUEST != $event->getRequestType()) {
135+
// BC for symfony < 5.3
136+
if (method_exists($event, 'isMainRequest') ? !$event->isMainRequest() : !$event->isMasterRequest()) {
136137
return;
137138
}
138139

src/Http/RequestMatcher/CacheableRequestMatcher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*/
2020
class CacheableRequestMatcher implements RequestMatcherInterface
2121
{
22-
public function matches(Request $request)
22+
public function matches(Request $request): bool
2323
{
2424
return $request->isMethodCacheable();
2525
}

src/Http/RequestMatcher/QuerystringRequestMatcher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function setQueryString($queryString)
3535
/**
3636
* {@inheritdoc}
3737
*/
38-
public function matches(Request $request)
38+
public function matches(Request $request): bool
3939
{
4040
if (!parent::matches($request)) {
4141
return false;

src/Http/RequestMatcher/UnsafeRequestMatcher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
class UnsafeRequestMatcher implements RequestMatcherInterface
1818
{
19-
public function matches(Request $request)
19+
public function matches(Request $request): bool
2020
{
2121
return !$request->isMethodSafe();
2222
}

0 commit comments

Comments
 (0)