• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tito10047 / progressive-image-bundle / 20674769022

03 Jan 2026 08:26AM UTC coverage: 86.782% (-2.3%) from 89.065%
20674769022

push

github

tito10047
add tag-aware cache support: implement usage of `TagAwareCacheInterface` in cache services, update bundle configurations, compiler pass, tests, and Twig templates; ensure compatibility with non-tag-aware caches

47 of 70 new or added lines in 6 files covered. (67.14%)

604 of 696 relevant lines covered (86.78%)

175.71 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

33.33
/src/DependencyInjection/CheckCacheInterfacePass.php
1
<?php
2

3
namespace Tito10047\ProgressiveImageBundle\DependencyInjection;
4

5
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Contracts\Cache\TagAwareCacheInterface;
8

9
class CheckCacheInterfacePass implements CompilerPassInterface
10
{
11
    public function process(ContainerBuilder $container): void
12
    {
13
        if ($container->hasParameter('progressive_image.image_cache_enabled') && !$container->getParameter('progressive_image.image_cache_enabled')) {
332✔
14
            return;
15✔
15
        }
16

17
        if (!$container->hasAlias('progressive_image.image_cache_service')) {
317✔
NEW
18
            return;
×
19
        }
20

21
        $cacheServiceId = (string) $container->getAlias('progressive_image.image_cache_service');
317✔
22
        if (!$container->hasDefinition($cacheServiceId)) {
317✔
NEW
23
            return;
×
24
        }
25

26
        $definition = $container->getDefinition($cacheServiceId);
317✔
27
        
28
        while ($definition->hasTag('container.service_alias')) {
317✔
NEW
29
            $tags = $definition->getTag('container.service_alias');
×
NEW
30
            $cacheServiceId = $tags[0]['alias'] ?? $cacheServiceId;
×
NEW
31
            if (!$container->hasDefinition($cacheServiceId)) {
×
NEW
32
                break;
×
33
            }
NEW
34
            $definition = $container->getDefinition($cacheServiceId);
×
35
        }
36

37
        // Ak ide o cache pool definovaný cez FrameworkBundle, Symfony ho v build čase
38
        // premení na definíciu, ktorej class je napr. Symfony\Component\Cache\Adapter\ArrayAdapter.
39
        // Ak má povolené tagy, Symfony ho obalí do TagAwareAdapter.
40
        
41
        $class = $container->getParameterBag()->resolveValue($definition->getClass());
317✔
42
        
43
        // Ak je trieda prázdna, môže to byť factory. V tom prípade skúsime pozrieť na factory
44
        if (!$class && $definition->getFactory()) {
317✔
45
            // Tu je ťažké určiť návratový typ factory v compile čase bez vykonania kódu
46
        }
47

48
        if ($class && !is_subclass_of($class, TagAwareCacheInterface::class) && $class !== TagAwareCacheInterface::class) {
317✔
NEW
49
            throw new \LogicException(sprintf(
×
NEW
50
                'Služba cache "%1$s" (trieda: %2$s) musí implementovať TagAwareCacheInterface, aby mohla byť použitá v ProgressiveImageBundle. ' .
×
NEW
51
                'Skontrolujte, či máte v konfigurácii framework.cache povolené "tags: true" pre tento pool a následne ho nastavte v konfigurácii bundle: ' .
×
NEW
52
                'progressive_image: { image_cache_service: "%1$s" }. ' .
×
NEW
53
                'Príklad konfigurácie poolu: framework: { cache: { pools: { %1$s: { adapter: cache.adapter.redis_tag_aware, tags: true } } } }',
×
NEW
54
                $cacheServiceId,
×
NEW
55
                $class
×
NEW
56
            ));
×
57
        }
58

59
        // Špeciálna kontrola pre Symfony cache pooly, ktoré nemajú nastavený class hneď,
60
        // ale vieme o nich zistiť, či sú taggable.
61
        if (!$class || $class === 'Symfony\Component\Cache\Adapter\ArrayAdapter' || $class === 'Symfony\Component\Cache\Adapter\FilesystemAdapter') {
317✔
NEW
62
             if (!$definition->hasTag('cache.taggable')) {
×
63
                 // Ak nemá tag cache.taggable a zároveň trieda nie je TagAware, vyhodíme chybu.
64
                 // Symfony TagAwareAdapter má triedu nastavenú na TagAwareAdapter.
NEW
65
                 throw new \LogicException(sprintf(
×
NEW
66
                     'Služba cache "%1$s" nie je "tag aware". Skontrolujte, či máte v konfigurácii framework.cache povolené "tags: true" pre tento pool ' .
×
NEW
67
                     'a následne ho nastavte v konfigurácii bundle: progressive_image: { image_cache_service: "%1$s" }. ' .
×
NEW
68
                     'Príklad konfigurácie poolu: framework: { cache: { pools: { %1$s: { adapter: cache.adapter.redis_tag_aware, tags: true } } } }',
×
NEW
69
                     $cacheServiceId
×
NEW
70
                 ));
×
71
             }
72
        }
73
    }
74
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc