Skip to content

Commit dfc7f92

Browse files
committed
Add Backend model for Fetch Tag limit config
1 parent 58c9025 commit dfc7f92

File tree

2 files changed

+74
-1
lines changed

2 files changed

+74
-1
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace IntegerNet\AsyncVarnish\Model\System\Config\Backend;
5+
6+
use Magento\Framework\App\Cache\TypeListInterface;
7+
use Magento\Framework\App\Config\Value;
8+
use Magento\Framework\App\ObjectManager;
9+
use Magento\Framework\Data\Collection\AbstractDb;
10+
use Magento\Framework\Escaper;
11+
use Magento\Framework\App\Config\ScopeConfigInterface;
12+
use Magento\Framework\Exception\LocalizedException;
13+
use Magento\Framework\Model\Context;
14+
use Magento\Framework\Model\ResourceModel\AbstractResource;
15+
use Magento\Framework\Registry;
16+
17+
/**
18+
* Backend model for processing Varnish Fetch Tag Limit settings
19+
*
20+
* Class HeaderLength
21+
*/
22+
class FetchTagLimit extends Value
23+
{
24+
/**
25+
* @var Escaper
26+
*/
27+
private $escaper;
28+
29+
/**
30+
* Ttl constructor.
31+
* @param Context $context
32+
* @param Registry $registry
33+
* @param ScopeConfigInterface $config
34+
* @param TypeListInterface $cacheTypeList
35+
* @param AbstractResource|null $resource
36+
* @param AbstractDb|null $resourceCollection
37+
* @param array $data
38+
* @param Escaper|null $escaper
39+
*/
40+
public function __construct(
41+
Context $context,
42+
Registry $registry,
43+
ScopeConfigInterface $config,
44+
TypeListInterface $cacheTypeList,
45+
?AbstractResource $resource = null,
46+
?AbstractDb $resourceCollection = null,
47+
array $data = [],
48+
?Escaper $escaper = null
49+
) {
50+
parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data);
51+
$this->escaper = $escaper ?: ObjectManager::getInstance()->create(Escaper::class);
52+
}
53+
54+
/**
55+
* Throw exception if HeaderLength data is invalid or empty
56+
*
57+
* @return $this
58+
* @throws LocalizedException
59+
*/
60+
public function beforeSave()
61+
{
62+
$value = $this->getValue();
63+
if ($value < 0 || !preg_match('/^[0-9]+$/', $value)) {
64+
throw new LocalizedException(
65+
__(
66+
'Fetch tag limit value "%1" is not valid. Please use only numbers equal or greater than 0.',
67+
$this->escaper->escapeHtml($value)
68+
)
69+
);
70+
}
71+
return $this;
72+
}
73+
}

src/etc/adminhtml/system.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<field id="varnish_fetch_tag_limit" type="text" translate="label comment" sortOrder="110"
2020
showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
2121
<label>Varnish fetch tag limit.</label>
22-
<backend_model>IntegerNet\AsyncVarnish\Model\System\Config\Backend\HeaderLength</backend_model>
22+
<backend_model>IntegerNet\AsyncVarnish\Model\System\Config\Backend\FetchTagLimit</backend_model>
2323
<comment>The maximum amount of tags that are fetched in 1 purge request. This can be
2424
set to a fairly high number (1 million by default), unless you run into resource
2525
limits/timeouts.</comment>

0 commit comments

Comments
 (0)