From 2edab6f03e24b685452b8d45d27c448499afee9c Mon Sep 17 00:00:00 2001 From: Matthias Pigulla Date: Thu, 28 Mar 2024 19:40:23 +0100 Subject: [PATCH] Fix a regression caused in #39 (#41) --- src/Caching/Attribute/Send304IfNotModified.php | 5 +++++ src/Caching/EventListener.php | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Caching/Attribute/Send304IfNotModified.php b/src/Caching/Attribute/Send304IfNotModified.php index 4c4c21e..2d7e960 100644 --- a/src/Caching/Attribute/Send304IfNotModified.php +++ b/src/Caching/Attribute/Send304IfNotModified.php @@ -10,6 +10,7 @@ use Attribute; use Exception; +use InvalidArgumentException; use Webfactory\Bundle\WfdMetaBundle\Helper\LastmodHelper; use Webfactory\Bundle\WfdMetaBundle\MetaQueryFactory; @@ -28,6 +29,10 @@ public function __construct(...$values) \E_USER_DEPRECATED ); + if (!$values) { + throw new InvalidArgumentException(sprintf('The %s attribute needs at least one criterion', __CLASS__)); + } + $this->lastmodHelper = new LastmodHelper(); foreach ($values as $key => $value) { diff --git a/src/Caching/EventListener.php b/src/Caching/EventListener.php index d06f907..1785642 100644 --- a/src/Caching/EventListener.php +++ b/src/Caching/EventListener.php @@ -109,7 +109,7 @@ protected function findAttribute($callback): ?Attribute\Send304IfNotModified $attributes = $method->getAttributes(\Webfactory\Bundle\WfdMetaBundle\Caching\Attribute\Send304IfNotModified::class); if ($attributes) { - return $attributes[0]; + return $attributes[0]->newInstance(); } }