11<?php
2-
32/**
43 * Copyright © Magento, Inc. All rights reserved.
54 * See COPYING.txt for license details.
1211use Magento \ReCaptchaValidationApi \Api \Data \ValidationConfigInterface ;
1312use Magento \ReCaptchaVersion3Invisible \Model \Frontend \UiConfigProvider ;
1413use Magento \ReCaptchaVersion3Invisible \Model \Frontend \ValidationConfigProvider ;
14+ use Magento \ReCaptchaWebapiGraphQl \Model \Adapter \ReCaptchaConfigInterface ;
1515
16- class Config implements ResetAfterRequestInterface
16+ class Config implements ReCaptchaConfigInterface, ResetAfterRequestInterface
1717{
1818 /**
1919 * @var string|null
@@ -35,21 +35,11 @@ class Config implements ResetAfterRequestInterface
3535 */
3636 private ?string $ languageCode = null ;
3737
38- /**
39- * @var UiConfigProvider
40- */
41- private UiConfigProvider $ uiConfigProvider ;
42-
4338 /**
4439 * @var array
4540 */
4641 private array $ uiConfig = [];
4742
48- /**
49- * @var ValidationConfigProvider
50- */
51- private ValidationConfigProvider $ validationConfigProvider ;
52-
5343 /**
5444 * @var ValidationConfigInterface|null
5545 */
@@ -66,13 +56,11 @@ class Config implements ResetAfterRequestInterface
6656 * @param array $formTypes
6757 */
6858 public function __construct (
69- UiConfigProvider $ uiConfigProvider ,
70- ValidationConfigProvider $ validationConfigProvider ,
59+ private readonly UiConfigProvider $ uiConfigProvider ,
60+ private readonly ValidationConfigProvider $ validationConfigProvider ,
7161 array $ formTypes = []
7262 ) {
7363 $ this ->formTypes = $ formTypes ;
74- $ this ->uiConfigProvider = $ uiConfigProvider ;
75- $ this ->validationConfigProvider = $ validationConfigProvider ;
7664 }
7765
7866 /**
@@ -91,12 +79,16 @@ public function getWebsiteKey(): string
9179 /**
9280 * Get configured minimum score value
9381 *
94- * @return float
82+ * @return float|null
9583 */
96- public function getMinimumScore (): float
84+ public function getMinimumScore (): float | null
9785 {
9886 if (!$ this ->minimumScore ) {
99- $ this ->minimumScore = $ this ->validationConfig ->getExtensionAttributes ()->getScoreThreshold ();
87+ $ validationProvider = $ this ->validationConfigProvider ->get ();
88+ if ($ validationProvider ->getExtensionAttributes () === null ) {
89+ return $ this ->minimumScore ;
90+ }
91+ $ this ->minimumScore = $ validationProvider ->getExtensionAttributes ()->getScoreThreshold ();
10092 }
10193 return $ this ->minimumScore ;
10294 }
@@ -114,6 +106,16 @@ public function getBadgePosition(): string
114106 return $ this ->badgePosition ;
115107 }
116108
109+ /**
110+ * Get configured captcha's theme
111+ *
112+ * @return string
113+ */
114+ public function getTheme (): string
115+ {
116+ return $ this ->getUiConfig ()['rendering ' ]['theme ' ];
117+ }
118+
117119 /**
118120 * Get code of language to send notifications
119121 *
@@ -155,7 +157,7 @@ public function getValidationConfig(): ValidationConfigInterface
155157 *
156158 * @return array
157159 */
158- private function getUiConfig (): array
160+ public function getUiConfig (): array
159161 {
160162 if (empty ($ this ->uiConfig )) {
161163 $ this ->uiConfig = $ this ->uiConfigProvider ->get ();
@@ -168,8 +170,11 @@ private function getUiConfig(): array
168170 */
169171 public function _resetState (): void
170172 {
171- $ this ->websiteKey = null ;
172173 $ this ->uiConfig = [];
174+ $ this ->websiteKey = null ;
175+ $ this ->minimumScore = null ;
176+ $ this ->languageCode = null ;
177+ $ this ->badgePosition = null ;
173178 $ this ->validationConfig = null ;
174179 }
175180}
0 commit comments