ReCaptcha.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. /**
  3. * MageSpecialist
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Open Software License (OSL 3.0)
  8. * that is bundled with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://opensource.org/licenses/osl-3.0.php
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to info@magespecialist.it so we can send you a copy immediately.
  14. *
  15. * @category MSP
  16. * @package MSP_ReCaptcha
  17. * @copyright Copyright (c) 2017 Skeeller srl (http://www.magespecialist.it)
  18. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  19. */
  20. namespace MSP\ReCaptcha\Block\Frontend;
  21. use Magento\Framework\Json\DecoderInterface;
  22. use Magento\Framework\Json\EncoderInterface;
  23. use Magento\Framework\View\Element\Template;
  24. use MSP\ReCaptcha\Model\Config;
  25. use MSP\ReCaptcha\Model\LayoutSettings;
  26. class ReCaptcha extends Template
  27. {
  28. /**
  29. * @var Config
  30. */
  31. private $config;
  32. /**
  33. * @var array
  34. */
  35. private $data;
  36. /**
  37. * @var DecoderInterface
  38. */
  39. private $decoder;
  40. /**
  41. * @var EncoderInterface
  42. */
  43. private $encoder;
  44. /**
  45. * @var LayoutSettings
  46. */
  47. private $layoutSettings;
  48. /**
  49. * ReCaptcha constructor.
  50. * @param Template\Context $context
  51. * @param DecoderInterface $decoder
  52. * @param EncoderInterface $encoder
  53. * @param LayoutSettings $layoutSettings
  54. * @param array $data
  55. */
  56. public function __construct(
  57. Template\Context $context,
  58. DecoderInterface $decoder,
  59. EncoderInterface $encoder,
  60. LayoutSettings $layoutSettings,
  61. array $data = []
  62. ) {
  63. parent::__construct($context, $data);
  64. $this->data = $data;
  65. $this->decoder = $decoder;
  66. $this->encoder = $encoder;
  67. $this->layoutSettings = $layoutSettings;
  68. }
  69. /**
  70. * Get public reCaptcha key
  71. * @return string
  72. */
  73. public function getPublicKey()
  74. {
  75. return $this->config->getPublicKey();
  76. }
  77. /**
  78. * @inheritdoc
  79. */
  80. public function getJsLayout()
  81. {
  82. $layout = $this->decoder->decode(parent::getJsLayout());
  83. $layout['components']['msp-recaptcha']['settings'] = $this->layoutSettings->getCaptchaSettings();
  84. return $this->encoder->encode($layout);
  85. }
  86. }