Exponential 5.x Kernel 7.5.40 Exponential New Stack (Symfony-based) Kernel — PHP Class Reference

AliasGeneratorDecorator.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Bundle\EzPublishCoreBundle\Imagine\Cache;
8
9 use eZ\Publish\API\Repository\Values\Content\Field;
10 use eZ\Publish\API\Repository\Values\Content\VersionInfo;
11 use eZ\Publish\Core\MVC\Symfony\SiteAccess;
12 use eZ\Publish\Core\MVC\Symfony\SiteAccess\SiteAccessAware;
13 use eZ\Publish\SPI\Variation\VariationHandler;
14 use Ibexa\Core\Persistence\Cache\Identifier\CacheIdentifierGeneratorInterface;
15 use Symfony\Component\Cache\Adapter\TagAwareAdapterInterface;
16 use Symfony\Component\Routing\RequestContext;
17
21 class AliasGeneratorDecorator implements VariationHandler, SiteAccessAware
22 {
23 private const IMAGE_VARIATION_TAG = 'image_variation';
24 private const IMAGE_VARIATION_SITEACCESS_TAG = 'image_variation_siteaccess';
25 private const IMAGE_VARIATION_CONTENT_TAG = 'image_variation_content';
26 private const IMAGE_VARIATION_FIELD_TAG = 'image_variation_field';
27 private const IMAGE_VARIATION_NAME_TAG = 'image_variation_name';
28 private const CONTENT_TAG = 'content';
29 private const CONTENT_VERSION_TAG = 'content_version';
30
32 private $aliasGenerator;
33
35 private $cache;
36
38 private $siteAccess;
39
41 private $requestContext;
42
44 private $cacheIdentifierGenerator;
45
52 public function __construct(
53 VariationHandler $aliasGenerator,
54 TagAwareAdapterInterface $cache,
55 RequestContext $requestContext,
56 CacheIdentifierGeneratorInterface $cacheIdentifierGenerator
57 ) {
58 $this->aliasGenerator = $aliasGenerator;
59 $this->cache = $cache;
60 $this->requestContext = $requestContext;
61 $this->cacheIdentifierGenerator = $cacheIdentifierGenerator;
62 }
63
74 public function getVariation(Field $field, VersionInfo $versionInfo, $variationName, array $parameters = [])
75 {
76 $item = $this->cache->getItem($this->getCacheKey($field, $versionInfo, $variationName));
77 $image = $item->get();
78 if (!$item->isHit()) {
79 $image = $this->aliasGenerator->getVariation($field, $versionInfo, $variationName, $parameters);
80 $item->set($image);
81 $item->tag($this->getTagsForVariation($field, $versionInfo, $variationName));
82 $this->cache->save($item);
83 }
84
85 return $image;
86 }
87
91 public function setSiteAccess(SiteAccess $siteAccess = null)
92 {
93 $this->siteAccess = $siteAccess;
94 }
95
103 private function getCacheKey(Field $field, VersionInfo $versionInfo, $variationName)
104 {
105 return sprintf(
106 $this->cacheIdentifierGenerator->generateKey(self::IMAGE_VARIATION_TAG, [], true) . '-%s-%s-%s-%d-%d-%d-%s-%s',
107 $this->siteAccess->name ?? 'default',
108 $this->requestContext->getScheme(),
109 $this->requestContext->getHost(),
110 $this->requestContext->getScheme() === 'https' ? $this->requestContext->getHttpsPort() : $this->requestContext->getHttpPort(),
111 $versionInfo->getContentInfo()->id,
112 $versionInfo->id,
113 $field->id,
114 $variationName
115 );
116 }
117
118 private function getTagsForVariation(Field $field, VersionInfo $versionInfo, string $variationName): array
119 {
120 $contentId = $versionInfo->getContentInfo()->id;
121
122 return [
123 $this->cacheIdentifierGenerator->generateTag(self::IMAGE_VARIATION_TAG),
124 $this->cacheIdentifierGenerator->generateTag(self::IMAGE_VARIATION_NAME_TAG, [$variationName]),
125 $this->cacheIdentifierGenerator->generateTag(self::IMAGE_VARIATION_SITEACCESS_TAG, [$this->siteAccess->name ?? 'default']),
126 $this->cacheIdentifierGenerator->generateTag(self::IMAGE_VARIATION_CONTENT_TAG, [$contentId]),
127 $this->cacheIdentifierGenerator->generateTag(self::IMAGE_VARIATION_FIELD_TAG, [$field->id]),
128 $this->cacheIdentifierGenerator->generateTag(self::CONTENT_TAG, [$contentId]),
129 $this->cacheIdentifierGenerator->generateTag(self::CONTENT_VERSION_TAG, [$contentId, $versionInfo->versionNo]),
130 ];
131 }
132
133 public function getVariationNameTag(): string
134 {
135 return self::IMAGE_VARIATION_NAME_TAG;
136 }
137 }
eZ\Bundle\EzPublishCoreBundle\Imagine\Cache\AliasGeneratorDecorator
Persistence Cache layer for AliasGenerator.
Definition: AliasGeneratorDecorator.php:22
eZ\Bundle\EzPublishCoreBundle\Imagine\Cache\AliasGeneratorDecorator\getVariation
getVariation(Field $field, VersionInfo $versionInfo, $variationName, array $parameters=[])
Definition: AliasGeneratorDecorator.php:74
eZ\Bundle\EzPublishCoreBundle\Imagine\Cache\AliasGeneratorDecorator\getTagsForVariation
getTagsForVariation(Field $field, VersionInfo $versionInfo, string $variationName)
Definition: AliasGeneratorDecorator.php:118
eZ\Bundle\EzPublishCoreBundle\Imagine\Cache\AliasGeneratorDecorator\IMAGE_VARIATION_CONTENT_TAG
const IMAGE_VARIATION_CONTENT_TAG
Definition: AliasGeneratorDecorator.php:25
eZ\Bundle\EzPublishCoreBundle\Imagine\Cache\AliasGeneratorDecorator\getVariationNameTag
getVariationNameTag()
Definition: AliasGeneratorDecorator.php:133
eZ\Bundle\EzPublishCoreBundle\Imagine\Cache\AliasGeneratorDecorator\setSiteAccess
setSiteAccess(SiteAccess $siteAccess=null)
Definition: AliasGeneratorDecorator.php:91
eZ\Bundle\EzPublishCoreBundle\Imagine\Cache\AliasGeneratorDecorator\$siteAccess
$siteAccess
Definition: AliasGeneratorDecorator.php:38
eZ\Bundle\EzPublishCoreBundle\Imagine\Cache\AliasGeneratorDecorator\IMAGE_VARIATION_TAG
const IMAGE_VARIATION_TAG
Definition: AliasGeneratorDecorator.php:23
eZ\Bundle\EzPublishCoreBundle\Imagine\Cache\AliasGeneratorDecorator\$aliasGenerator
$aliasGenerator
Definition: AliasGeneratorDecorator.php:32
eZ\Bundle\EzPublishCoreBundle\Imagine\Cache\AliasGeneratorDecorator\CONTENT_VERSION_TAG
const CONTENT_VERSION_TAG
Definition: AliasGeneratorDecorator.php:29
eZ\Bundle\EzPublishCoreBundle\Imagine\Cache\AliasGeneratorDecorator\IMAGE_VARIATION_NAME_TAG
const IMAGE_VARIATION_NAME_TAG
Definition: AliasGeneratorDecorator.php:27
eZ\Bundle\EzPublishCoreBundle\Imagine\Cache\AliasGeneratorDecorator\$requestContext
$requestContext
Definition: AliasGeneratorDecorator.php:41
eZ\Bundle\EzPublishCoreBundle\Imagine\Cache\AliasGeneratorDecorator\$cacheIdentifierGenerator
$cacheIdentifierGenerator
Definition: AliasGeneratorDecorator.php:44
eZ\Bundle\EzPublishCoreBundle\Imagine\Cache\AliasGeneratorDecorator\$cache
$cache
Definition: AliasGeneratorDecorator.php:35
eZ\Bundle\EzPublishCoreBundle\Imagine\Cache\AliasGeneratorDecorator\IMAGE_VARIATION_FIELD_TAG
const IMAGE_VARIATION_FIELD_TAG
Definition: AliasGeneratorDecorator.php:26
eZ\Bundle\EzPublishCoreBundle\Imagine\Cache\AliasGeneratorDecorator\CONTENT_TAG
const CONTENT_TAG
Definition: AliasGeneratorDecorator.php:28
eZ\Bundle\EzPublishCoreBundle\Imagine\Cache\AliasGeneratorDecorator\getCacheKey
getCacheKey(Field $field, VersionInfo $versionInfo, $variationName)
Definition: AliasGeneratorDecorator.php:103
eZ\Bundle\EzPublishCoreBundle\Imagine\Cache\AliasGeneratorDecorator\IMAGE_VARIATION_SITEACCESS_TAG
const IMAGE_VARIATION_SITEACCESS_TAG
Definition: AliasGeneratorDecorator.php:24
eZ\Bundle\EzPublishCoreBundle\Imagine\Cache\AliasGeneratorDecorator\__construct
__construct(VariationHandler $aliasGenerator, TagAwareAdapterInterface $cache, RequestContext $requestContext, CacheIdentifierGeneratorInterface $cacheIdentifierGenerator)
Definition: AliasGeneratorDecorator.php:52
eZ\Publish\API\Repository\Values\Content\Field
Definition: API/Repository/Values/Content/Field.php:21
eZ\Publish\API\Repository\Values\Content\VersionInfo
Definition: API/Repository/Values/Content/VersionInfo.php:27
eZ\Publish\API\Repository\Values\Content\VersionInfo\getContentInfo
getContentInfo()
Content of the content this version belongs to.
eZ\Publish\Core\MVC\Symfony\SiteAccess
Base struct for a siteaccess representation.
Definition: SiteAccess.php:16
Ibexa\Core\Persistence\Cache\Identifier\CacheIdentifierGeneratorInterface
Definition: CacheIdentifierGeneratorInterface.php:15
eZ\Publish\Core\MVC\Symfony\SiteAccess\SiteAccessAware
Interface for SiteAccess aware services.
Definition: SiteAccessAware.php:15
eZ\Publish\SPI\Variation\VariationHandler
Interface for Variation services.
Definition: VariationHandler.php:18
eZ\Bundle\EzPublishCoreBundle\Imagine\Cache
Definition: AliasGeneratorDecorator.php:7
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.