| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* @copyright © Melograno Venture Studio. All rights reserved. |
| 5 |
* @licence See COPYING.md for license details. |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace IvyForms\Services\Security\Recaptcha; |
| 9 |
|
| 10 |
// phpcs:disable PSR1.Files.SideEffects |
| 11 |
if (!defined('ABSPATH')) { |
| 12 |
exit; // Exit if accessed directly |
| 13 |
} |
| 14 |
|
| 15 |
use IvyForms\Services\Security\Common\CaptchaServiceInterface; |
| 16 |
|
| 17 |
/** |
| 18 |
* Provides reCAPTCHA frontend configuration |
| 19 |
* |
| 20 |
* @package IvyForms\Services\Security\Recaptcha |
| 21 |
*/ |
| 22 |
class RecaptchaConfigProvider |
| 23 |
{ |
| 24 |
/** |
| 25 |
* Get reCAPTCHA configuration for frontend |
| 26 |
* |
| 27 |
* @param CaptchaServiceInterface|null $service |
| 28 |
* @return array<string, mixed> |
| 29 |
*/ |
| 30 |
public function getConfig(?CaptchaServiceInterface $service): array |
| 31 |
{ |
| 32 |
$config = [ |
| 33 |
'configured' => false, |
| 34 |
'type' => 'v2', |
| 35 |
'siteKey' => '', |
| 36 |
'scriptUrl' => '', |
| 37 |
'size' => 'normal' |
| 38 |
]; |
| 39 |
|
| 40 |
if ($service && $service->isConfigured()) { |
| 41 |
$recaptchaConfig = $service->getFrontendConfig( |
| 42 |
$service->getType(), |
| 43 |
$service->getSiteKey() |
| 44 |
); |
| 45 |
$recaptchaConfig['configured'] = true; |
| 46 |
return $recaptchaConfig; |
| 47 |
} |
| 48 |
|
| 49 |
return $config; |
| 50 |
} |
| 51 |
} |
| 52 |
|