6
6
7
7
namespace Magento \PageCache \Model \System \Config \Backend ;
8
8
9
+ use Magento \Framework \App \ObjectManager ;
10
+ use Magento \Framework \Escaper ;
11
+ use Magento \Framework \App \Config \ScopeConfigInterface ;
12
+
9
13
/**
10
14
* Backend model for processing Public content cache lifetime settings
11
15
*
12
16
* Class Ttl
13
17
*/
14
18
class Ttl extends \Magento \Framework \App \Config \Value
15
19
{
20
+ /**
21
+ * @var Escaper
22
+ */
23
+ private $ escaper ;
24
+
25
+ /**
26
+ * Ttl constructor.
27
+ * @param \Magento\Framework\Model\Context $context
28
+ * @param \Magento\Framework\Registry $registry
29
+ * @param ScopeConfigInterface $config
30
+ * @param \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList
31
+ * @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource
32
+ * @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection
33
+ * @param array $data
34
+ * @param Escaper|null $escaper
35
+ */
36
+ public function __construct (
37
+ \Magento \Framework \Model \Context $ context ,
38
+ \Magento \Framework \Registry $ registry ,
39
+ ScopeConfigInterface $ config ,
40
+ \Magento \Framework \App \Cache \TypeListInterface $ cacheTypeList ,
41
+ ?\Magento \Framework \Model \ResourceModel \AbstractResource $ resource = null ,
42
+ ?\Magento \Framework \Data \Collection \AbstractDb $ resourceCollection = null ,
43
+ array $ data = [],
44
+ ?Escaper $ escaper = null
45
+ ) {
46
+ parent ::__construct ($ context , $ registry , $ config , $ cacheTypeList , $ resource , $ resourceCollection , $ data );
47
+ $ this ->escaper = $ escaper ?: ObjectManager::getInstance ()->create (Escaper::class);
48
+ }
49
+
16
50
/**
17
51
* Throw exception if Ttl data is invalid or empty
18
52
*
@@ -24,7 +58,10 @@ public function beforeSave()
24
58
$ value = $ this ->getValue ();
25
59
if ($ value < 0 || !preg_match ('/^[0-9]+$/ ' , $ value )) {
26
60
throw new \Magento \Framework \Exception \LocalizedException (
27
- __ ('Ttl value "%1" is not valid. Please use only numbers equal or greater than zero. ' , $ value )
61
+ __ (
62
+ 'Ttl value "%1" is not valid. Please use only numbers equal or greater than zero. ' ,
63
+ $ this ->escaper ->escapeHtml ($ value )
64
+ )
28
65
);
29
66
}
30
67
return $ this ;
0 commit comments