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
- /**
19
- * @var string|null
20
- */
21
- private ?string $ websiteKey = null ;
22
-
23
18
/**
24
19
* @var float|null
25
20
*/
26
21
private ?float $ minimumScore = null ;
27
22
28
- /**
29
- * @var string|null
30
- */
31
- private ?string $ badgePosition = null ;
32
-
33
- /**
34
- * @var string|null
35
- */
36
- private ?string $ languageCode = null ;
37
-
38
- /**
39
- * @var UiConfigProvider
40
- */
41
- private UiConfigProvider $ uiConfigProvider ;
42
-
43
23
/**
44
24
* @var array
45
25
*/
46
26
private array $ uiConfig = [];
47
27
48
- /**
49
- * @var ValidationConfigProvider
50
- */
51
- private ValidationConfigProvider $ validationConfigProvider ;
52
-
53
28
/**
54
29
* @var ValidationConfigInterface|null
55
30
*/
56
31
private ?ValidationConfigInterface $ validationConfig = null ;
57
32
58
- /**
59
- * @var array
60
- */
61
- private array $ formTypes ;
62
-
63
33
/**
64
34
* @param UiConfigProvider $uiConfigProvider
65
35
* @param ValidationConfigProvider $validationConfigProvider
66
36
* @param array $formTypes
67
37
*/
68
38
public function __construct (
69
- UiConfigProvider $ uiConfigProvider ,
70
- ValidationConfigProvider $ validationConfigProvider ,
71
- array $ formTypes = []
39
+ private readonly UiConfigProvider $ uiConfigProvider ,
40
+ private readonly ValidationConfigProvider $ validationConfigProvider ,
41
+ private readonly array $ formTypes
72
42
) {
73
- $ this ->formTypes = $ formTypes ;
74
- $ this ->uiConfigProvider = $ uiConfigProvider ;
75
- $ this ->validationConfigProvider = $ validationConfigProvider ;
76
43
}
77
44
78
45
/**
@@ -82,21 +49,22 @@ public function __construct(
82
49
*/
83
50
public function getWebsiteKey (): string
84
51
{
85
- if (!$ this ->websiteKey ) {
86
- $ this ->websiteKey = $ this ->getUiConfig ()['rendering ' ]['sitekey ' ];
87
- }
88
- return $ this ->websiteKey ;
52
+ return $ this ->getUiConfig ()['rendering ' ]['sitekey ' ] ?? '' ;
89
53
}
90
54
91
55
/**
92
56
* Get configured minimum score value
93
57
*
94
- * @return float
58
+ * @return float|null
95
59
*/
96
- public function getMinimumScore (): float
60
+ public function getMinimumScore (): ? float
97
61
{
98
62
if (!$ this ->minimumScore ) {
99
- $ this ->minimumScore = $ this ->validationConfig ->getExtensionAttributes ()->getScoreThreshold ();
63
+ $ validationProvider = $ this ->validationConfigProvider ->get ();
64
+ if ($ validationProvider ->getExtensionAttributes () === null ) {
65
+ return $ this ->minimumScore ;
66
+ }
67
+ $ this ->minimumScore = $ validationProvider ->getExtensionAttributes ()->getScoreThreshold ();
100
68
}
101
69
return $ this ->minimumScore ;
102
70
}
@@ -108,10 +76,7 @@ public function getMinimumScore(): float
108
76
*/
109
77
public function getBadgePosition (): string
110
78
{
111
- if (!$ this ->badgePosition ) {
112
- $ this ->badgePosition = $ this ->getUiConfig ()['rendering ' ]['badge ' ];
113
- }
114
- return $ this ->badgePosition ;
79
+ return $ this ->getUiConfig ()['rendering ' ]['badge ' ] ?? '' ;
115
80
}
116
81
117
82
/**
@@ -121,10 +86,17 @@ public function getBadgePosition(): string
121
86
*/
122
87
public function getLanguageCode (): string
123
88
{
124
- if (!$ this ->languageCode ) {
125
- $ this ->languageCode = $ this ->getUiConfig ()['rendering ' ]['hl ' ];
126
- }
127
- return $ this ->languageCode ;
89
+ return $ this ->getUiConfig ()['rendering ' ]['hl ' ] ?? '' ;
90
+ }
91
+
92
+ /**
93
+ * Get configured captcha's theme
94
+ *
95
+ * @return string
96
+ */
97
+ public function getTheme (): string
98
+ {
99
+ return $ this ->getUiConfig ()['rendering ' ]['theme ' ] ?? '' ;
128
100
}
129
101
130
102
/**
@@ -158,7 +130,7 @@ public function getValidationConfig(): ValidationConfigInterface
158
130
private function getUiConfig (): array
159
131
{
160
132
if (empty ($ this ->uiConfig )) {
161
- $ this ->uiConfig = $ this ->uiConfigProvider ->get ();
133
+ $ this ->uiConfig = $ this ->uiConfigProvider ->get () ?? [] ;
162
134
}
163
135
return $ this ->uiConfig ;
164
136
}
@@ -168,8 +140,8 @@ private function getUiConfig(): array
168
140
*/
169
141
public function _resetState (): void
170
142
{
171
- $ this ->websiteKey = null ;
172
143
$ this ->uiConfig = [];
144
+ $ this ->minimumScore = null ;
173
145
$ this ->validationConfig = null ;
174
146
}
175
147
}
0 commit comments