Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
72 changes: 37 additions & 35 deletions config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@
use FOS\HttpCacheBundle\CacheManager;
use Neusta\Pimcore\HttpCacheBundle\Adapter\FOSHttpCache\CacheInvalidatorAdapter;
use Neusta\Pimcore\HttpCacheBundle\Adapter\FOSHttpCache\ResponseTaggerAdapter;
use Neusta\Pimcore\HttpCacheBundle\Cache\CacheInvalidator;
use Neusta\Pimcore\HttpCacheBundle\Cache\CacheInvalidator\OnlyWhenActiveCacheInvalidator;
use Neusta\Pimcore\HttpCacheBundle\Cache\CacheInvalidator\RemoveDisabledTagsCacheInvalidator;
use Neusta\Pimcore\HttpCacheBundle\Cache\CacheTagChecker;
use Neusta\Pimcore\HttpCacheBundle\Cache\CacheTagChecker\ElementCacheTagChecker;
use Neusta\Pimcore\HttpCacheBundle\Cache\CacheTagChecker\StaticCacheTagChecker;
use Neusta\Pimcore\HttpCacheBundle\Cache\ResponseTagger;
use Neusta\Pimcore\HttpCacheBundle\Cache\ResponseTagger\OnlyWhenActiveResponseTagger;
use Neusta\Pimcore\HttpCacheBundle\Cache\ResponseTagger\RemoveDisabledTagsResponseTagger;
use Neusta\Pimcore\HttpCacheBundle\CacheActivator;
use Neusta\Pimcore\HttpCacheBundle\CacheInvalidator;
use Neusta\Pimcore\HttpCacheBundle\CacheInvalidator\OnlyWhenActiveCacheInvalidator;
use Neusta\Pimcore\HttpCacheBundle\CacheInvalidator\RemoveDisabledTagsCacheInvalidator;
use Neusta\Pimcore\HttpCacheBundle\CacheTag\CacheTagChecker\ElementCacheTagChecker;
use Neusta\Pimcore\HttpCacheBundle\CacheTag\CacheTagChecker\StaticCacheTagChecker;
use Neusta\Pimcore\HttpCacheBundle\Element\ElementRepository;
use Neusta\Pimcore\HttpCacheBundle\Element\InvalidateElementListener;
use Neusta\Pimcore\HttpCacheBundle\Element\TagElementListener;
use Neusta\Pimcore\HttpCacheBundle\Element\EventListener\InvalidateElementListener;
use Neusta\Pimcore\HttpCacheBundle\Element\EventListener\TagElementListener;
use Neusta\Pimcore\HttpCacheBundle\ResponseTagger;
use Neusta\Pimcore\HttpCacheBundle\ResponseTagger\OnlyWhenActiveResponseTagger;
use Neusta\Pimcore\HttpCacheBundle\ResponseTagger\RemoveDisabledTagsResponseTagger;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use function Symfony\Component\DependencyInjection\Loader\Configurator\abstract_arg;
use function Symfony\Component\DependencyInjection\Loader\Configurator\inline_service;
Expand All @@ -24,48 +23,51 @@
return static function (ContainerConfigurator $configurator) {
$services = $configurator->services();

$services->set(CacheActivator::class);
$services->set('neusta_pimcore_http_cache.cache_activator', CacheActivator::class)
->alias(CacheActivator::class, 'neusta_pimcore_http_cache.cache_activator');

$services->set(CacheInvalidator::class, CacheInvalidatorAdapter::class)
$services->set('neusta_pimcore_http_cache.cache_invalidator', CacheInvalidatorAdapter::class)
->arg('$invalidator', service(CacheManager::class));

$services->set(RemoveDisabledTagsCacheInvalidator::class)
->decorate(CacheInvalidator::class, null, -99)
->args([service('.inner'), service(CacheTagChecker::class)]);
$services->set(null, RemoveDisabledTagsCacheInvalidator::class)
->decorate('neusta_pimcore_http_cache.cache_invalidator', null, -99)
->args([service('.inner'), service('neusta_pimcore_http_cache.cache_tag_checker')]);

$services->set(OnlyWhenActiveCacheInvalidator::class)
->decorate(CacheInvalidator::class, null, -100)
->args([service('.inner'), service(CacheActivator::class)]);
$services->set(null, OnlyWhenActiveCacheInvalidator::class)
->decorate('neusta_pimcore_http_cache.cache_invalidator', null, -100)
->args([service('.inner'), service('neusta_pimcore_http_cache.cache_activator')]);

$services->set(ResponseTagger::class, ResponseTaggerAdapter::class)
$services->alias(CacheInvalidator::class, 'neusta_pimcore_http_cache.cache_invalidator');

$services->set('neusta_pimcore_http_cache.response_tagger', ResponseTaggerAdapter::class)
->arg('$responseTagger', service('fos_http_cache.http.symfony_response_tagger'));

$services->set(RemoveDisabledTagsResponseTagger::class)
->decorate(ResponseTagger::class, null, -99)
->args([service('.inner'), service(CacheTagChecker::class)]);
$services->set(null, RemoveDisabledTagsResponseTagger::class)
->decorate('neusta_pimcore_http_cache.response_tagger', null, -99)
->args([service('.inner'), service('neusta_pimcore_http_cache.cache_tag_checker')]);

$services->set(null, OnlyWhenActiveResponseTagger::class)
->decorate('neusta_pimcore_http_cache.response_tagger', null, -100)
->args([service('.inner'), service('neusta_pimcore_http_cache.cache_activator')]);

$services->set(OnlyWhenActiveResponseTagger::class)
->decorate(ResponseTagger::class, null, -100)
->args([service('.inner'), service(CacheActivator::class)]);
$services->alias(ResponseTagger::class, 'neusta_pimcore_http_cache.response_tagger');

$services->set(StaticCacheTagChecker::class)
$services->set('neusta_pimcore_http_cache.cache_tag_checker', StaticCacheTagChecker::class)
->arg('$types', abstract_arg('Set in the extension'));

$services->set(ElementCacheTagChecker::class)
->decorate(StaticCacheTagChecker::class)
$services->set('neusta_pimcore_http_cache.cache_tag_checker.element', ElementCacheTagChecker::class)
->decorate('neusta_pimcore_http_cache.cache_tag_checker')
->arg('$inner', service('.inner'))
->arg('$repository', inline_service(ElementRepository::class))
->arg('$assets', ['enabled' => false, 'types' => []])
->arg('$documents', ['enabled' => false, 'types' => []])
->arg('$objects', ['enabled' => false, 'types' => [], 'classes' => []]);

$services->alias(CacheTagChecker::class, StaticCacheTagChecker::class);

$services->set(TagElementListener::class)
->arg('$responseTagger', service(ResponseTagger::class))
$services->set('neusta_pimcore_http_cache.element.tag_listener', TagElementListener::class)
->arg('$responseTagger', service('neusta_pimcore_http_cache.response_tagger'))
->arg('$dispatcher', service('event_dispatcher'));

$services->set(InvalidateElementListener::class)
->arg('$cacheInvalidator', service(CacheInvalidator::class))
$services->set('neusta_pimcore_http_cache.element.invalidate_listener', InvalidateElementListener::class)
->arg('$cacheInvalidator', service('neusta_pimcore_http_cache.cache_invalidator'))
->arg('$dispatcher', service('event_dispatcher'));
};
4 changes: 2 additions & 2 deletions src/Adapter/FOSHttpCache/CacheInvalidatorAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace Neusta\Pimcore\HttpCacheBundle\Adapter\FOSHttpCache;

use FOS\HttpCache\CacheInvalidator as FosCacheInvalidator;
use Neusta\Pimcore\HttpCacheBundle\Cache\CacheInvalidator;
use Neusta\Pimcore\HttpCacheBundle\Cache\CacheTags;
use Neusta\Pimcore\HttpCacheBundle\CacheInvalidator;
use Neusta\Pimcore\HttpCacheBundle\CacheTags;

final class CacheInvalidatorAdapter implements CacheInvalidator
{
Expand Down
4 changes: 2 additions & 2 deletions src/Adapter/FOSHttpCache/ResponseTaggerAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
namespace Neusta\Pimcore\HttpCacheBundle\Adapter\FOSHttpCache;

use FOS\HttpCache\ResponseTagger as FosResponseTagger;
use Neusta\Pimcore\HttpCacheBundle\Cache\CacheTags;
use Neusta\Pimcore\HttpCacheBundle\Cache\ResponseTagger;
use Neusta\Pimcore\HttpCacheBundle\CacheTags;
use Neusta\Pimcore\HttpCacheBundle\ResponseTagger;

final class ResponseTaggerAdapter implements ResponseTagger
{
Expand Down
31 changes: 0 additions & 31 deletions src/Cache/CacheTypeFactory.php

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php declare(strict_types=1);

namespace Neusta\Pimcore\HttpCacheBundle\Cache;
namespace Neusta\Pimcore\HttpCacheBundle;

interface CacheInvalidator
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php declare(strict_types=1);

namespace Neusta\Pimcore\HttpCacheBundle\Cache\CacheInvalidator;
namespace Neusta\Pimcore\HttpCacheBundle\CacheInvalidator;

use Neusta\Pimcore\HttpCacheBundle\Cache\CacheInvalidator;
use Neusta\Pimcore\HttpCacheBundle\Cache\CacheTags;
use Neusta\Pimcore\HttpCacheBundle\CacheActivator;
use Neusta\Pimcore\HttpCacheBundle\CacheInvalidator;
use Neusta\Pimcore\HttpCacheBundle\CacheTags;

final class OnlyWhenActiveCacheInvalidator implements CacheInvalidator
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php declare(strict_types=1);

namespace Neusta\Pimcore\HttpCacheBundle\Cache\CacheInvalidator;
namespace Neusta\Pimcore\HttpCacheBundle\CacheInvalidator;

use Neusta\Pimcore\HttpCacheBundle\Cache\CacheInvalidator;
use Neusta\Pimcore\HttpCacheBundle\Cache\CacheTagChecker;
use Neusta\Pimcore\HttpCacheBundle\Cache\CacheTags;
use Neusta\Pimcore\HttpCacheBundle\CacheInvalidator;
use Neusta\Pimcore\HttpCacheBundle\CacheTag\CacheTagChecker;
use Neusta\Pimcore\HttpCacheBundle\CacheTags;

final class RemoveDisabledTagsCacheInvalidator implements CacheInvalidator
{
Expand Down
16 changes: 9 additions & 7 deletions src/Cache/CacheTag.php → src/CacheTag.php
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
<?php declare(strict_types=1);

namespace Neusta\Pimcore\HttpCacheBundle\Cache;
namespace Neusta\Pimcore\HttpCacheBundle;

use Neusta\Pimcore\HttpCacheBundle\Cache\CacheType\ElementCacheType;
use Neusta\Pimcore\HttpCacheBundle\CacheTag\CacheTagType;
use Neusta\Pimcore\HttpCacheBundle\CacheTag\CacheTagType\ElementCacheTagType;
use Neusta\Pimcore\HttpCacheBundle\CacheTag\CacheTagTypeFactory;
use Neusta\Pimcore\HttpCacheBundle\Exception\InvalidArgumentException;
use Pimcore\Model\Element\ElementInterface;

final class CacheTag
{
private function __construct(
public readonly string $tag,
public readonly CacheType $type,
public readonly CacheTagType $type,
) {
if ('' === trim($tag)) {
throw InvalidArgumentException::becauseCacheTagIsEmpty();
}

if (!$type instanceof ElementCacheType && ElementCacheType::isReserved($type->toString())) {
if (!$type instanceof ElementCacheTagType && ElementCacheTagType::isReserved($type->toString())) {
throw InvalidArgumentException::becauseCacheTypeIsReserved($type);
}
}

public static function fromString(string $tag, ?CacheType $type = null): self
public static function fromString(string $tag, ?CacheTagType $type = null): self
{
return new self($tag, $type ?? CacheTypeFactory::createEmpty());
return new self($tag, $type ?? CacheTagTypeFactory::createEmpty());
}

public static function fromElement(ElementInterface $element): self
Expand All @@ -32,7 +34,7 @@ public static function fromElement(ElementInterface $element): self
throw InvalidArgumentException::becauseElementHasNoId();
}

return new self((string) $id, CacheTypeFactory::createFromElement($element));
return new self((string) $id, CacheTagTypeFactory::createFromElement($element));
}

public function toString(): string
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php declare(strict_types=1);

namespace Neusta\Pimcore\HttpCacheBundle\Cache;
namespace Neusta\Pimcore\HttpCacheBundle\CacheTag;

use Neusta\Pimcore\HttpCacheBundle\CacheTag;

interface CacheTagChecker
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php declare(strict_types=1);

namespace Neusta\Pimcore\HttpCacheBundle\Cache\CacheTagChecker;
namespace Neusta\Pimcore\HttpCacheBundle\CacheTag\CacheTagChecker;

use Neusta\Pimcore\HttpCacheBundle\Cache\CacheTag;
use Neusta\Pimcore\HttpCacheBundle\Cache\CacheTagChecker;
use Neusta\Pimcore\HttpCacheBundle\Cache\CacheType\ElementCacheType;
use Neusta\Pimcore\HttpCacheBundle\CacheTag;
use Neusta\Pimcore\HttpCacheBundle\CacheTag\CacheTagChecker;
use Neusta\Pimcore\HttpCacheBundle\CacheTag\CacheTagType\ElementCacheTagType;
use Neusta\Pimcore\HttpCacheBundle\Element\ElementRepository;
use Neusta\Pimcore\HttpCacheBundle\Element\ElementType;
use Pimcore\Model\DataObject\Concrete;
Expand All @@ -27,7 +27,7 @@ public function __construct(

public function isEnabled(CacheTag $tag): bool
{
if (!$tag->type instanceof ElementCacheType) {
if (!$tag->type instanceof ElementCacheTagType) {
return $this->inner->isEnabled($tag);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php declare(strict_types=1);

namespace Neusta\Pimcore\HttpCacheBundle\Cache\CacheTagChecker;
namespace Neusta\Pimcore\HttpCacheBundle\CacheTag\CacheTagChecker;

use Neusta\Pimcore\HttpCacheBundle\Cache\CacheTag;
use Neusta\Pimcore\HttpCacheBundle\Cache\CacheTagChecker;
use Neusta\Pimcore\HttpCacheBundle\CacheTag;
use Neusta\Pimcore\HttpCacheBundle\CacheTag\CacheTagChecker;

final class StaticCacheTagChecker implements CacheTagChecker
{
Expand Down
4 changes: 2 additions & 2 deletions src/Cache/CacheType.php → src/CacheTag/CacheTagType.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php declare(strict_types=1);

namespace Neusta\Pimcore\HttpCacheBundle\Cache;
namespace Neusta\Pimcore\HttpCacheBundle\CacheTag;

interface CacheType
interface CacheTagType
{
public function applyTo(string $tag): string;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php declare(strict_types=1);

namespace Neusta\Pimcore\HttpCacheBundle\Cache\CacheType;
namespace Neusta\Pimcore\HttpCacheBundle\CacheTag\CacheTagType;

use Neusta\Pimcore\HttpCacheBundle\Cache\CacheType;
use Neusta\Pimcore\HttpCacheBundle\CacheTag\CacheTagType;
use Neusta\Pimcore\HttpCacheBundle\Exception\InvalidArgumentException;

final class CustomCacheType implements CacheType
final class CustomCacheTagType implements CacheTagType
{
public function __construct(
private readonly string $type,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php declare(strict_types=1);

namespace Neusta\Pimcore\HttpCacheBundle\Cache\CacheType;
namespace Neusta\Pimcore\HttpCacheBundle\CacheTag\CacheTagType;

use Neusta\Pimcore\HttpCacheBundle\Cache\CacheType;
use Neusta\Pimcore\HttpCacheBundle\CacheTag\CacheTagType;
use Neusta\Pimcore\HttpCacheBundle\Element\ElementType;

final class ElementCacheType implements CacheType
final class ElementCacheTagType implements CacheTagType
{
public function __construct(
public readonly ElementType $type,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php declare(strict_types=1);

namespace Neusta\Pimcore\HttpCacheBundle\Cache\CacheType;
namespace Neusta\Pimcore\HttpCacheBundle\CacheTag\CacheTagType;

use Neusta\Pimcore\HttpCacheBundle\Cache\CacheType;
use Neusta\Pimcore\HttpCacheBundle\CacheTag\CacheTagType;

final class EmptyCacheType implements CacheType
final class EmptyCacheTagType implements CacheTagType
{
public function applyTo(string $tag): string
{
Expand Down
31 changes: 31 additions & 0 deletions src/CacheTag/CacheTagTypeFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php declare(strict_types=1);

namespace Neusta\Pimcore\HttpCacheBundle\CacheTag;

use Neusta\Pimcore\HttpCacheBundle\CacheTag\CacheTagType\CustomCacheTagType;
use Neusta\Pimcore\HttpCacheBundle\CacheTag\CacheTagType\ElementCacheTagType;
use Neusta\Pimcore\HttpCacheBundle\CacheTag\CacheTagType\EmptyCacheTagType;
use Neusta\Pimcore\HttpCacheBundle\Element\ElementType;
use Pimcore\Model\Element\ElementInterface;

final class CacheTagTypeFactory
{
public static function createEmpty(): EmptyCacheTagType
{
return new EmptyCacheTagType();
}

public static function createFromString(string $type): ElementCacheTagType|CustomCacheTagType
{
if ($elementType = ElementType::tryFrom($type)) {
return new ElementCacheTagType($elementType);
}

return new CustomCacheTagType($type);
}

public static function createFromElement(ElementInterface $element): ElementCacheTagType
{
return new ElementCacheTagType(ElementType::fromElement($element));
}
}
Loading