Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ConfigProvider.php
Go to the documentation of this file.
1 <?php
7 
9 {
13  protected $storeManager;
14 
18  protected $captchaData;
19 
23  protected $formIds;
24 
30  public function __construct(
31  \Magento\Store\Model\StoreManagerInterface $storeManager,
32  \Magento\Captcha\Helper\Data $captchaData,
33  array $formIds
34  ) {
35  $this->storeManager = $storeManager;
36  $this->captchaData = $captchaData;
37  $this->formIds = $formIds;
38  }
39 
43  public function getConfig()
44  {
45  $config = [];
46  foreach ($this->formIds as $formId) {
47  $config['captcha'][$formId] = [
48  'isCaseSensitive' => $this->isCaseSensitive($formId),
49  'imageHeight' => $this->getImageHeight($formId),
50  'imageSrc' => $this->getImageSrc($formId),
51  'refreshUrl' => $this->getRefreshUrl(),
52  'isRequired' => $this->isRequired($formId)
53  ];
54  }
55  return $config;
56  }
57 
64  protected function isCaseSensitive($formId)
65  {
66  return (boolean)$this->getCaptchaModel($formId)->isCaseSensitive();
67  }
68 
75  protected function getImageHeight($formId)
76  {
77  return $this->getCaptchaModel($formId)->getHeight();
78  }
79 
86  protected function getImageSrc($formId)
87  {
88  if ($this->isRequired($formId)) {
89  $captcha = $this->getCaptchaModel($formId);
90  $captcha->generate();
91  return $captcha->getImgSrc();
92  }
93  return '';
94  }
95 
101  protected function getRefreshUrl()
102  {
103  $store = $this->storeManager->getStore();
104  return $store->getUrl('captcha/refresh', ['_secure' => $store->isCurrentlySecure()]);
105  }
106 
113  protected function isRequired($formId)
114  {
115  return (boolean)$this->getCaptchaModel($formId)->isRequired();
116  }
117 
124  protected function getCaptchaModel($formId)
125  {
126  return $this->captchaData->getCaptcha($formId);
127  }
128 }
__construct(\Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Captcha\Helper\Data $captchaData, array $formIds)
$config
Definition: fraud_order.php:17
$captcha
Definition: default.phtml:12