diff --git a/.gitignore b/.gitignore
index ac8a491..c5d79fa 100644
--- a/.gitignore
+++ b/.gitignore
@@ -29,3 +29,5 @@ Tests/Application/.env.*.local
package-lock.json
node_modules/
build/
+
+.php-version
diff --git a/Controller/SnippetAreaController.php b/Controller/SnippetAreaController.php
index 25b39ba..79ee7da 100644
--- a/Controller/SnippetAreaController.php
+++ b/Controller/SnippetAreaController.php
@@ -53,7 +53,7 @@ class SnippetAreaController
private $serializer;
/**
- * @var ReferenceStoreInterface
+ * @var ReferenceStoreInterface|null
*/
private $snippetAreaReferenceStore;
@@ -77,7 +77,7 @@ public function __construct(
ContentMapperInterface $contentMapper,
StructureResolverInterface $structureResolver,
SerializerInterface $serializer,
- ReferenceStoreInterface $snippetReferenceStore,
+ ?ReferenceStoreInterface $snippetReferenceStore,
int $maxAge,
int $sharedMaxAge,
int $cacheLifetime
@@ -126,7 +126,9 @@ public function getAction(Request $request, string $area): Response
throw new NotFoundHttpException(\sprintf('Snippet for snippet area "%s" does not exist in locale "%s"', $area, $locale));
}
- $this->snippetAreaReferenceStore->add($area);
+ if ($this->snippetAreaReferenceStore) {
+ $this->snippetAreaReferenceStore->add($area);
+ }
$resolvedSnippet = $this->structureResolver->resolve(
$snippet,
diff --git a/EventSubscriber/SnippetAreaInvalidationSubscriber.php b/EventSubscriber/SnippetAreaInvalidationSubscriber.php
deleted file mode 100644
index 05eb925..0000000
--- a/EventSubscriber/SnippetAreaInvalidationSubscriber.php
+++ /dev/null
@@ -1,64 +0,0 @@
-cacheManager = $cacheManager;
- }
-
- public static function getSubscribedEvents()
- {
- return [
- WebspaceDefaultSnippetModifiedEvent::class => 'invalidateSnippetAreaOnModified',
- WebspaceDefaultSnippetRemovedEvent::class => 'invalidateSnippetAreaOnRemoved',
- ];
- }
-
- public function invalidateSnippetAreaOnModified(WebspaceDefaultSnippetModifiedEvent $event): void
- {
- $this->invalidateSnippetArea($event->getSnippetAreaKey());
- }
-
- public function invalidateSnippetAreaOnRemoved(WebspaceDefaultSnippetRemovedEvent $event): void
- {
- $this->invalidateSnippetArea($event->getSnippetAreaKey());
- }
-
- private function invalidateSnippetArea(string $snippetAreaKey): void
- {
- if (!$this->cacheManager) {
- return;
- }
-
- $this->cacheManager->invalidateReference('snippet_area', $snippetAreaKey);
- }
-}
diff --git a/Resources/config/controllers.xml b/Resources/config/controllers.xml
index 7aa850f..404882d 100644
--- a/Resources/config/controllers.xml
+++ b/Resources/config/controllers.xml
@@ -28,7 +28,7 @@
-
+
%sulu_http_cache.cache.max_age%
%sulu_http_cache.cache.shared_max_age%
%sulu_headless.snippet_area.cache_lifetime%
diff --git a/Resources/config/event-subscribers.xml b/Resources/config/event-subscribers.xml
index 01a04ad..48114d1 100644
--- a/Resources/config/event-subscribers.xml
+++ b/Resources/config/event-subscribers.xml
@@ -13,11 +13,5 @@
-
-
-
-
-
-
diff --git a/Resources/config/services.xml b/Resources/config/services.xml
index 5bf7ada..bdde3b0 100644
--- a/Resources/config/services.xml
+++ b/Resources/config/services.xml
@@ -39,11 +39,5 @@
-
-
-
-
-
diff --git a/Tests/Application/.env b/Tests/Application/.env
index cc879ad..608fa78 100644
--- a/Tests/Application/.env
+++ b/Tests/Application/.env
@@ -1,2 +1,2 @@
APP_ENV=test
-DATABASE_URL=mysql://root@127.0.0.1:3306/su_headless_test
+DATABASE_URL=mysql://root:root@127.0.0.1:3306/su_headless_test
diff --git a/Tests/Functional/Controller/SnippetAreaControllerTest.php b/Tests/Functional/Controller/SnippetAreaControllerTest.php
index 125239c..c4ce70f 100644
--- a/Tests/Functional/Controller/SnippetAreaControllerTest.php
+++ b/Tests/Functional/Controller/SnippetAreaControllerTest.php
@@ -15,7 +15,9 @@
use Sulu\Bundle\HeadlessBundle\Tests\Functional\BaseTestCase;
use Sulu\Bundle\HeadlessBundle\Tests\Traits\CreateSnippetTrait;
+use Sulu\Bundle\WebsiteBundle\ReferenceStore\ReferenceStoreInterface;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
+use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Response;
class SnippetAreaControllerTest extends BaseTestCase
@@ -27,6 +29,11 @@ class SnippetAreaControllerTest extends BaseTestCase
*/
private $websiteClient;
+ /**
+ * @var ReferenceStoreInterface|null
+ */
+ private $snippetAreaReferenceStore;
+
public static function setUpBeforeClass(): void
{
self::initPhpcr();
@@ -62,6 +69,10 @@ public static function setUpBeforeClass(): void
protected function setUp(): void
{
$this->websiteClient = $this->createWebsiteClient();
+
+ /** @var ReferenceStoreInterface|null $snippetAreaReferenceStore */
+ $snippetAreaReferenceStore = self::getContainer()->get('sulu_snippet.reference_store.snippet_area', ContainerInterface::NULL_ON_INVALID_REFERENCE);
+ $this->snippetAreaReferenceStore = $snippetAreaReferenceStore;
}
/**
@@ -125,7 +136,10 @@ public function testGetAction(
if (200 === $response->getStatusCode()) {
$this->assertStringContainsString('public', (string) $response->headers->get('Cache-Control'));
- $this->assertStringContainsString('snippet_area-default', (string) $response->headers->get('x-cache-tags'));
+
+ if ($this->snippetAreaReferenceStore) {
+ $this->assertStringContainsString('snippet_area-default', (string) $response->headers->get('x-cache-tags'));
+ }
}
if (null !== $expectedPatternFile) {
diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon
index 9c6d18c..fa74ef3 100644
--- a/phpstan-baseline.neon
+++ b/phpstan-baseline.neon
@@ -40,11 +40,6 @@ parameters:
count: 1
path: Content/ContentTypeResolver/ImageMapResolver.php
- -
- message: "#^Cannot use array destructuring on string\\.$#"
- count: 1
- path: Content/ContentTypeResolver/PageSelectionResolver.php
-
-
message: "#^Cannot access offset 0 on mixed\\.$#"
count: 1
@@ -105,11 +100,6 @@ parameters:
count: 1
path: Content/DataProviderResolver/MediaDataProviderResolver.php
- -
- message: "#^Cannot use array destructuring on string\\.$#"
- count: 1
- path: Content/DataProviderResolver/PageDataProviderResolver.php
-
-
message: "#^PHPDoc tag @var above a method has no effect\\.$#"
count: 1
@@ -140,11 +130,6 @@ parameters:
count: 1
path: Content/DataProviderResolver/PageDataProviderResolver.php
- -
- message: "#^Cannot use array destructuring on string\\.$#"
- count: 1
- path: Content/DataProviderResolver/SnippetDataProviderResolver.php
-
-
message: "#^PHPDoc tag @var above a method has no effect\\.$#"
count: 1