Captcha.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. namespace Magento\Captcha\CustomerData;
  8. use Magento\Customer\CustomerData\SectionSourceInterface;
  9. /**
  10. * Captcha section
  11. */
  12. class Captcha extends \Magento\Framework\DataObject implements SectionSourceInterface
  13. {
  14. /**
  15. * @var array
  16. */
  17. private $formIds;
  18. /**
  19. * @var \Magento\Captcha\Helper\Data
  20. */
  21. private $helper;
  22. /**
  23. * @param \Magento\Captcha\Helper\Data $helper
  24. * @param array $formIds
  25. * @param array $data
  26. * @codeCoverageIgnore
  27. */
  28. public function __construct(
  29. \Magento\Captcha\Helper\Data $helper,
  30. array $formIds,
  31. array $data = []
  32. ) {
  33. parent::__construct($data);
  34. $this->helper = $helper;
  35. $this->formIds = $formIds;
  36. }
  37. /**
  38. * @inheritdoc
  39. */
  40. public function getSectionData() :array
  41. {
  42. $data = [];
  43. foreach ($this->formIds as $formId) {
  44. $captchaModel = $this->helper->getCaptcha($formId);
  45. $data[$formId] = [
  46. 'isRequired' => $captchaModel->isRequired(),
  47. 'timestamp' => time()
  48. ];
  49. }
  50. return $data;
  51. }
  52. }