These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php namespace Arcanedev\NoCaptcha; |
||
2 | |||
3 | use Arcanedev\Support\PackageServiceProvider as ServiceProvider; |
||
4 | |||
5 | /** |
||
6 | * Class NoCaptchaServiceProvider |
||
7 | * |
||
8 | * @package Arcanedev\NoCaptcha |
||
9 | * @author ARCANEDEV <[email protected]> |
||
10 | */ |
||
11 | class NoCaptchaServiceProvider extends ServiceProvider |
||
12 | { |
||
13 | /* ------------------------------------------------------------------------------------------------ |
||
14 | | Properties |
||
15 | | ------------------------------------------------------------------------------------------------ |
||
16 | */ |
||
17 | /** |
||
18 | * Vendor name. |
||
19 | * |
||
20 | * @var string |
||
21 | */ |
||
22 | protected $vendor = 'arcanedev'; |
||
23 | |||
24 | /** |
||
25 | * Package name. |
||
26 | * |
||
27 | * @var string |
||
28 | */ |
||
29 | protected $package = 'no-captcha'; |
||
30 | |||
31 | /* ------------------------------------------------------------------------------------------------ |
||
32 | | Getters & Setters |
||
33 | | ------------------------------------------------------------------------------------------------ |
||
34 | */ |
||
35 | /** |
||
36 | * Get the base path of the package. |
||
37 | * |
||
38 | * @return string |
||
39 | */ |
||
40 | 72 | public function getBasePath() |
|
41 | { |
||
42 | 72 | return dirname(__DIR__); |
|
43 | } |
||
44 | |||
45 | /* ------------------------------------------------------------------------------------------------ |
||
46 | | Main Functions |
||
47 | | ------------------------------------------------------------------------------------------------ |
||
48 | */ |
||
49 | /** |
||
50 | * Register the service provider. |
||
51 | */ |
||
52 | 72 | public function register() |
|
53 | { |
||
54 | 72 | $this->registerConfig(); |
|
55 | 72 | $this->registerNoCaptcha(); |
|
56 | 72 | } |
|
57 | |||
58 | /** |
||
59 | * Bootstrap the application events. |
||
60 | */ |
||
61 | 72 | public function boot() |
|
62 | { |
||
63 | 72 | parent::boot(); |
|
64 | |||
65 | 72 | $this->publishConfig(); |
|
0 ignored issues
–
show
|
|||
66 | 72 | $this->registerValidatorRules($this->app); |
|
67 | 72 | $this->registerFormMacros($this->app); |
|
68 | 72 | } |
|
69 | |||
70 | /** |
||
71 | * Get the services provided by the provider. |
||
72 | * |
||
73 | * @return array |
||
74 | */ |
||
75 | 12 | public function provides() |
|
76 | { |
||
77 | return [ |
||
78 | 12 | 'arcanedev.no-captcha', |
|
79 | \Arcanedev\NoCaptcha\Contracts\NoCaptcha::class |
||
80 | 9 | ]; |
|
81 | } |
||
82 | |||
83 | /* ------------------------------------------------------------------------------------------------ |
||
84 | | Other Functions |
||
85 | | ------------------------------------------------------------------------------------------------ |
||
86 | */ |
||
87 | /** |
||
88 | * Register NoCaptcha service. |
||
89 | */ |
||
90 | 72 | private function registerNoCaptcha() |
|
91 | { |
||
92 | $this->app->bind('arcanedev.no-captcha', function($app) { |
||
93 | /** @var \Illuminate\Config\Repository $config */ |
||
94 | 60 | $config = $app['config']; |
|
95 | |||
96 | 60 | return new NoCaptcha( |
|
97 | 60 | $config->get('no-captcha.secret'), |
|
98 | 60 | $config->get('no-captcha.sitekey'), |
|
99 | 60 | $config->get('no-captcha.lang'), |
|
100 | 60 | $config->get('no-captcha.attributes', []) |
|
101 | 45 | ); |
|
102 | 72 | }); |
|
103 | |||
104 | 72 | $this->app->bind( |
|
105 | 72 | \Arcanedev\NoCaptcha\Contracts\NoCaptcha::class, |
|
106 | 18 | 'arcanedev.no-captcha' |
|
107 | 54 | ); |
|
108 | 72 | } |
|
109 | |||
110 | /** |
||
111 | * Register Validator rules. |
||
112 | * |
||
113 | * @param \Illuminate\Foundation\Application $app |
||
114 | */ |
||
115 | 72 | private function registerValidatorRules($app) |
|
116 | { |
||
117 | $app['validator']->extend('captcha', function($attribute, $value) use ($app) { |
||
118 | 36 | unset($attribute); |
|
119 | 36 | $ip = $app['request']->getClientIp(); |
|
120 | |||
121 | 36 | return $app['arcanedev.no-captcha']->verify($value, $ip); |
|
122 | 72 | }); |
|
123 | 72 | } |
|
124 | |||
125 | /** |
||
126 | * Register Form Macros. |
||
127 | * |
||
128 | * @param \Illuminate\Foundation\Application $app |
||
129 | */ |
||
130 | 72 | private function registerFormMacros($app) |
|
131 | { |
||
132 | 72 | if ($app->bound('form')) { |
|
133 | 72 | $app['form']->macro('captcha', function($name, array $attributes = []) use ($app) { |
|
134 | 12 | return $app['arcanedev.no-captcha']->display($name, $attributes); |
|
135 | 72 | }); |
|
136 | 54 | } |
|
137 | 72 | } |
|
138 | } |
||
139 |
If you implement
__call
and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__call
is implemented by a parent class and only the child class knows which methods exist: