|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +declare(strict_types=1); |
| 7 | + |
| 8 | +namespace Magento\ReCaptchaReview\Model; |
| 9 | + |
| 10 | +use Magento\Framework\App\Config\ScopeConfigInterface; |
| 11 | +use Magento\ReCaptcha\Model\ConfigEnabledInterface; |
| 12 | +use Magento\ReCaptcha\Model\ConfigInterface; |
| 13 | +use Magento\Store\Model\ScopeInterface; |
| 14 | + |
| 15 | +/** |
| 16 | + * Read configuration from store config |
| 17 | + */ |
| 18 | +class ConfigEnabled implements ConfigEnabledInterface |
| 19 | +{ |
| 20 | + public const XML_PATH_ENABLED_FRONTEND_REVIEW = 'recaptcha/frontend/enabled_review'; |
| 21 | + |
| 22 | + /** |
| 23 | + * @var ConfigInterface |
| 24 | + */ |
| 25 | + private $reCaptchaConfig; |
| 26 | + |
| 27 | + /** |
| 28 | + * @var ScopeConfigInterface |
| 29 | + */ |
| 30 | + private $scopeConfig; |
| 31 | + |
| 32 | + /** |
| 33 | + * @param ConfigInterface $reCaptchaConfig |
| 34 | + * @param ScopeConfigInterface $scopeConfig |
| 35 | + */ |
| 36 | + public function __construct( |
| 37 | + ConfigInterface $reCaptchaConfig, |
| 38 | + ScopeConfigInterface $scopeConfig |
| 39 | + ) { |
| 40 | + $this->reCaptchaConfig = $reCaptchaConfig; |
| 41 | + $this->scopeConfig = $scopeConfig; |
| 42 | + } |
| 43 | + |
| 44 | + /** |
| 45 | + * Return true if enabled on frontend captcha for review |
| 46 | + * @return bool |
| 47 | + */ |
| 48 | + public function isEnabled(): bool |
| 49 | + { |
| 50 | + if (!$this->reCaptchaConfig->isEnabledFrontend()) { |
| 51 | + return false; |
| 52 | + } |
| 53 | + |
| 54 | + return (bool)$this->scopeConfig->getValue( |
| 55 | + static::XML_PATH_ENABLED_FRONTEND_REVIEW, |
| 56 | + ScopeInterface::SCOPE_WEBSITE |
| 57 | + ); |
| 58 | + } |
| 59 | +} |
0 commit comments