|
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
|
12 |
|
public function __construct(Application $app) |
|
34
|
|
|
{ |
|
35
|
12 |
|
parent::__construct($app); |
|
36
|
|
|
|
|
37
|
12 |
|
$this->validator = $app['validator']; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/* ------------------------------------------------------------------------------------------------ |
|
41
|
|
|
| Main Functions |
|
42
|
|
|
| ------------------------------------------------------------------------------------------------ |
|
43
|
|
|
*/ |
|
44
|
|
|
/** |
|
45
|
|
|
* {@inheritdoc} |
|
46
|
|
|
*/ |
|
47
|
|
|
public function boot() |
|
48
|
|
|
{ |
|
49
|
|
|
$this->registerUserValidators(); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* {@inheritdoc} |
|
54
|
|
|
*/ |
|
55
|
|
|
public function register() |
|
56
|
|
|
{ |
|
57
|
|
|
// |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/* ------------------------------------------------------------------------------------------------ |
|
61
|
|
|
| Validators |
|
62
|
|
|
| ------------------------------------------------------------------------------------------------ |
|
63
|
|
|
*/ |
|
64
|
|
|
/** |
|
65
|
|
|
* Register the user validators. |
|
66
|
|
|
*/ |
|
67
|
|
|
private function registerUserValidators() |
|
68
|
|
|
{ |
|
69
|
|
|
$this->extendValidator( |
|
70
|
|
|
'user_password', |
|
71
|
|
|
\Arcanesoft\Auth\Validators\UserValidator::class, |
|
72
|
|
|
function($message, $attribute) { |
|
73
|
|
|
$message = 'auth::validation.user_password'; |
|
74
|
|
|
|
|
75
|
|
|
return str_replace(':attribute', $attribute, trans($message)); |
|
76
|
|
|
} |
|
77
|
|
|
); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/* ------------------------------------------------------------------------------------------------ |
|
81
|
|
|
| Other Functions |
|
82
|
|
|
| ------------------------------------------------------------------------------------------------ |
|
83
|
|
|
*/ |
|
84
|
|
|
/** |
|
85
|
|
|
* Extend validator. |
|
86
|
|
|
* |
|
87
|
|
|
* @param string $name |
|
88
|
|
|
* @param string $class |
|
89
|
|
|
* @param \Closure|null $replacer |
|
90
|
|
|
*/ |
|
91
|
|
|
private function extendValidator($name, $class, Closure $replacer = null) |
|
92
|
|
|
{ |
|
93
|
|
|
$this->validator->extend($name, "{$class}@validate" . studly_case($name)); |
|
94
|
|
|
|
|
95
|
|
|
if ( ! is_null($replacer)) |
|
96
|
|
|
$this->validator->replacer($name, $replacer); |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|