Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Data.php
Go to the documentation of this file.
1 <?php
7 
11 class Data
12 {
16  protected $_scopeConfig;
17 
21  public function __construct(\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig)
22  {
23  $this->_scopeConfig = $scopeConfig;
24  }
25 
29  const XML_PATH_CLEANUP_PROBABILITY = 'oauth/cleanup/cleanup_probability';
30 
31  const XML_PATH_CLEANUP_EXPIRATION_PERIOD = 'oauth/cleanup/expiration_period';
32 
39 
43  const XML_PATH_CONSUMER_EXPIRATION_PERIOD = 'oauth/consumer/expiration_period';
44 
45  const XML_PATH_CONSUMER_POST_MAXREDIRECTS = 'oauth/consumer/post_maxredirects';
46 
47  const XML_PATH_CONSUMER_POST_TIMEOUT = 'oauth/consumer/post_timeout';
48 
55 
57 
65  public function isCleanupProbability()
66  {
67  // Safe get cleanup probability value from system configuration
68  $configValue = (int)$this->_scopeConfig->getValue(self::XML_PATH_CLEANUP_PROBABILITY);
69  return $configValue > 0 ? 1 == \Magento\Framework\Math\Random::getRandomNumber(1, $configValue) : false;
70  }
71 
77  public function getCleanupExpirationPeriod()
78  {
79  $minutes = (int)$this->_scopeConfig->getValue(self::XML_PATH_CLEANUP_EXPIRATION_PERIOD);
80  return $minutes > 0 ? $minutes : self::CLEANUP_EXPIRATION_PERIOD_DEFAULT;
81  }
82 
88  public function getConsumerExpirationPeriod()
89  {
90  $seconds = (int)$this->_scopeConfig->getValue(self::XML_PATH_CONSUMER_EXPIRATION_PERIOD);
91  return $seconds > 0 ? $seconds : self::CONSUMER_EXPIRATION_PERIOD_DEFAULT;
92  }
93 
99  public function getConsumerPostMaxRedirects()
100  {
101  $redirects = (int)$this->_scopeConfig->getValue(self::XML_PATH_CONSUMER_POST_MAXREDIRECTS);
102  return $redirects > 0 ? $redirects : 0;
103  }
104 
110  public function getConsumerPostTimeout()
111  {
112  $seconds = (int)$this->_scopeConfig->getValue(self::XML_PATH_CONSUMER_POST_TIMEOUT);
113  return $seconds > 0 ? $seconds : self::CONSUMER_POST_TIMEOUT_DEFAULT;
114  }
115 
121  public function getCustomerTokenLifetime()
122  {
123  $hours = (int)$this->_scopeConfig->getValue('oauth/access_token_lifetime/customer');
124  return $hours > 0 ? $hours : 0;
125  }
126 
132  public function getAdminTokenLifetime()
133  {
134  $hours = (int)$this->_scopeConfig->getValue('oauth/access_token_lifetime/admin');
135  return $hours > 0 ? $hours : 0;
136  }
137 }
static getRandomNumber($min=0, $max=null)
Definition: Random.php:62
__construct(\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig)
Definition: Data.php:21