Completed
Push — master ( 146761...077cc1 )
by Vuong
01:27
created

ServiceProvider::provides()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
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\Contracts\Support\DeferrableProvider;
16
use Illuminate\Support\ServiceProvider as BaseServiceProvider;
17
18
/**
19
 * @author Vuong Minh <[email protected]>
20
 * @since 1.0.0
21
 */
22
class ServiceProvider extends BaseServiceProvider implements DeferrableProvider
23
{
24
    public function boot(): void
25
    {
26
        $this->loadTrans();
27
        $this->loadExt();
28
    }
29
30
    protected function loadTrans(): void
31
    {
32
        $this->publishes([
33
            __DIR__ . '/../resources/lang' => resource_path('lang/vendor/phpVietValidation'),
34
        ]);
35
        $this->loadTranslationsFrom(__DIR__ . '/../resources/lang/', 'phpVietValidation');
36
    }
37
38
    protected function loadExt(): void
39
    {
40
        foreach ($this->getCallableRules() as $name => $rule) {
41
            $this->app['validator']->extend($name, $rule, $rule->message());
42
        }
43
    }
44
45
    protected function getCallableRules(): array
46
    {
47
        return [
48
            'land_line_vn' => $this->app->make(LandLineVN::class),
49
            'mobile_vn' => $this->app->make(MobileVN::class),
50
            'id_vn' => $this->app->make(IdVN::class),
51
            'ip_vn' => $this->app->make(IpVN::class),
52
            'ipv4_vn' => $this->app->make(IpVN::class, [IpVN::IPV4]),
53
            'ipv6_vn' => $this->app->make(IpVN::class, [IpVN::IPV6]),
54
        ];
55
    }
56
57
    public function provides(): array
58
    {
59
        return ['validator'];
60
    }
61
62
}
63