Completed
Pull Request — master (#42)
by ARCANEDEV
17:46
created

DeferredServicesProvider::getPaths()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Arcanedev\LaravelLang\Providers;
6
7
use Arcanedev\LaravelLang\{TransChecker, TransManager, TransPublisher};
8
use Arcanedev\LaravelLang\Contracts\TransChecker as TransCheckerContract;
9
use Arcanedev\LaravelLang\Contracts\TransManager as TransManagerContract;
10
use Arcanedev\LaravelLang\Contracts\TransPublisher as TransPublisherContract;
11
use Arcanedev\Support\Providers\ServiceProvider;
12
use Illuminate\Contracts\Foundation\Application;
13
use Illuminate\Contracts\Support\DeferrableProvider;
14
15
/**
16
 * Class     DeferredServicesProvider
17
 *
18
 * @author   ARCANEDEV <[email protected]>
19
 */
20
class DeferredServicesProvider extends ServiceProvider implements DeferrableProvider
21
{
22
    /* -----------------------------------------------------------------
23
     |  Main Methods
24
     | -----------------------------------------------------------------
25
     */
26
27
    /**
28
     * Register any application services.
29
     */
30 116
    public function register(): void
31
    {
32 116
        $this->registerTransManager();
33 116
        $this->registerTransChecker();
34 116
        $this->registerLangPublisher();
35 116
    }
36
37
    /**
38
     * Get the services provided by the provider.
39
     *
40
     * @return array
41
     */
42 4
    public function provides(): array
43
    {
44
        return [
45 4
            TransManagerContract::class,
46
            TransCheckerContract::class,
47
            TransPublisherContract::class,
48
        ];
49
    }
50
51
    /* -----------------------------------------------------------------
52
     |  Services
53
     | -----------------------------------------------------------------
54
     */
55
56
    /**
57
     * Register the trans manager.
58
     */
59 116
    private function registerTransManager(): void
60
    {
61 58
        $this->singleton(TransManagerContract::class, function (Application $app) {
62 88
            return new TransManager($app['files'], $this->getPaths($app));
63 116
        });
64 116
    }
65
66
    /**
67
     * Register the trans checker.
68
     */
69 116
    private function registerTransChecker(): void
70
    {
71 58
        $this->singleton(TransCheckerContract::class, function (Application $app) {
72 32
            return new TransChecker(
73 32
                $app['translator'],
74 16
                $app[TransManagerContract::class],
75 32
                $app['config']->get('laravel-lang', [])
76
            );
77 116
        });
78 116
    }
79
80
    /**
81
     * Register the lang publisher.
82
     */
83 116
    private function registerLangPublisher(): void
84
    {
85 58
        $this->singleton(TransPublisherContract::class, function (Application $app) {
86 56
            return new TransPublisher(
87 56
                $app['files'],
88 28
                $app[TransManagerContract::class],
89 56
                $app->langPath()
90
            );
91 116
        });
92 116
    }
93
94
    /**
95
     * Get the localization paths.
96
     *
97
     * @param  \Illuminate\Contracts\Foundation\Application  $app
98
     *
99
     * @return array
100
     */
101 88
    private function getPaths(Application $app): array
102
    {
103
        return [
104 88
            'app'     => $app->langPath(),
105 88
            'vendors' => $app['config']->get('laravel-lang.vendor', []),
106
        ];
107
    }
108
}
109