|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @link https://github.com/phpviet/laravel-validation |
|
4
|
|
|
* |
|
5
|
|
|
* @copyright (c) PHP Viet |
|
6
|
|
|
* @license [MIT](https://opensource.org/licenses/MIT) |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace PHPViet\Laravel\Validation; |
|
10
|
|
|
|
|
11
|
|
|
use Illuminate\Support\ServiceProvider as BaseServiceProvider; |
|
12
|
|
|
use PHPViet\Laravel\Validation\Rules\IdVN; |
|
13
|
|
|
use PHPViet\Laravel\Validation\Rules\IpVN; |
|
14
|
|
|
use PHPViet\Laravel\Validation\Rules\LandLineVN; |
|
15
|
|
|
use PHPViet\Laravel\Validation\Rules\MobileVN; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @author Vuong Minh <[email protected]> |
|
19
|
|
|
* @since 1.0.0 |
|
20
|
|
|
*/ |
|
21
|
|
|
class ServiceProvider extends BaseServiceProvider |
|
22
|
|
|
{ |
|
23
|
|
|
public function boot(): void |
|
24
|
|
|
{ |
|
25
|
|
|
$this->loadTrans(); |
|
26
|
|
|
$this->loadExt(); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
protected function loadTrans(): void |
|
30
|
|
|
{ |
|
31
|
|
|
$this->publishes([ |
|
32
|
|
|
__DIR__.'/../resources/lang' => resource_path('lang/vendor/phpVietValidation'), |
|
33
|
|
|
]); |
|
34
|
|
|
$this->loadTranslationsFrom(__DIR__.'/../resources/lang/', 'phpVietValidation'); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
protected function loadExt(): void |
|
38
|
|
|
{ |
|
39
|
|
|
if (isset($this->app['validator'])) { |
|
40
|
|
|
foreach ($this->getCallableRules() as $name => $rule) { |
|
41
|
|
|
$this->app['validator']->extend($name, $rule, $rule->message()); |
|
42
|
|
|
} |
|
43
|
|
|
} |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
protected function getCallableRules(): array |
|
47
|
|
|
{ |
|
48
|
|
|
return [ |
|
49
|
|
|
'land_line_vn' => $this->app->make(LandLineVN::class), |
|
50
|
|
|
'mobile_vn' => $this->app->make(MobileVN::class), |
|
51
|
|
|
'id_vn' => $this->app->make(IdVN::class), |
|
52
|
|
|
'ip_vn' => $this->app->make(IpVN::class), |
|
53
|
|
|
'ipv4_vn' => $this->app->make(IpVN::class, ['version' => IpVN::IPV4]), |
|
54
|
|
|
'ipv6_vn' => $this->app->make(IpVN::class, ['version' => IpVN::IPV6]), |
|
55
|
|
|
]; |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|