Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Ttl.php
Go to the documentation of this file.
1 <?php
8 
12 
18 class Ttl extends \Magento\Framework\App\Config\Value
19 {
23  private $escaper;
24 
36  public function __construct(
37  \Magento\Framework\Model\Context $context,
38  \Magento\Framework\Registry $registry,
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 
56  public function beforeSave()
57  {
58  $value = $this->getValue();
59  if ($value < 0 || !preg_match('/^[0-9]+$/', $value)) {
60  throw new \Magento\Framework\Exception\LocalizedException(
61  __(
62  'Ttl value "%1" is not valid. Please use only numbers equal or greater than zero.',
63  $this->escaper->escapeHtml($value)
64  )
65  );
66  }
67  return $this;
68  }
69 }
$config
Definition: fraud_order.php:17
__()
Definition: __.php:13
$resource
Definition: bulk.php:12
__construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, ScopeConfigInterface $config, \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList, ?\Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, ?\Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[], ?Escaper $escaper=null)
Definition: Ttl.php:36
$value
Definition: gender.phtml:16