-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathUserCaptchaConfiguration.php
More file actions
91 lines (74 loc) · 2.07 KB
/
UserCaptchaConfiguration.php
File metadata and controls
91 lines (74 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
namespace Captcha\Bundle\CaptchaBundle\Support;
use Captcha\Bundle\CaptchaBundle\Support\Exception\FileNotFoundException;
use Symfony\Component\HttpKernel\Kernel;
final class UserCaptchaConfiguration
{
/**
* Disable instance creation.
*/
private function __construct()
{
}
/**
* Get user's captcha configuration by captcha id.
*
* @param string $captchaId
*
* @return array
*/
public static function get($captchaId)
{
$captchaId = trim($captchaId);
$captchaIdTemp = strtolower($captchaId);
$configs = array_change_key_case(self::all(), CASE_LOWER);
$config = (is_array($configs) && array_key_exists($captchaIdTemp, $configs))
? $configs[$captchaIdTemp]
: null;
if (is_array($config)) {
$config['CaptchaId'] = $captchaId;
}
return $config;
}
/**
* Get all user's captcha configuration.
*
* @return array
*
* @throw FileNotFoundException
*/
public static function all()
{
$configPath = Path::getConfigDirPath('captcha.php');
if (!file_exists($configPath)) {
if (Kernel::VERSION < 4) {
$path = 'app/config/captcha.php';
} else {
$path = 'config/packages/captcha.php';
}
throw new FileNotFoundException(sprintf('File "%s" could not be found.', $path));
}
$captchaConfigs = require $configPath;
return $captchaConfigs;
}
/**
* Save user's captcha configuration options.
*
* @param array $config
*
* @return void
*/
public static function save(array $config)
{
unset($config['CaptchaId']);
unset($config['UserInputID']);
if (empty($config)) {
return;
}
$settings = \CaptchaConfiguration::LoadSettings();
foreach ($config as $option => $value) {
$settings->$option = $value;
}
\CaptchaConfiguration::SaveSettings($settings);
}
}