Completed
Push — master ( 9539c9...6ce7ae )
by ARCANEDEV
12s
created

ValidatorServiceProvider::validator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php namespace Arcanesoft\Auth\Providers;
2
3
use Arcanedev\Support\ServiceProvider;
4
use Closure;
5
6
/**
7
 * Class     ValidatorServiceProvider
8
 *
9
 * @package  Arcanesoft\Auth\Providers
10
 * @author   ARCANEDEV <[email protected]>
11
 */
12
class ValidatorServiceProvider extends ServiceProvider
13
{
14
    /* -----------------------------------------------------------------
15
     |  Main Methods
16
     | -----------------------------------------------------------------
17
     */
18
19
    /**
20
     * Register the service provider.
21
     */
22 10
    public function register()
23
    {
24
        //
25 10
    }
26
27
    /**
28
     * Boot the service provider.
29
     */
30 10
    public function boot()
31
    {
32 10
        $this->registerUserValidators();
33 10
    }
34
35
    /* -----------------------------------------------------------------
36
     |  Validators
37
     | -----------------------------------------------------------------
38
     */
39
40
    /**
41
     * Register the user validators.
42
     */
43 10
    private function registerUserValidators()
44
    {
45 10
        $this->extendValidator(
46 10
            'user_password',
47 10
            \Arcanesoft\Auth\Validators\UserValidator::class,
48 10
            function($message, $attribute) {
49
                $message = 'auth::validation.user_password';
50
51
                return str_replace(':attribute', $attribute, trans($message));
52 10
            }
53
        );
54 10
    }
55
56
    /* -----------------------------------------------------------------
57
     |  Other Methods
58
     | -----------------------------------------------------------------
59
     */
60
61
    /**
62
     * Get the validator instance.
63
     *
64
     * @return \Illuminate\Validation\Factory
65
     */
66 10
    private function validator()
67
    {
68 10
        return $this->app['validator'];
69
    }
70
71
    /**
72
     * Extend validator.
73
     *
74
     * @param  string         $name
75
     * @param  string         $class
76
     * @param  \Closure|null  $replacer
77
     */
78 10
    private function extendValidator($name, $class, Closure $replacer = null)
79
    {
80 10
        $this->validator()->extend($name, "{$class}@validate" . studly_case($name));
81
82 10
        if ( ! is_null($replacer))
83 10
            $this->validator()->replacer($name, $replacer);
84 10
    }
85
}
86