Completed
Pull Request — master (#77)
by
unknown
04:31
created

CaptchaServiceProvider::boot()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 25
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 11
Bugs 3 Features 2
Metric Value
c 11
b 3
f 2
dl 0
loc 25
rs 8.8571
cc 3
eloc 12
nc 3
nop 0
1
<?php
2
3
namespace Mews\Captcha;
4
5
use Illuminate\Support\ServiceProvider;
6
7
/**
8
 * Class CaptchaServiceProvider
9
 * @package Mews\Captcha
10
 */
11
class CaptchaServiceProvider extends ServiceProvider {
12
13
    /**
14
     * Boot the service provider.
15
     *
16
     * @return null
17
     */
18
    public function boot()
19
    {
20
        // Publish configuration files
21
        $this->publishes([
22
            __DIR__.'/../config/captcha.php' => config_path('captcha.php')
23
        ], 'config');
24
25
        // HTTP routing
26
        if (strpos($this->app->version(), 'Lumen') !== false) {
27
            //Laravel Lumen
28
            $this->app->get('captcha[/{config}]', 'Mews\Captcha\LumenCaptchaController@getCaptcha');
0 ignored issues
show
Bug introduced by
The method get() does not seem to exist on object<Illuminate\Contra...Foundation\Application>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
29
        } else if (starts_with($this->app->version(), '5.2.') !== false) {
30
            //Laravel 5.2.x
31
            $this->app['router']->get('captcha/{config?}', '\Mews\Captcha\CaptchaController@getCaptcha')->middleware('web');
32
        } else {
33
            //Laravel 5.0.x ~ 5.1.x
34
            $this->app['router']->get('captcha/{config?}', '\Mews\Captcha\CaptchaController@getCaptcha');
35
        }
36
37
        // Validator extensions
38
        $this->app['validator']->extend('captcha', function($attribute, $value, $parameters)
0 ignored issues
show
Unused Code introduced by
The parameter $parameters is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
39
        {
40
            return captcha_check($value);
41
        });
42
    }
43
44
    /**
45
     * Register the service provider.
46
     *
47
     * @return void
48
     */
49
    public function register()
50
    {
51
        // Merge configs
52
        $this->mergeConfigFrom(
53
            __DIR__.'/../config/captcha.php', 'captcha'
54
        );
55
56
        // Bind captcha
57
        $this->app->bind('captcha', function($app)
58
        {
59
            return new Captcha(
60
                $app['Illuminate\Filesystem\Filesystem'],
61
                $app['Illuminate\Config\Repository'],
62
                $app['Intervention\Image\ImageManager'],
63
                $app['Illuminate\Session\Store'],
64
                $app['Illuminate\Hashing\BcryptHasher'],
65
                $app['Illuminate\Support\Str']
66
            );
67
        });
68
    }
69
70
}
71