|
4 | 4 | * @copyright Copyright (C) Ibexa AS. All rights reserved. |
5 | 5 | * @license For full copyright and license information view LICENSE file distributed with this source code. |
6 | 6 | */ |
| 7 | +declare(strict_types=1); |
7 | 8 |
|
8 | 9 | namespace Ibexa\HttpCache\ResponseTagger\Value; |
9 | 10 |
|
| 11 | +use FOS\HttpCache\ResponseTagger as FosResponseTagger; |
10 | 12 | use Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo; |
11 | 13 | use Ibexa\Contracts\HttpCache\Handler\ContentTagInterface; |
| 14 | +use Psr\Log\LoggerInterface; |
| 15 | +use Psr\Log\NullLogger; |
| 16 | +use RuntimeException; |
12 | 17 |
|
13 | 18 | class ContentInfoTagger extends AbstractValueTagger |
14 | 19 | { |
| 20 | + public function __construct( |
| 21 | + FosResponseTagger $responseTagger, |
| 22 | + private LoggerInterface $logger = new NullLogger(), |
| 23 | + private readonly bool $debug = false |
| 24 | + ) { |
| 25 | + parent::__construct($responseTagger); |
| 26 | + |
| 27 | + $this->logger = $logger ?? new NullLogger(); |
| 28 | + } |
| 29 | + |
15 | 30 | public function tag($value) |
16 | 31 | { |
17 | 32 | if (!$value instanceof ContentInfo) { |
| 33 | + $message = sprintf( |
| 34 | + '%s expects value of type %s, got %s.', |
| 35 | + self::class, |
| 36 | + ContentInfo::class, |
| 37 | + get_debug_type($value), |
| 38 | + ); |
| 39 | + |
| 40 | + if ($this->debug) { |
| 41 | + throw new RuntimeException($message); |
| 42 | + } |
| 43 | + |
| 44 | + $this->logger->warning($message); |
| 45 | + |
18 | 46 | return $this; |
19 | 47 | } |
20 | 48 |
|
21 | 49 | $this->responseTagger->addTags([ |
22 | | - ContentTagInterface::CONTENT_PREFIX . $value->id, |
| 50 | + ContentTagInterface::CONTENT_PREFIX . $value->getId(), |
23 | 51 | ContentTagInterface::CONTENT_TYPE_PREFIX . $value->contentTypeId, |
24 | 52 | ]); |
25 | 53 |
|
26 | 54 | if ($value->mainLocationId) { |
27 | | - $this->responseTagger->addTags([ContentTagInterface::LOCATION_PREFIX . $value->mainLocationId]); |
| 55 | + $this->responseTagger->addTags([ |
| 56 | + ContentTagInterface::LOCATION_PREFIX . $value->getMainLocationId(), |
| 57 | + ]); |
28 | 58 | } |
29 | 59 | } |
30 | 60 | } |
0 commit comments