Skip to content

Commit d646991

Browse files
authored
Merge pull request #533 from FriendsOfSymfony/symfony-5
symfony 5 compatibility
2 parents cb8b530 + f8a1f72 commit d646991

32 files changed

+237
-98
lines changed

.styleci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ preset: symfony
33
enabled:
44
- alpha_ordered_imports
55
- short_array_syntax
6+
7+
disabled:
8+
- single_line_throw

.travis.yml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,15 @@ matrix:
2828
include:
2929
# Minimum supported dependencies with the latest and oldest PHP version
3030

31-
- php: 7.1
32-
env:
33-
- COMPOSER_FLAGS="--prefer-stable --prefer-lowest"
3431
- php: 7.2
3532
env:
36-
- COMPOSER_FLAGS="--prefer-stable --prefer-lowest"
33+
- COMPOSER_FLAGS="--prefer-stable --prefer-lowest" DEPENDENCIES="symfony/validator:^3.4.4 symfony/templating:^3.4.4"
34+
- php: 7.3
35+
env:
36+
- COMPOSER_FLAGS="--prefer-stable --prefer-lowest" DEPENDENCIES="symfony/validator:^3.4.4 symfony/templating:^3.4.4"
3737

3838
# Test the latest stable release
3939

40-
- php: 7.1
4140
- php: 7.2
4241
- php: 7.3
4342
env:
@@ -49,6 +48,9 @@ matrix:
4948
- php: 7.3
5049
env: DEPENDENCIES="symfony/lts:^3"
5150

51+
- php: 7.3
52+
env: DEPENDENCIES="symfony/flex" SYMFONY_VERSION="^4"
53+
5254
# Latest commit to master
5355
- php: 7.3
5456
env: STABILITY="dev"
@@ -60,7 +62,8 @@ matrix:
6062
before_install:
6163
- if [[ $COVERAGE != true ]]; then phpenv config-rm xdebug.ini || true; fi
6264
- if ! [ -z "$STABILITY" ]; then composer config minimum-stability ${STABILITY}; fi;
63-
- if ! [ -v "$DEPENDENCIES" ]; then composer require --no-update ${DEPENDENCIES}; fi;
65+
- if ! [ -z "$DEPENDENCIES" ]; then composer require --no-update ${DEPENDENCIES}; fi;
66+
- if ! [ -z "$SYMFONY_VERSION" ]; then composer config extra.symfony.require ${SYMFONY_VERSION}; fi;
6467

6568
install:
6669
# To be removed when this issue will be resolved: https://github.com/composer/composer/issues/5355

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
Changelog
22
=========
33

4+
2.8.0
5+
-----
6+
7+
### Fixed
8+
9+
* Adjusted to work with Twig 3
10+
* Adjusted to work with Symfony 5
11+
412
2.7.2
513
-----
614

composer.json

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,30 @@
2121
}
2222
],
2323
"require": {
24-
"php": "^7.1",
24+
"php": "^7.2",
2525
"friendsofsymfony/http-cache": "^2.5.2",
26-
"symfony/framework-bundle": "^3.4.4 || ^4.0",
27-
"symfony/http-foundation": "^3.4.4 || ^4.0",
28-
"symfony/http-kernel": "^3.4.4 || ^4.0"
26+
"symfony/framework-bundle": "^3.4.4 || ^4.1.12 || ^5.0",
27+
"symfony/http-foundation": "^3.4.4 || ^4.1.12 || ^5.0",
28+
"symfony/http-kernel": "^3.4.4 || ^4.1.12 || ^5.0"
2929
},
3030
"require-dev": {
3131
"php-http/guzzle6-adapter": "^1.0 || ^2.0",
3232
"php-http/message": "^1.0",
3333
"mockery/mockery": "^1.0",
3434
"monolog/monolog": "*",
35-
"sensio/framework-extra-bundle": "^3.0",
36-
"symfony/browser-kit": "^3.4.4 || ^4.0",
37-
"symfony/console": "^3.4.4 || ^4.0",
38-
"symfony/finder": "^3.4.4 || ^4.0",
39-
"symfony/phpunit-bridge": "^4.2.4",
40-
"symfony/security-bundle": "^3.4.4 || ^4.0",
41-
"symfony/twig-bundle": "^3.4.4 || ^4.0",
42-
"symfony/yaml": "^3.4.4 || ^4.0",
43-
"symfony/css-selector": "^3.4.4 || ^4.0",
44-
"symfony/expression-language": "^3.4.4 || ^4.0",
45-
"symfony/monolog-bundle": "^3.0",
46-
"symfony/routing": "^3.4.4 || ^4.0",
47-
"matthiasnoback/symfony-dependency-injection-test": "^2.3",
35+
"sensio/framework-extra-bundle": "^3.0 || ^4.0 || ^5.0",
36+
"symfony/browser-kit": "^3.4.4 || ^4.1.12 || ^5.0",
37+
"symfony/console": "^3.4.4 || ^4.1.12 || ^5.0",
38+
"symfony/finder": "^3.4.4 || ^4.1.12 || ^5.0",
39+
"symfony/phpunit-bridge": "^4.2.4 || ^5.0",
40+
"symfony/security-bundle": "^3.4.4 || ^4.1.12 || ^5.0",
41+
"symfony/twig-bundle": "^3.4.4 || ^4.1.12 || ^5.0",
42+
"symfony/yaml": "^3.4.4 || ^4.1.12 || ^5.0",
43+
"symfony/css-selector": "^3.4.4 || ^4.1.12 || ^5.0",
44+
"symfony/expression-language": "^3.4.4 || ^4.1.12 || ^5.0",
45+
"symfony/monolog-bundle": "^3.0 || ^4.1.12 || ^5.0",
46+
"symfony/routing": "^3.4.4 || ^4.1.12 || ^5.0",
47+
"matthiasnoback/symfony-dependency-injection-test": "^4.0",
4848
"sebastian/exporter": "^2.0"
4949
},
5050
"suggest": {
@@ -71,7 +71,7 @@
7171
},
7272
"extra": {
7373
"branch-alias": {
74-
"dev-master": "2.5.x-dev"
74+
"dev-master": "2.x-dev"
7575
}
7676
}
7777
}

src/Command/InvalidatePathCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,5 +80,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
8080

8181
$this->getCacheManager()->invalidatePath($path);
8282
}
83+
84+
return 0;
8385
}
8486
}

src/Command/InvalidateRegexCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,5 +77,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
7777
$regex = $input->getArgument('regex');
7878

7979
$this->getCacheManager()->invalidateRegex($regex);
80+
81+
return 0;
8082
}
8183
}

src/Command/InvalidateTagCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
7272
$tags = $input->getArgument('tags');
7373

7474
$this->getCacheManager()->invalidateTags($tags);
75+
76+
return 0;
7577
}
7678
}

src/Command/RefreshPathCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,5 +80,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
8080

8181
$this->getCacheManager()->refreshPath($path);
8282
}
83+
84+
return 0;
8385
}
8486
}

src/EventListener/CacheControlListener.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,16 @@
1616
use Symfony\Component\HttpFoundation\Request;
1717
use Symfony\Component\HttpFoundation\Response;
1818
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
19+
use Symfony\Component\HttpKernel\Event\ResponseEvent;
20+
use Symfony\Component\HttpKernel\Kernel;
1921
use Symfony\Component\HttpKernel\KernelEvents;
2022

23+
if (Kernel::MAJOR_VERSION >= 5) {
24+
class_alias(ResponseEvent::class, 'FOS\HttpCacheBundle\EventListener\CacheControlResponseEvent');
25+
} else {
26+
class_alias(FilterResponseEvent::class, 'FOS\HttpCacheBundle\EventListener\CacheControlResponseEvent');
27+
}
28+
2129
/**
2230
* Set caching settings on matching response according to the configurations.
2331
*
@@ -95,10 +103,8 @@ public function setSkip($skip = true)
95103

96104
/**
97105
* Apply the header rules if the request matches.
98-
*
99-
* @param FilterResponseEvent $event
100106
*/
101-
public function onKernelResponse(FilterResponseEvent $event)
107+
public function onKernelResponse(CacheControlResponseEvent $event)
102108
{
103109
$request = $event->getRequest();
104110
$response = $event->getResponse();

src/EventListener/FlashMessageListener.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,18 @@
1616
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
1717
use Symfony\Component\HttpFoundation\Session\Session;
1818
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
19+
use Symfony\Component\HttpKernel\Event\ResponseEvent;
1920
use Symfony\Component\HttpKernel\HttpKernel;
21+
use Symfony\Component\HttpKernel\Kernel;
2022
use Symfony\Component\HttpKernel\KernelEvents;
2123
use Symfony\Component\OptionsResolver\OptionsResolver;
2224

25+
if (Kernel::MAJOR_VERSION >= 5) {
26+
class_alias(ResponseEvent::class, 'FOS\HttpCacheBundle\EventListener\FlashMessageResponseEvent');
27+
} else {
28+
class_alias(FilterResponseEvent::class, 'FOS\HttpCacheBundle\EventListener\FlashMessageResponseEvent');
29+
}
30+
2331
/**
2432
* This event handler reads all flash messages and moves them into a cookie.
2533
*
@@ -66,10 +74,8 @@ public static function getSubscribedEvents()
6674

6775
/**
6876
* Moves flash messages from the session to a cookie inside a Response Kernel listener.
69-
*
70-
* @param FilterResponseEvent $event
7177
*/
72-
public function onKernelResponse(FilterResponseEvent $event)
78+
public function onKernelResponse(FlashMessageResponseEvent $event)
7379
{
7480
if (HttpKernel::MASTER_REQUEST !== $event->getRequestType()) {
7581
return;

src/EventListener/InvalidationListener.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,17 @@
2424
use Symfony\Component\HttpFoundation\Request;
2525
use Symfony\Component\HttpFoundation\Response;
2626
use Symfony\Component\HttpKernel\Event\PostResponseEvent;
27+
use Symfony\Component\HttpKernel\Event\TerminateEvent;
28+
use Symfony\Component\HttpKernel\Kernel;
2729
use Symfony\Component\HttpKernel\KernelEvents;
2830
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
2931

32+
if (Kernel::MAJOR_VERSION >= 5) {
33+
class_alias(TerminateEvent::class, 'FOS\HttpCacheBundle\EventListener\InvalidationTerminateEvent');
34+
} else {
35+
class_alias(PostResponseEvent::class, 'FOS\HttpCacheBundle\EventListener\InvalidationTerminateEvent');
36+
}
37+
3038
/**
3139
* On kernel.terminate event, this event handler invalidates routes for the
3240
* current request and flushes the CacheManager.
@@ -88,10 +96,8 @@ public function __construct(
8896
* their routes to the cache manager;
8997
* - flush the cache manager in order to send invalidation requests to the
9098
* HTTP cache.
91-
*
92-
* @param PostResponseEvent $event
9399
*/
94-
public function onKernelTerminate(PostResponseEvent $event)
100+
public function onKernelTerminate(InvalidationTerminateEvent $event)
95101
{
96102
$request = $event->getRequest();
97103
$response = $event->getResponse();

src/EventListener/SessionListener.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,18 @@
1515
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
1616
use Symfony\Component\HttpKernel\Event\FinishRequestEvent;
1717
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
18+
use Symfony\Component\HttpKernel\Event\RequestEvent;
19+
use Symfony\Component\HttpKernel\Event\ResponseEvent;
1820
use Symfony\Component\HttpKernel\EventListener\SessionListener as BaseSessionListener;
21+
use Symfony\Component\HttpKernel\Kernel;
22+
23+
if (Kernel::MAJOR_VERSION >= 5) {
24+
class_alias(RequestEvent::class, 'FOS\HttpCacheBundle\EventListener\SessionRequestEvent');
25+
class_alias(ResponseEvent::class, 'FOS\HttpCacheBundle\EventListener\SessionResponseEvent');
26+
} else {
27+
class_alias(GetResponseEvent::class, 'FOS\HttpCacheBundle\EventListener\SessionRequestEvent');
28+
class_alias(FilterResponseEvent::class, 'FOS\HttpCacheBundle\EventListener\SessionResponseEvent');
29+
}
1930

2031
/**
2132
* Decorates the default Symfony session listener.
@@ -60,12 +71,12 @@ public function __construct(BaseSessionListener $inner, string $userHashHeader,
6071
$this->userIdentifierHeaders = $userIdentifierHeaders;
6172
}
6273

63-
public function onKernelRequest(GetResponseEvent $event)
74+
public function onKernelRequest(SessionRequestEvent $event)
6475
{
6576
return $this->inner->onKernelRequest($event);
6677
}
6778

68-
public function onKernelResponse(FilterResponseEvent $event)
79+
public function onKernelResponse(SessionResponseEvent $event)
6980
{
7081
if (!$event->isMasterRequest()) {
7182
return;

src/EventListener/TagListener.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,17 @@
1919
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
2020
use Symfony\Component\HttpFoundation\Request;
2121
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
22+
use Symfony\Component\HttpKernel\Event\ResponseEvent;
2223
use Symfony\Component\HttpKernel\HttpKernelInterface;
24+
use Symfony\Component\HttpKernel\Kernel;
2325
use Symfony\Component\HttpKernel\KernelEvents;
2426

27+
if (Kernel::MAJOR_VERSION >= 5) {
28+
class_alias(ResponseEvent::class, 'FOS\HttpCacheBundle\EventListener\TagResponseEvent');
29+
} else {
30+
class_alias(FilterResponseEvent::class, 'FOS\HttpCacheBundle\EventListener\TagResponseEvent');
31+
}
32+
2533
/**
2634
* Event handler for the cache tagging tags.
2735
*
@@ -81,10 +89,8 @@ public function __construct(
8189
*
8290
* - For a safe (GET or HEAD) request, the tags are set on the response.
8391
* - For a non-safe request, the tags will be invalidated.
84-
*
85-
* @param FilterResponseEvent $event
8692
*/
87-
public function onKernelResponse(FilterResponseEvent $event)
93+
public function onKernelResponse(TagResponseEvent $event)
8894
{
8995
$request = $event->getRequest();
9096
$response = $event->getResponse();

src/EventListener/UserContextListener.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,22 @@
2020
use Symfony\Component\HttpFoundation\Response;
2121
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
2222
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
23+
use Symfony\Component\HttpKernel\Event\RequestEvent;
24+
use Symfony\Component\HttpKernel\Event\ResponseEvent;
2325
use Symfony\Component\HttpKernel\EventListener\AbstractSessionListener;
2426
use Symfony\Component\HttpKernel\HttpKernelInterface;
2527
use Symfony\Component\HttpKernel\Kernel;
2628
use Symfony\Component\HttpKernel\KernelEvents;
2729
use Symfony\Component\OptionsResolver\OptionsResolver;
2830

31+
if (Kernel::MAJOR_VERSION >= 5) {
32+
class_alias(RequestEvent::class, 'FOS\HttpCacheBundle\EventListener\UserContextRequestEvent');
33+
class_alias(ResponseEvent::class, 'FOS\HttpCacheBundle\EventListener\UserContextResponseEvent');
34+
} else {
35+
class_alias(GetResponseEvent::class, 'FOS\HttpCacheBundle\EventListener\UserContextRequestEvent');
36+
class_alias(FilterResponseEvent::class, 'FOS\HttpCacheBundle\EventListener\UserContextResponseEvent');
37+
}
38+
2939
/**
3040
* Check requests and responses with the matcher.
3141
*
@@ -119,10 +129,8 @@ public function __construct(
119129
* the generated hash.
120130
*
121131
* If the ttl is bigger than 0, cache headers will be set for this response.
122-
*
123-
* @param GetResponseEvent $event
124132
*/
125-
public function onKernelRequest(GetResponseEvent $event)
133+
public function onKernelRequest(UserContextRequestEvent $event)
126134
{
127135
if (HttpKernelInterface::MASTER_REQUEST != $event->getRequestType()) {
128136
return;
@@ -185,10 +193,8 @@ private function isAnonymous(Request $request)
185193
/**
186194
* Add the context hash header to the headers to vary on if the header was
187195
* present in the request.
188-
*
189-
* @param FilterResponseEvent $event
190196
*/
191-
public function onKernelResponse(FilterResponseEvent $event)
197+
public function onKernelResponse(UserContextResponseEvent $event)
192198
{
193199
if (HttpKernelInterface::MASTER_REQUEST != $event->getRequestType()) {
194200
return;

tests/Functional/Command/CommandTestCase.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,16 @@
1414
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
1515
use Symfony\Bundle\FrameworkBundle\Client;
1616
use Symfony\Bundle\FrameworkBundle\Console\Application;
17+
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
1718
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
1819
use Symfony\Component\Console\Input\StringInput;
1920
use Symfony\Component\Console\Output\OutputInterface;
2021
use Symfony\Component\Console\Output\StreamOutput;
2122

23+
if (!\class_exists(KernelBrowser::class)) {
24+
\class_alias(Client::class, KernelBrowser::class);
25+
}
26+
2227
abstract class CommandTestCase extends WebTestCase
2328
{
2429
use MockeryPHPUnitIntegration;
@@ -28,13 +33,9 @@ abstract class CommandTestCase extends WebTestCase
2833
*
2934
* The verbosity is always verbose because Symfony looks at the definition in the environment variables.
3035
*
31-
* @param Client $client
32-
* @param string $command
33-
* @param int $exitCode Expected command exit code
34-
*
35-
* @return string
36+
* @param int $exitCode Expected command exit code
3637
*/
37-
protected function runCommand(Client $client, $command, $exitCode = 0)
38+
protected function runCommand(KernelBrowser $client, $command, $exitCode = 0): string
3839
{
3940
$application = new Application($client->getKernel());
4041
$application->setAutoExit(false);

0 commit comments

Comments
 (0)