Completed
Push — master ( 300b9f...943d1a )
by Vuong
02:13 queued 01:10
created

ServiceProvider::loadExt()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 3
nc 3
nop 0
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 PHPViet\Laravel\Validation\Rules\IdVN;
12
use PHPViet\Laravel\Validation\Rules\IpVN;
13
use PHPViet\Laravel\Validation\Rules\MobileVN;
14
use PHPViet\Laravel\Validation\Rules\LandLineVN;
15
use Illuminate\Support\ServiceProvider as BaseServiceProvider;
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, [IpVN::IPV4]),
54
            'ipv6_vn' => $this->app->make(IpVN::class, [IpVN::IPV6]),
55
        ];
56
    }
57
}
58