Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

symfony 5 compatibility #533

Merged
merged 1 commit into from Nov 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .styleci.yml
Expand Up @@ -3,3 +3,6 @@ preset: symfony
enabled:
- alpha_ordered_imports
- short_array_syntax

disabled:
- single_line_throw
15 changes: 9 additions & 6 deletions .travis.yml
Expand Up @@ -28,16 +28,15 @@ matrix:
include:
# Minimum supported dependencies with the latest and oldest PHP version

- php: 7.1
env:
- COMPOSER_FLAGS="--prefer-stable --prefer-lowest"
- php: 7.2
env:
- COMPOSER_FLAGS="--prefer-stable --prefer-lowest"
- COMPOSER_FLAGS="--prefer-stable --prefer-lowest" DEPENDENCIES="symfony/validator:^3.4.4 symfony/templating:^3.4.4"
- php: 7.3
env:
- COMPOSER_FLAGS="--prefer-stable --prefer-lowest" DEPENDENCIES="symfony/validator:^3.4.4 symfony/templating:^3.4.4"

# Test the latest stable release

- php: 7.1
- php: 7.2
- php: 7.3
env:
Expand All @@ -49,6 +48,9 @@ matrix:
- php: 7.3
env: DEPENDENCIES="symfony/lts:^3"

- php: 7.3
env: DEPENDENCIES="symfony/flex" SYMFONY_VERSION="^4"

# Latest commit to master
- php: 7.3
env: STABILITY="dev"
Expand All @@ -60,7 +62,8 @@ matrix:
before_install:
- if [[ $COVERAGE != true ]]; then phpenv config-rm xdebug.ini || true; fi
- if ! [ -z "$STABILITY" ]; then composer config minimum-stability ${STABILITY}; fi;
- if ! [ -v "$DEPENDENCIES" ]; then composer require --no-update ${DEPENDENCIES}; fi;
- if ! [ -z "$DEPENDENCIES" ]; then composer require --no-update ${DEPENDENCIES}; fi;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good to me

- if ! [ -z "$SYMFONY_VERSION" ]; then composer config extra.symfony.require ${SYMFONY_VERSION}; fi;

install:
# To be removed when this issue will be resolved: https://github.com/composer/composer/issues/5355
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
@@ -1,6 +1,14 @@
Changelog
=========

2.8.0
-----

### Fixed

* Adjusted to work with Twig 3
* Adjusted to work with Symfony 5

2.7.2
-----

Expand Down
36 changes: 18 additions & 18 deletions composer.json
Expand Up @@ -21,30 +21,30 @@
}
],
"require": {
"php": "^7.1",
"php": "^7.2",
"friendsofsymfony/http-cache": "^2.5.2",
"symfony/framework-bundle": "^3.4.4 || ^4.0",
"symfony/http-foundation": "^3.4.4 || ^4.0",
"symfony/http-kernel": "^3.4.4 || ^4.0"
"symfony/framework-bundle": "^3.4.4 || ^4.1.12 || ^5.0",
"symfony/http-foundation": "^3.4.4 || ^4.1.12 || ^5.0",
"symfony/http-kernel": "^3.4.4 || ^4.1.12 || ^5.0"
},
"require-dev": {
"php-http/guzzle6-adapter": "^1.0 || ^2.0",
"php-http/message": "^1.0",
"mockery/mockery": "^1.0",
"monolog/monolog": "*",
"sensio/framework-extra-bundle": "^3.0",
"symfony/browser-kit": "^3.4.4 || ^4.0",
"symfony/console": "^3.4.4 || ^4.0",
"symfony/finder": "^3.4.4 || ^4.0",
"symfony/phpunit-bridge": "^4.2.4",
"symfony/security-bundle": "^3.4.4 || ^4.0",
"symfony/twig-bundle": "^3.4.4 || ^4.0",
"symfony/yaml": "^3.4.4 || ^4.0",
"symfony/css-selector": "^3.4.4 || ^4.0",
"symfony/expression-language": "^3.4.4 || ^4.0",
"symfony/monolog-bundle": "^3.0",
"symfony/routing": "^3.4.4 || ^4.0",
"matthiasnoback/symfony-dependency-injection-test": "^2.3",
"sensio/framework-extra-bundle": "^3.0 || ^4.0 || ^5.0",
"symfony/browser-kit": "^3.4.4 || ^4.1.12 || ^5.0",
"symfony/console": "^3.4.4 || ^4.1.12 || ^5.0",
"symfony/finder": "^3.4.4 || ^4.1.12 || ^5.0",
"symfony/phpunit-bridge": "^4.2.4 || ^5.0",
"symfony/security-bundle": "^3.4.4 || ^4.1.12 || ^5.0",
"symfony/twig-bundle": "^3.4.4 || ^4.1.12 || ^5.0",
"symfony/yaml": "^3.4.4 || ^4.1.12 || ^5.0",
"symfony/css-selector": "^3.4.4 || ^4.1.12 || ^5.0",
"symfony/expression-language": "^3.4.4 || ^4.1.12 || ^5.0",
"symfony/monolog-bundle": "^3.0 || ^4.1.12 || ^5.0",
"symfony/routing": "^3.4.4 || ^4.1.12 || ^5.0",
"matthiasnoback/symfony-dependency-injection-test": "^4.0",
"sebastian/exporter": "^2.0"
},
"suggest": {
Expand All @@ -71,7 +71,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "2.5.x-dev"
"dev-master": "2.x-dev"
}
}
}
2 changes: 2 additions & 0 deletions src/Command/InvalidatePathCommand.php
Expand Up @@ -80,5 +80,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

$this->getCacheManager()->invalidatePath($path);
}

return 0;
}
}
2 changes: 2 additions & 0 deletions src/Command/InvalidateRegexCommand.php
Expand Up @@ -77,5 +77,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$regex = $input->getArgument('regex');

$this->getCacheManager()->invalidateRegex($regex);

return 0;
}
}
2 changes: 2 additions & 0 deletions src/Command/InvalidateTagCommand.php
Expand Up @@ -72,5 +72,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$tags = $input->getArgument('tags');

$this->getCacheManager()->invalidateTags($tags);

return 0;
}
}
2 changes: 2 additions & 0 deletions src/Command/RefreshPathCommand.php
Expand Up @@ -80,5 +80,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

$this->getCacheManager()->refreshPath($path);
}

return 0;
}
}
12 changes: 9 additions & 3 deletions src/EventListener/CacheControlListener.php
Expand Up @@ -16,8 +16,16 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\HttpKernel\KernelEvents;

if (Kernel::MAJOR_VERSION >= 5) {
class_alias(ResponseEvent::class, 'FOS\HttpCacheBundle\EventListener\CacheControlResponseEvent');
} else {
class_alias(FilterResponseEvent::class, 'FOS\HttpCacheBundle\EventListener\CacheControlResponseEvent');
}

/**
* Set caching settings on matching response according to the configurations.
*
Expand Down Expand Up @@ -95,10 +103,8 @@ public function setSkip($skip = true)

/**
* Apply the header rules if the request matches.
*
* @param FilterResponseEvent $event
*/
public function onKernelResponse(FilterResponseEvent $event)
public function onKernelResponse(CacheControlResponseEvent $event)
{
$request = $event->getRequest();
$response = $event->getResponse();
Expand Down
12 changes: 9 additions & 3 deletions src/EventListener/FlashMessageListener.php
Expand Up @@ -16,10 +16,18 @@
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\HttpKernel\HttpKernel;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\OptionsResolver\OptionsResolver;

if (Kernel::MAJOR_VERSION >= 5) {
class_alias(ResponseEvent::class, 'FOS\HttpCacheBundle\EventListener\FlashMessageResponseEvent');
} else {
class_alias(FilterResponseEvent::class, 'FOS\HttpCacheBundle\EventListener\FlashMessageResponseEvent');
}

/**
* This event handler reads all flash messages and moves them into a cookie.
*
Expand Down Expand Up @@ -66,10 +74,8 @@ public static function getSubscribedEvents()

/**
* Moves flash messages from the session to a cookie inside a Response Kernel listener.
*
* @param FilterResponseEvent $event
*/
public function onKernelResponse(FilterResponseEvent $event)
public function onKernelResponse(FlashMessageResponseEvent $event)
{
if (HttpKernel::MASTER_REQUEST !== $event->getRequestType()) {
return;
Expand Down
12 changes: 9 additions & 3 deletions src/EventListener/InvalidationListener.php
Expand Up @@ -24,9 +24,17 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\PostResponseEvent;
use Symfony\Component\HttpKernel\Event\TerminateEvent;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;

if (Kernel::MAJOR_VERSION >= 5) {
class_alias(TerminateEvent::class, 'FOS\HttpCacheBundle\EventListener\InvalidationTerminateEvent');
} else {
class_alias(PostResponseEvent::class, 'FOS\HttpCacheBundle\EventListener\InvalidationTerminateEvent');
}

/**
* On kernel.terminate event, this event handler invalidates routes for the
* current request and flushes the CacheManager.
Expand Down Expand Up @@ -88,10 +96,8 @@ public function __construct(
* their routes to the cache manager;
* - flush the cache manager in order to send invalidation requests to the
* HTTP cache.
*
* @param PostResponseEvent $event
*/
public function onKernelTerminate(PostResponseEvent $event)
public function onKernelTerminate(InvalidationTerminateEvent $event)
{
$request = $event->getRequest();
$response = $event->getResponse();
Expand Down
15 changes: 13 additions & 2 deletions src/EventListener/SessionListener.php
Expand Up @@ -15,7 +15,18 @@
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\Event\FinishRequestEvent;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\HttpKernel\EventListener\SessionListener as BaseSessionListener;
use Symfony\Component\HttpKernel\Kernel;

if (Kernel::MAJOR_VERSION >= 5) {
class_alias(RequestEvent::class, 'FOS\HttpCacheBundle\EventListener\SessionRequestEvent');
class_alias(ResponseEvent::class, 'FOS\HttpCacheBundle\EventListener\SessionResponseEvent');
} else {
class_alias(GetResponseEvent::class, 'FOS\HttpCacheBundle\EventListener\SessionRequestEvent');
class_alias(FilterResponseEvent::class, 'FOS\HttpCacheBundle\EventListener\SessionResponseEvent');
}

/**
* Decorates the default Symfony session listener.
Expand Down Expand Up @@ -60,12 +71,12 @@ public function __construct(BaseSessionListener $inner, string $userHashHeader,
$this->userIdentifierHeaders = $userIdentifierHeaders;
}

public function onKernelRequest(GetResponseEvent $event)
public function onKernelRequest(SessionRequestEvent $event)
{
return $this->inner->onKernelRequest($event);
}

public function onKernelResponse(FilterResponseEvent $event)
public function onKernelResponse(SessionResponseEvent $event)
{
if (!$event->isMasterRequest()) {
return;
Expand Down
12 changes: 9 additions & 3 deletions src/EventListener/TagListener.php
Expand Up @@ -19,9 +19,17 @@
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\HttpKernel\KernelEvents;

if (Kernel::MAJOR_VERSION >= 5) {
class_alias(ResponseEvent::class, 'FOS\HttpCacheBundle\EventListener\TagResponseEvent');
} else {
class_alias(FilterResponseEvent::class, 'FOS\HttpCacheBundle\EventListener\TagResponseEvent');
}

/**
* Event handler for the cache tagging tags.
*
Expand Down Expand Up @@ -81,10 +89,8 @@ public function __construct(
*
* - For a safe (GET or HEAD) request, the tags are set on the response.
* - For a non-safe request, the tags will be invalidated.
*
* @param FilterResponseEvent $event
*/
public function onKernelResponse(FilterResponseEvent $event)
public function onKernelResponse(TagResponseEvent $event)
{
$request = $event->getRequest();
$response = $event->getResponse();
Expand Down
18 changes: 12 additions & 6 deletions src/EventListener/UserContextListener.php
Expand Up @@ -20,12 +20,22 @@
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\HttpKernel\EventListener\AbstractSessionListener;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\OptionsResolver\OptionsResolver;

if (Kernel::MAJOR_VERSION >= 5) {
class_alias(RequestEvent::class, 'FOS\HttpCacheBundle\EventListener\UserContextRequestEvent');
class_alias(ResponseEvent::class, 'FOS\HttpCacheBundle\EventListener\UserContextResponseEvent');
} else {
class_alias(GetResponseEvent::class, 'FOS\HttpCacheBundle\EventListener\UserContextRequestEvent');
class_alias(FilterResponseEvent::class, 'FOS\HttpCacheBundle\EventListener\UserContextResponseEvent');
}

/**
* Check requests and responses with the matcher.
*
Expand Down Expand Up @@ -119,10 +129,8 @@ public function __construct(
* the generated hash.
*
* If the ttl is bigger than 0, cache headers will be set for this response.
*
* @param GetResponseEvent $event
*/
public function onKernelRequest(GetResponseEvent $event)
public function onKernelRequest(UserContextRequestEvent $event)
{
if (HttpKernelInterface::MASTER_REQUEST != $event->getRequestType()) {
return;
Expand Down Expand Up @@ -185,10 +193,8 @@ private function isAnonymous(Request $request)
/**
* Add the context hash header to the headers to vary on if the header was
* present in the request.
*
* @param FilterResponseEvent $event
*/
public function onKernelResponse(FilterResponseEvent $event)
public function onKernelResponse(UserContextResponseEvent $event)
{
if (HttpKernelInterface::MASTER_REQUEST != $event->getRequestType()) {
return;
Expand Down
13 changes: 7 additions & 6 deletions tests/Functional/Command/CommandTestCase.php
Expand Up @@ -14,11 +14,16 @@
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
use Symfony\Bundle\FrameworkBundle\Client;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\Console\Input\StringInput;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Output\StreamOutput;

if (!\class_exists(KernelBrowser::class)) {
\class_alias(Client::class, KernelBrowser::class);
}

abstract class CommandTestCase extends WebTestCase
{
use MockeryPHPUnitIntegration;
Expand All @@ -28,13 +33,9 @@ abstract class CommandTestCase extends WebTestCase
*
* The verbosity is always verbose because Symfony looks at the definition in the environment variables.
*
* @param Client $client
* @param string $command
* @param int $exitCode Expected command exit code
*
* @return string
* @param int $exitCode Expected command exit code
*/
protected function runCommand(Client $client, $command, $exitCode = 0)
protected function runCommand(KernelBrowser $client, $command, $exitCode = 0): string
{
$application = new Application($client->getKernel());
$application->setAutoExit(false);
Expand Down