Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/contracts/ResponseTagger/ResponseTagger.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
*/
interface ResponseTagger
{
/**
* Checks if a value is supported by the tagger.
*/
Comment thread
wiewiurdp marked this conversation as resolved.
Outdated
public function supports(mixed $value): bool;

/**
* Extracts tags from a value.
*
Expand Down
3 changes: 1 addition & 2 deletions src/lib/ResponseTagger/Delegator/ContentValueViewTagger.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
use Ibexa\Contracts\Core\Repository\Values\Content\Content;
use Ibexa\Contracts\HttpCache\ResponseTagger\ResponseTagger;
use Ibexa\Core\MVC\Symfony\View\ContentValueView;
use Ibexa\HttpCache\ResponseTagger\Value\AbstractValueTagger;

class ContentValueViewTagger extends AbstractValueTagger
class ContentValueViewTagger implements ResponseTagger
Comment thread
wiewiurdp marked this conversation as resolved.
Outdated
{
public function __construct(private readonly ResponseTagger $contentInfoTagger)
{
Expand Down
17 changes: 6 additions & 11 deletions src/lib/ResponseTagger/Delegator/DispatcherTagger.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,15 @@ public function __construct(private iterable $taggers = [])
{
}

public function supports(mixed $value): bool
{
return true;
}

public function tag(mixed $value): void
{
foreach ($this->taggers as $tagger) {
if (method_exists($tagger, 'supports')) {
if ($tagger->supports($value)) {
$tagger->tag($value);
}
} else {
trigger_deprecation(
'ibexa/http-cache',
'5.0.7',
'%s does not implement supports(). This will be required in 6.0, supports() will be a part of ResponseTagger interface',
get_debug_type($tagger),
);
if ($tagger->supports($value)) {

@mnocon mnocon Jun 18, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Going back the initial idea that pushed us towards these changes - maybe we throw an exception* if there's no tagger supporting given value? As this must be a mistake.

The origial report said that if you pass a Content object (instead of ContentInfo) to be tagged, nothing happens and you get no information that something is wrong.

*or log a warning, or log a warning in dev mode, or something else

$tagger->tag($value);
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/lib/ResponseTagger/Delegator/LocationValueViewTagger.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
use Ibexa\Contracts\Core\Repository\Values\Content\Location;
use Ibexa\Contracts\HttpCache\ResponseTagger\ResponseTagger;
use Ibexa\Core\MVC\Symfony\View\LocationValueView;
use Ibexa\HttpCache\ResponseTagger\Value\AbstractValueTagger;

class LocationValueViewTagger extends AbstractValueTagger
class LocationValueViewTagger implements ResponseTagger
Comment thread
wiewiurdp marked this conversation as resolved.
Outdated
{
public function __construct(private readonly ResponseTagger $locationTagger)
{
Expand Down
21 changes: 0 additions & 21 deletions src/lib/ResponseTagger/Value/AbstractValueTagger.php

This file was deleted.

8 changes: 7 additions & 1 deletion src/lib/ResponseTagger/Value/ContentInfoTagger.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,20 @@

namespace Ibexa\HttpCache\ResponseTagger\Value;

use FOS\HttpCache\ResponseTagger as FosResponseTagger;
use Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo;
use Ibexa\Contracts\HttpCache\Handler\ContentTagInterface;
use Ibexa\Contracts\HttpCache\ResponseTagger\ResponseTagger;

/**
* @final
*/
class ContentInfoTagger extends AbstractValueTagger
class ContentInfoTagger implements ResponseTagger
Comment thread
konradoboza marked this conversation as resolved.
Outdated
{
public function __construct(private readonly FosResponseTagger $responseTagger)
{
}

public function supports(mixed $value): bool
{
return $value instanceof ContentInfo;
Expand Down
8 changes: 7 additions & 1 deletion src/lib/ResponseTagger/Value/LocationTagger.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,20 @@

namespace Ibexa\HttpCache\ResponseTagger\Value;

use FOS\HttpCache\ResponseTagger as FosResponseTagger;
use Ibexa\Contracts\Core\Repository\Values\Content\Location;
use Ibexa\Contracts\HttpCache\Handler\ContentTagInterface;
use Ibexa\Contracts\HttpCache\ResponseTagger\ResponseTagger;

/**
* @final
*/
class LocationTagger extends AbstractValueTagger
class LocationTagger implements ResponseTagger
Comment thread
konradoboza marked this conversation as resolved.
Outdated
{
public function __construct(private readonly FosResponseTagger $responseTagger)
{
}

public function supports(mixed $value): bool
{
return $value instanceof Location;
Expand Down
24 changes: 7 additions & 17 deletions tests/lib/ResponseTagger/Delegator/DispatcherTaggerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function testDoesNotCallTagWhenNoTaggerSupportsTheValue(): void
$dispatcher->tag($location);
}

public function testCustomResponseTaggerImplementationLackingSupportsMethodShouldTag(): void
public function testCallsCustomResponseTaggerWhenItSupportsTheValue(): void
{
$foo = new stdClass();

Expand All @@ -103,6 +103,11 @@ public function __construct(private bool &$wasCalled)
{
}

public function supports(mixed $value): bool
{
return true;
}

public function tag(mixed $value): void
{
$this->wasCalled = true;
Expand All @@ -111,23 +116,8 @@ public function tag(mixed $value): void

$dispatcher = new DispatcherTagger([$contentInfoTagger, $customTagger]);

$deprecation = null;
set_error_handler(static function (int $errorCode, string $errorString) use (&$deprecation): bool {
if ($errorCode === E_USER_DEPRECATED) {
$deprecation = $errorString;
}

return true;
});

try {
$dispatcher->tag($foo);
} finally {
restore_error_handler();
}

$dispatcher->tag($foo);
self::assertTrue($wasCalled, 'Custom ResponseTagger::tag() was not called by the dispatcher.');
self::assertStringContainsString('does not implement supports()', $deprecation);
}

public function testToStringWithNoTaggers(): void
Expand Down
Loading