1
1
<?php
2
-
3
2
/**
4
3
* Copyright © Magento, Inc. All rights reserved.
5
4
* See COPYING.txt for license details.
12
11
use Magento \ReCaptchaValidationApi \Api \Data \ValidationConfigInterface ;
13
12
use Magento \ReCaptchaVersion3Invisible \Model \Frontend \UiConfigProvider ;
14
13
use Magento \ReCaptchaVersion3Invisible \Model \Frontend \ValidationConfigProvider ;
14
+ use Magento \ReCaptchaWebapiGraphQl \Model \Adapter \ReCaptchaConfigInterface ;
15
15
16
- class Config implements ResetAfterRequestInterface
16
+ class Config implements ReCaptchaConfigInterface, ResetAfterRequestInterface
17
17
{
18
18
/**
19
19
* @var string|null
@@ -35,21 +35,11 @@ class Config implements ResetAfterRequestInterface
35
35
*/
36
36
private ?string $ languageCode = null ;
37
37
38
- /**
39
- * @var UiConfigProvider
40
- */
41
- private UiConfigProvider $ uiConfigProvider ;
42
-
43
38
/**
44
39
* @var array
45
40
*/
46
41
private array $ uiConfig = [];
47
42
48
- /**
49
- * @var ValidationConfigProvider
50
- */
51
- private ValidationConfigProvider $ validationConfigProvider ;
52
-
53
43
/**
54
44
* @var ValidationConfigInterface|null
55
45
*/
@@ -66,13 +56,11 @@ class Config implements ResetAfterRequestInterface
66
56
* @param array $formTypes
67
57
*/
68
58
public function __construct (
69
- UiConfigProvider $ uiConfigProvider ,
70
- ValidationConfigProvider $ validationConfigProvider ,
59
+ private readonly UiConfigProvider $ uiConfigProvider ,
60
+ private readonly ValidationConfigProvider $ validationConfigProvider ,
71
61
array $ formTypes = []
72
62
) {
73
63
$ this ->formTypes = $ formTypes ;
74
- $ this ->uiConfigProvider = $ uiConfigProvider ;
75
- $ this ->validationConfigProvider = $ validationConfigProvider ;
76
64
}
77
65
78
66
/**
@@ -91,12 +79,16 @@ public function getWebsiteKey(): string
91
79
/**
92
80
* Get configured minimum score value
93
81
*
94
- * @return float
82
+ * @return float|null
95
83
*/
96
- public function getMinimumScore (): float
84
+ public function getMinimumScore (): float | null
97
85
{
98
86
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 ();
100
92
}
101
93
return $ this ->minimumScore ;
102
94
}
@@ -114,6 +106,16 @@ public function getBadgePosition(): string
114
106
return $ this ->badgePosition ;
115
107
}
116
108
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
+
117
119
/**
118
120
* Get code of language to send notifications
119
121
*
@@ -155,7 +157,7 @@ public function getValidationConfig(): ValidationConfigInterface
155
157
*
156
158
* @return array
157
159
*/
158
- private function getUiConfig (): array
160
+ public function getUiConfig (): array
159
161
{
160
162
if (empty ($ this ->uiConfig )) {
161
163
$ this ->uiConfig = $ this ->uiConfigProvider ->get ();
@@ -168,8 +170,11 @@ private function getUiConfig(): array
168
170
*/
169
171
public function _resetState (): void
170
172
{
171
- $ this ->websiteKey = null ;
172
173
$ this ->uiConfig = [];
174
+ $ this ->websiteKey = null ;
175
+ $ this ->minimumScore = null ;
176
+ $ this ->languageCode = null ;
177
+ $ this ->badgePosition = null ;
173
178
$ this ->validationConfig = null ;
174
179
}
175
180
}
0 commit comments