-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathConfig.php
More file actions
149 lines (116 loc) · 4.99 KB
/
Copy pathConfig.php
File metadata and controls
149 lines (116 loc) · 4.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<?php
declare(strict_types=1);
namespace Elgentos\VarnishExtended\Model;
use Magento\Framework\App\Cache\StateInterface;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Filesystem\Directory\ReadFactory;
use Magento\Framework\HTTP\PhpEnvironment\Request;
use Magento\Framework\Module\Dir\Reader;
use Magento\Framework\Serialize\Serializer\Json;
use Magento\PageCache\Model\Config as PageCacheConfig;
use Magento\PageCache\Model\Varnish\VclGeneratorFactory;
use Magento\Store\Model\ScopeInterface;
class Config extends PageCacheConfig
{
private ScopeConfigInterface $scopeConfig;
private Json $serializer;
public const XML_PATH_VARNISH_ENABLE_BFCACHE = 'system/full_page_cache/varnish/enable_bfcache';
public const XML_PATH_VARNISH_ENABLE_MEDIA_CACHE = 'system/full_page_cache/varnish/enable_media_cache';
public const XML_PATH_VARNISH_ENABLE_STATIC_CACHE = 'system/full_page_cache/varnish/enable_static_cache';
public const XML_PATH_VARNISH_TRACKING_PARAMETERS = 'system/full_page_cache/varnish/tracking_parameters';
public const XML_PATH_VARNISH_USE_XKEY_VMOD = 'system/full_page_cache/varnish/use_xkey_vmod';
public const XML_PATH_VARNISH_USE_SOFT_PURGING = 'system/full_page_cache/varnish/use_soft_purging';
public const XML_PATH_VARNISH_PASS_ON_COOKIE_PRESENCE = 'system/full_page_cache/varnish/pass_on_cookie_presence';
public const XML_PATH_VARNISH_CUSTOM_VCL_PREPEND_FILE = 'system/full_page_cache/varnish/custom_vcl_prepend_file';
public const XML_PATH_VARNISH_CUSTOM_VCL_APPEND_FILE = 'system/full_page_cache/varnish/custom_vcl_append_file';
public function __construct(
ReadFactory $readFactory,
ScopeConfigInterface $scopeConfig,
StateInterface $cacheState,
Reader $reader,
VclGeneratorFactory $vclGeneratorFactory,
Json $serializer
) {
parent::__construct(
$readFactory,
$scopeConfig,
$cacheState,
$reader,
$vclGeneratorFactory,
$serializer
);
$this->serializer = $serializer;
$this->scopeConfig = $scopeConfig;
}
public function getTrackingParameters(): string
{
$trackingParams = $this->scopeConfig->getValue(static::XML_PATH_VARNISH_TRACKING_PARAMETERS);
if (is_string($trackingParams) && !json_decode($trackingParams)) { // fallback for version 1.0.0 notation
return $trackingParams;
}
return implode('|', array_map(function ($param) {
return $param['param'];
}, is_array($trackingParams) ? $trackingParams : json_decode($trackingParams ?? '{}', true)));
}
public function getUseXkeyVmod(): bool
{
return (bool) $this->scopeConfig->getValue(static::XML_PATH_VARNISH_USE_XKEY_VMOD);
}
public function getUseSoftPurging(): bool
{
return (bool) $this->scopeConfig->getValue(static::XML_PATH_VARNISH_USE_SOFT_PURGING);
}
public function getPassOnCookiePresence(): array
{
return $this->serializer->unserialize($this->scopeConfig->getValue(static::XML_PATH_VARNISH_PASS_ON_COOKIE_PRESENCE) ?? '{}');
}
public function getEnableBfcache(): bool
{
return (bool) $this->scopeConfig->getValue(static::XML_PATH_VARNISH_ENABLE_BFCACHE);
}
public function getSslOffloadedHeader()
{
return $this->scopeConfig->getValue(Request::XML_PATH_OFFLOADER_HEADER);
}
public function getBackendHost()
{
return $this->scopeConfig->getValue(static::XML_VARNISH_PAGECACHE_BACKEND_HOST);
}
public function getBackendPort()
{
return $this->scopeConfig->getValue(static::XML_VARNISH_PAGECACHE_BACKEND_PORT);
}
public function getAccessList()
{
$accessList = $this->_scopeConfig->getValue(static::XML_VARNISH_PAGECACHE_ACCESS_LIST);
return array_map('trim', explode(',', $accessList));
}
public function getGracePeriod()
{
return $this->scopeConfig->getValue(static::XML_VARNISH_PAGECACHE_GRACE_PERIOD);
}
public function getDesignExceptions()
{
$expressions = $this->scopeConfig->getValue(
\Magento\PageCache\Model\Config::XML_VARNISH_PAGECACHE_DESIGN_THEME_REGEX,
ScopeInterface::SCOPE_STORE
);
return $expressions ? $this->serializer->unserialize($expressions) : [];
}
public function getEnableMediaCache(): bool
{
return (bool) $this->scopeConfig->getValue(static::XML_PATH_VARNISH_ENABLE_MEDIA_CACHE);
}
public function getEnableStaticCache(): bool
{
return (bool) $this->scopeConfig->getValue(static::XML_PATH_VARNISH_ENABLE_STATIC_CACHE);
}
public function getCustomVclPrependFile(): string
{
return (string) $this->scopeConfig->getValue(static::XML_PATH_VARNISH_CUSTOM_VCL_PREPEND_FILE);
}
public function getCustomVclAppendFile(): string
{
return (string) $this->scopeConfig->getValue(static::XML_PATH_VARNISH_CUSTOM_VCL_APPEND_FILE);
}
}