-
Notifications
You must be signed in to change notification settings - Fork 193
Expand file tree
/
Copy pathRecaptcha.php
More file actions
104 lines (83 loc) · 2.36 KB
/
Recaptcha.php
File metadata and controls
104 lines (83 loc) · 2.36 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
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
namespace Greggilbert\Recaptcha;
class Recaptcha
{
protected $service;
protected $config = [ ];
protected $dataParameterKeys = [ 'theme', 'type', 'callback', 'tabindex', 'expired-callback' ];
public function __construct($service, $config)
{
$this->service = $service;
$this->config = $config;
}
/**
* View render
*
* @param $parameter
* @return \Greggilbert\Recaptcha\view
*/
public function instantRender($parameter)
{
$options = [];
if (is_string($parameter)) {
$this->config['public_key'] = $parameter;
}
if (!empty($parameter['public_key'])) {
$this->config['public_key'] = $parameter['public_key'];
$options = $parameter;
}
// Array
return $this->render($options);
}
/**
* Render the recaptcha
*
* @param array $options
*
* @return view
*/
public function render($options = [ ])
{
$mergedOptions = array_merge($this->config['options'], $options);
$data = [
'public_key' => $this->config['public_key'],
'options' => $mergedOptions,
'dataParams' => $this->extractDataParams($mergedOptions),
];
if (array_key_exists('lang', $mergedOptions) && "" !== trim($mergedOptions['lang'])) {
$data['lang'] = $mergedOptions['lang'];
}
$view = $this->getView($options);
return app('view')->make($view, $data);
}
/**
* Generate the view path
*
* @param array $options
*
* @return string
*/
protected function getView($options = [ ])
{
$view = 'recaptcha::' . $this->service->getTemplate();
$configTemplate = $this->config['template'];
if (array_key_exists('template', $options)) {
$view = $options['template'];
} elseif ("" !== trim($configTemplate)) {
$view = $configTemplate;
}
return $view;
}
/**
* Extract the parameters to be converted to data-* attributes
* See the docs at https://developers.google.com/recaptcha/docs/display
*
* @param array $options
*
* @return array
*/
protected function extractDataParams($options = [ ])
{
return array_only($options, $this->dataParameterKeys);
}
}