Completed
Push — master ( 6f15ff...d42090 )
by ARCANEDEV
25s
created

ServicesProvider::registerFilesystem()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 15
ccs 10
cts 10
cp 1
crap 1
rs 9.7666
c 0
b 0
f 0
1
<?php namespace Arcanedev\LogViewer\Providers;
2
3
use Arcanedev\LogViewer\{Contracts, LogViewer, Utilities};
4
use Arcanedev\Support\Providers\ServiceProvider;
5
use Illuminate\Contracts\Support\DeferrableProvider;
6
use Illuminate\Support\Arr;
7
8
/**
9
 * Class     ServicesProvider
10
 *
11
 * @package  Arcanedev\LogViewer\Providers
12
 * @author   ARCANEDEV <[email protected]>
13
 */
14
class ServicesProvider extends ServiceProvider implements DeferrableProvider
15
{
16
    /* -----------------------------------------------------------------
17
     |  Main Methods
18
     | -----------------------------------------------------------------
19
     */
20
21
    /**
22
     * Register the service provider.
23
     */
24 288
    public function register(): void
25
    {
26 288
        $this->registerLogViewer();
27 288
        $this->registerLogLevels();
28 288
        $this->registerStyler();
29 288
        $this->registerLogMenu();
30 288
        $this->registerFilesystem();
31 288
        $this->registerFactory();
32 288
        $this->registerChecker();
33 288
    }
34
35
    /**
36
     * Get the services provided by the provider.
37
     *
38
     * @return array
39
     */
40 2
    public function provides(): array
41
    {
42
        return [
43 2
            Contracts\LogViewer::class,
44
            Contracts\Utilities\LogLevels::class,
45
            Contracts\Utilities\LogStyler::class,
46
            Contracts\Utilities\LogMenu::class,
47
            Contracts\Utilities\Filesystem::class,
48
            Contracts\Utilities\Factory::class,
49
            Contracts\Utilities\LogChecker::class,
50
        ];
51
    }
52
53
    /* -----------------------------------------------------------------
54
     |  LogViewer Utilities
55
     | -----------------------------------------------------------------
56
     */
57
58
    /**
59
     * Register the log viewer service.
60
     */
61 288
    private function registerLogViewer(): void
62
    {
63 288
        $this->singleton(Contracts\LogViewer::class, LogViewer::class);
64 288
    }
65
66
    /**
67
     * Register the log levels.
68
     */
69 288
    private function registerLogLevels(): void
70
    {
71
        $this->singleton(Contracts\Utilities\LogLevels::class, function ($app) {
72
            /**
73
             * @var  \Illuminate\Config\Repository       $config
74
             * @var  \Illuminate\Translation\Translator  $translator
75
             */
76 172
            $config     = $app['config'];
77 172
            $translator = $app['translator'];
78
79 172
            return new Utilities\LogLevels($translator, $config->get('log-viewer.locale'));
80 288
        });
81 288
    }
82
83
    /**
84
     * Register the log styler.
85
     */
86 288
    private function registerStyler(): void
87
    {
88 288
        $this->singleton(Contracts\Utilities\LogStyler::class, Utilities\LogStyler::class);
89 288
    }
90
91
    /**
92
     * Register the log menu builder.
93
     */
94 288
    private function registerLogMenu(): void
95
    {
96 288
        $this->singleton(Contracts\Utilities\LogMenu::class, Utilities\LogMenu::class);
97 288
    }
98
99
    /**
100
     * Register the log filesystem.
101
     */
102 288
    private function registerFilesystem(): void
103
    {
104
        $this->singleton(Contracts\Utilities\Filesystem::class, function ($app) {
105
            /** @var  \Illuminate\Config\Repository  $config */
106 248
            $config     = $app['config'];
107 248
            $pattern    = $config->get('log-viewer.pattern', []);
108 248
            $filesystem = new Utilities\Filesystem($app['files'], $config->get('log-viewer.storage-path'));
109
110 248
            return $filesystem->setPattern(
111 248
                Arr::get($pattern, 'prefix',    Utilities\Filesystem::PATTERN_PREFIX),
112 248
                Arr::get($pattern, 'date',      Utilities\Filesystem::PATTERN_DATE),
113 248
                Arr::get($pattern, 'extension', Utilities\Filesystem::PATTERN_EXTENSION)
114
            );
115 288
        });
116 288
    }
117
118
    /**
119
     * Register the log factory class.
120
     */
121 288
    private function registerFactory(): void
122
    {
123 288
        $this->singleton(Contracts\Utilities\Factory::class, Utilities\Factory::class);
124 288
    }
125
126
    /**
127
     * Register the log checker service.
128
     */
129 288
    private function registerChecker(): void
130
    {
131 288
        $this->singleton(Contracts\Utilities\LogChecker::class, Utilities\LogChecker::class);
132 288
    }
133
}
134