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{
18- /**
19- * @var string|null
20- */
21- private ?string $ websiteKey = null ;
22-
2318 /**
2419 * @var float|null
2520 */
2621 private ?float $ minimumScore = null ;
2722
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-
4323 /**
4424 * @var array
4525 */
4626 private array $ uiConfig = [];
4727
48- /**
49- * @var ValidationConfigProvider
50- */
51- private ValidationConfigProvider $ validationConfigProvider ;
52-
5328 /**
5429 * @var ValidationConfigInterface|null
5530 */
5631 private ?ValidationConfigInterface $ validationConfig = null ;
5732
58- /**
59- * @var array
60- */
61- private array $ formTypes ;
62-
6333 /**
6434 * @param UiConfigProvider $uiConfigProvider
6535 * @param ValidationConfigProvider $validationConfigProvider
6636 * @param array $formTypes
6737 */
6838 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
7242 ) {
73- $ this ->formTypes = $ formTypes ;
74- $ this ->uiConfigProvider = $ uiConfigProvider ;
75- $ this ->validationConfigProvider = $ validationConfigProvider ;
7643 }
7744
7845 /**
@@ -82,21 +49,22 @@ public function __construct(
8249 */
8350 public function getWebsiteKey (): string
8451 {
85- if (!$ this ->websiteKey ) {
86- $ this ->websiteKey = $ this ->getUiConfig ()['rendering ' ]['sitekey ' ];
87- }
88- return $ this ->websiteKey ;
52+ return $ this ->getUiConfig ()['rendering ' ]['sitekey ' ] ?? '' ;
8953 }
9054
9155 /**
9256 * Get configured minimum score value
9357 *
94- * @return float
58+ * @return float|null
9559 */
96- public function getMinimumScore (): float
60+ public function getMinimumScore (): ? float
9761 {
9862 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 ();
10068 }
10169 return $ this ->minimumScore ;
10270 }
@@ -108,10 +76,7 @@ public function getMinimumScore(): float
10876 */
10977 public function getBadgePosition (): string
11078 {
111- if (!$ this ->badgePosition ) {
112- $ this ->badgePosition = $ this ->getUiConfig ()['rendering ' ]['badge ' ];
113- }
114- return $ this ->badgePosition ;
79+ return $ this ->getUiConfig ()['rendering ' ]['badge ' ] ?? '' ;
11580 }
11681
11782 /**
@@ -121,10 +86,17 @@ public function getBadgePosition(): string
12186 */
12287 public function getLanguageCode (): string
12388 {
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 ' ] ?? '' ;
128100 }
129101
130102 /**
@@ -158,7 +130,7 @@ public function getValidationConfig(): ValidationConfigInterface
158130 private function getUiConfig (): array
159131 {
160132 if (empty ($ this ->uiConfig )) {
161- $ this ->uiConfig = $ this ->uiConfigProvider ->get ();
133+ $ this ->uiConfig = $ this ->uiConfigProvider ->get () ?? [] ;
162134 }
163135 return $ this ->uiConfig ;
164136 }
@@ -168,8 +140,8 @@ private function getUiConfig(): array
168140 */
169141 public function _resetState (): void
170142 {
171- $ this ->websiteKey = null ;
172143 $ this ->uiConfig = [];
144+ $ this ->minimumScore = null ;
173145 $ this ->validationConfig = null ;
174146 }
175147}
0 commit comments