diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml new file mode 100644 index 00000000..8de22235 --- /dev/null +++ b/.github/workflows/static.yml @@ -0,0 +1,39 @@ +name: Static analysis + +on: + push: + branches: + - "*.x" + pull_request: + +jobs: + phpstan-src: + name: PHPStan src + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Pull in optional dependencies + run: composer require --no-update jean-beru/fos-http-cache-cloudfront twig/twig symfony/console + + - name: PHPStan + uses: docker://oskarstark/phpstan-ga + with: + args: analyze --no-progress + + phpstan-tests: + name: PHPStan tests + runs-on: ubuntu-latest + env: + REQUIRE_DEV: "true" + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: PHPStan + uses: docker://oskarstark/phpstan-ga + with: + args: analyze --no-progress -c phpstan.tests.neon.dist diff --git a/composer.json b/composer.json index 50e84540..51e837b8 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,14 @@ "name": "friendsofsymfony/http-cache-bundle", "type": "symfony-bundle", "description": "Set path based HTTP cache headers and send invalidation requests to your HTTP cache", - "keywords": [ "http", "caching", "purge", "invalidation", "varnish", "esi" ], + "keywords": [ + "http", + "caching", + "purge", + "invalidation", + "varnish", + "esi" + ], "homepage": "https://github.com/FriendsOfSymfony/FOSHttpCacheBundle", "license": "MIT", "authors": [ @@ -23,9 +30,11 @@ "require": { "php": "^8.1", "friendsofsymfony/http-cache": "^2.15 || 3.x-dev", + "symfony/expression-language": "^6.4 || ^7.0", "symfony/framework-bundle": "^6.4 || ^7.0", "symfony/http-foundation": "^6.4 || ^7.0", - "symfony/http-kernel": "^6.4 || ^7.0" + "symfony/http-kernel": "^6.4 || ^7.0", + "symfony/security-bundle": "^6.4 || ^7.0" }, "require-dev": { "php-http/guzzle7-adapter": "^0.1.1", @@ -39,16 +48,18 @@ "symfony/console": "^6.4 || ^7.0", "symfony/finder": "^6.4 || ^7.0", "phpunit/phpunit": "^10.5", - "symfony/security-bundle": "^6.4 || ^7.0", "symfony/twig-bundle": "^6.4 || ^7.0", "twig/twig": "^v3.8", "symfony/yaml": "^6.4 || ^7.0", "symfony/css-selector": "^6.4 || ^7.0", - "symfony/expression-language": "^6.4 || ^7.0", "symfony/monolog-bundle": "^3.0", "symfony/routing": "^6.4 || ^7.0", "matthiasnoback/symfony-config-test": "^4.3.0 || ^5.1", - "matthiasnoback/symfony-dependency-injection-test": "^4.3.1 || ^5.0" + "matthiasnoback/symfony-dependency-injection-test": "^4.3.1 || ^5.0", + "phpstan/phpstan": "^1.10", + "phpstan/phpstan-symfony": "^1.3", + "phpstan/extension-installer": "^1.3", + "jean-beru/fos-http-cache-cloudfront": "^1.1" }, "suggest": { "jean-beru/fos-http-cache-cloudfront": "To use CloudFront proxy", @@ -75,7 +86,8 @@ }, "config": { "allow-plugins": { - "php-http/discovery": true + "php-http/discovery": true, + "phpstan/extension-installer": true } } -} +} \ No newline at end of file diff --git a/phpstan.neon.dist b/phpstan.neon.dist new file mode 100644 index 00000000..672e0fa1 --- /dev/null +++ b/phpstan.neon.dist @@ -0,0 +1,4 @@ +parameters: + level: 1 + paths: + - src \ No newline at end of file diff --git a/phpstan.tests.neon.dist b/phpstan.tests.neon.dist new file mode 100644 index 00000000..a4edab22 --- /dev/null +++ b/phpstan.tests.neon.dist @@ -0,0 +1,6 @@ +parameters: + level: 1 + paths: + - tests + excludePaths: + - 'tests/Resources/Fixtures/config' \ No newline at end of file diff --git a/src/EventListener/FlashMessageListener.php b/src/EventListener/FlashMessageListener.php index 1da25e0f..62a9b104 100644 --- a/src/EventListener/FlashMessageListener.php +++ b/src/EventListener/FlashMessageListener.php @@ -19,8 +19,6 @@ use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\OptionsResolver\OptionsResolver; -class_alias(ResponseEvent::class, 'FOS\HttpCacheBundle\EventListener\FlashMessageResponseEvent'); - /** * This event handler reads all flash messages and moves them into a cookie. * @@ -54,7 +52,7 @@ public static function getSubscribedEvents(): array /** * Moves flash messages from the session to a cookie inside a Response Kernel listener. */ - public function onKernelResponse(FlashMessageResponseEvent $event): void + public function onKernelResponse(ResponseEvent $event): void { try { $session = $event->getRequest()->getSession(); diff --git a/src/Security/Http/Logout/ContextInvalidationSessionLogoutHandler.php b/src/Security/Http/Logout/ContextInvalidationSessionLogoutHandler.php index 5955f955..c77a42fa 100644 --- a/src/Security/Http/Logout/ContextInvalidationSessionLogoutHandler.php +++ b/src/Security/Http/Logout/ContextInvalidationSessionLogoutHandler.php @@ -12,10 +12,10 @@ namespace FOS\HttpCacheBundle\Security\Http\Logout; use FOS\HttpCacheBundle\UserContextInvalidator; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\Security\Http\Event\LogoutEvent; -use Symfony\Component\Security\Http\EventListener\SessionLogoutListener; -final class ContextInvalidationSessionLogoutHandler extends SessionLogoutListener +final class ContextInvalidationSessionLogoutHandler implements EventSubscriberInterface { private UserContextInvalidator $invalidator; @@ -28,8 +28,14 @@ public function onLogout(LogoutEvent $event): void { if ($event->getRequest()->hasSession()) { $this->invalidator->invalidateContext($event->getRequest()->getSession()->getId()); + $event->getRequest()->getSession()->invalidate(); } + } - parent::onLogout($event); + public static function getSubscribedEvents(): array + { + return [ + LogoutEvent::class => 'onLogout', + ]; } } diff --git a/tests/Functional/SessionHelperTrait.php b/tests/Functional/SessionHelperTrait.php index a274ad5c..f460fd29 100644 --- a/tests/Functional/SessionHelperTrait.php +++ b/tests/Functional/SessionHelperTrait.php @@ -12,7 +12,6 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Event\RequestEvent; -use Symfony\Component\HttpKernel\Kernel; use Symfony\Component\HttpKernel\KernelEvents; /** @@ -22,12 +21,9 @@ trait SessionHelperTrait { private function callInRequestContext(KernelBrowser $client, callable $callable) { - $container = method_exists($this, 'getContainer') ? self::getContainer() : (property_exists($this, 'container') ? self::$container : $client->getContainer()); /** @var EventDispatcherInterface $eventDispatcher */ - $eventDispatcher = Kernel::MAJOR_VERSION < 5 - ? $container->get(EventDispatcherInterface::class) - : self::$kernel->getContainer()->get('test.service_container')->get(EventDispatcherInterface::class) - ; + $eventDispatcher = self::$kernel->getContainer()->get('test.service_container')->get(EventDispatcherInterface::class); + $wrappedCallable = function (RequestEvent $event) use (&$callable) { try { $callable($event);