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
|
12 |
|
public function register() |
23
|
|
|
{ |
24
|
|
|
// |
25
|
12 |
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Boot the service provider. |
29
|
|
|
*/ |
30
|
12 |
|
public function boot() |
31
|
|
|
{ |
32
|
12 |
|
$this->registerUserValidators(); |
33
|
12 |
|
} |
34
|
|
|
|
35
|
|
|
/* ----------------------------------------------------------------- |
36
|
|
|
| Validators |
37
|
|
|
| ----------------------------------------------------------------- |
38
|
|
|
*/ |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Register the user validators. |
42
|
|
|
*/ |
43
|
12 |
|
private function registerUserValidators() |
44
|
|
|
{ |
45
|
12 |
|
$this->extendValidator( |
46
|
12 |
|
'user_password', |
47
|
12 |
|
\Arcanesoft\Auth\Validators\UserValidator::class, |
48
|
6 |
|
function($message, $attribute) { |
49
|
|
|
$message = 'auth::validation.user_password'; |
50
|
|
|
|
51
|
|
|
return str_replace(':attribute', $attribute, trans($message)); |
52
|
6 |
|
} |
53
|
6 |
|
); |
54
|
12 |
|
} |
55
|
|
|
|
56
|
|
|
/* ----------------------------------------------------------------- |
57
|
|
|
| Other Methods |
58
|
|
|
| ----------------------------------------------------------------- |
59
|
|
|
*/ |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Get the validator instance. |
63
|
|
|
* |
64
|
|
|
* @return \Illuminate\Validation\Factory |
65
|
|
|
*/ |
66
|
12 |
|
private function validator() |
67
|
|
|
{ |
68
|
12 |
|
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
|
12 |
|
private function extendValidator($name, $class, Closure $replacer = null) |
79
|
|
|
{ |
80
|
12 |
|
$this->validator()->extend($name, "{$class}@validate" . studly_case($name)); |
81
|
|
|
|
82
|
12 |
|
if ( ! is_null($replacer)) |
83
|
12 |
|
$this->validator()->replacer($name, $replacer); |
84
|
12 |
|
} |
85
|
|
|
} |
86
|
|
|
|