Completed
Push — master ( f40498...e3ae3a )
by ARCANEDEV
03:17
created

ValidatorServiceProvider::boot()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
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
use Illuminate\Contracts\Foundation\Application;
6
7
/**
8
 * Class     ValidatorServiceProvider
9
 *
10
 * @package  Arcanesoft\Auth\Providers
11
 * @author   ARCANEDEV <[email protected]>
12
 */
13
class ValidatorServiceProvider extends ServiceProvider
14
{
15
    /* ------------------------------------------------------------------------------------------------
16
     |  Properties
17
     | ------------------------------------------------------------------------------------------------
18
     */
19
    /**
20
     * The Validator instance.
21
     *
22
     * @var \Illuminate\Validation\Factory
23
     */
24
    protected $validator;
25
26
    /* ------------------------------------------------------------------------------------------------
27
     |  Constructor
28
     | ------------------------------------------------------------------------------------------------
29
     */
30
    /**
31
     * {@inheritdoc}
32
     */
33 24
    public function __construct(Application $app)
34
    {
35 24
        parent::__construct($app);
36
37
        /** @var  \    $validator */
38 24
        $this->validator = $app['validator'];
39 24
    }
40
41
    /* ------------------------------------------------------------------------------------------------
42
     |  Main Functions
43
     | ------------------------------------------------------------------------------------------------
44
     */
45
    /**
46
     * {@inheritdoc}
47
     */
48 24
    public function boot()
49
    {
50 24
        $this->registerUserValidators();
51 24
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56 24
    public function register()
57
    {
58
        //
59 24
    }
60
61
    /* ------------------------------------------------------------------------------------------------
62
     |  Validators
63
     | ------------------------------------------------------------------------------------------------
64
     */
65
    /**
66
     * Register the user validators.
67
     */
68 24
    private function registerUserValidators()
69
    {
70 24
        $class = \Arcanesoft\Auth\Validators\UserValidator::class;
71
72 24
        $this->extendValidator('user_password', $class, function($message, $attribute) {
73
            $message = 'auth::validation.user_password';
74
75
            return str_replace(':attribute', $attribute, trans($message));
76 24
        });
77 24
    }
78
79
    /* ------------------------------------------------------------------------------------------------
80
     |  Other Functions
81
     | ------------------------------------------------------------------------------------------------
82
     */
83
    /**
84
     * Extend validator.
85
     *
86
     * @param  string         $name
87
     * @param  string         $class
88
     * @param  \Closure|null  $replacer
89
     */
90 24
    private function extendValidator($name, $class, Closure $replacer = null)
91
    {
92 24
        $this->validator->extend($name, $class . '@validate' . studly_case($name));
93
94 24
        if ( ! is_null($replacer)) {
95 24
            $this->validator->replacer($name, $replacer);
96 18
        }
97 24
    }
98
}
99