From 1cad9caef9bd3f4efd74c102a962adf0d4c33507 Mon Sep 17 00:00:00 2001 From: Simon Schmidt Date: Wed, 15 May 2024 16:59:19 +0200 Subject: [PATCH] Fix error if no cache tags was registered If no cache tags was registered, stopCollectingCacheInfo() returns [null, null]. If we try to assign another tag 'element-api' on it, we get the following error: [Error] Attempt to modify property "tags" on null This patch solves the problem. --- src/controllers/DefaultController.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/controllers/DefaultController.php b/src/controllers/DefaultController.php index ea8c937..9a255be 100644 --- a/src/controllers/DefaultController.php +++ b/src/controllers/DefaultController.php @@ -25,6 +25,7 @@ use ReflectionFunction; use yii\base\InvalidConfigException; use yii\base\UserException; +use yii\caching\TagDependency; use yii\web\HttpException; use yii\web\JsonResponseFormatter; use yii\web\Response; @@ -234,7 +235,14 @@ public function actionIndex(string $pattern): Response /** @phpstan-ignore-next-line */ [$dep, $maxDuration] = $elementsService->stopCollectingCacheInfo(); - $dep->tags[] = 'element-api'; + + if (is_null($dep)) { + $dep = new TagDependency([ + 'tags' => ['element-api'], + ]); + } else { + $dep->tags[] = 'element-api'; + } if ($maxDuration) { if ($expire !== null) {