CaptchaServiceProvider   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 6
dl 0
loc 57
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 17 1
A register() 0 19 2
A provides() 0 4 1
1
<?php
2
3
namespace Vicens\Captcha\Providers;
4
5
use Vicens\Captcha\Captcha;
6
use Illuminate\Support\Arr;
7
use Illuminate\Support\Facades\Config;
8
use Illuminate\Support\ServiceProvider;
9
use Illuminate\Support\Facades\Validator;
10
11
class CaptchaServiceProvider extends ServiceProvider
12
{
13
14
    /**
15
     * boot
16
     */
17
    public function boot()
18
    {
19
        // 发布配置文件
20
        $this->publishes([
21
            __DIR__ . '/../config.php' => config_path('captcha.php')
22
        ], 'config');
23
24
        // 注册路由
25
        $this->loadRoutesFrom(__DIR__ . '/../routes.php');
26
27
        // 注册验证器
28
        Validator::extend('captcha', function ($attribute, $value) {
29
30
            return $this->app['captcha']->check($value);
31
        });
32
33
    }
34
35
    /**
36
     * register
37
     */
38
    public function register()
39
    {
40
41
        // 合并配置项
42
        $this->mergeConfigFrom(__DIR__ . '/../config.php', 'captcha');
43
44
        // 注册服务
45
        $this->app->singleton('captcha', function () {
46
47
            $config = Config::get('captcha', array());
48
49
            if (Arr::get($config, 'debug') === null) {
50
                // 自动开启调试模型
51
                Arr::set($config, 'debug', Config::get('app.debug', false));
52
            }
53
54
            return new Captcha($config);
55
        });
56
    }
57
58
    /**
59
     * provides
60
     *
61
     * @return string[]
62
     */
63
    public function provides()
64
    {
65
        return ['captcha'];
66
    }
67
}
68