Passed
Pull Request — master (#71)
by László
07:10
created

UploadHandlerServiceProvider::setupConfig()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
nc 1
cc 1
nop 0
crap 1
1
<?php
2
3
namespace CodingSocks\UploadHandler;
4
5
use Illuminate\Support\ServiceProvider;
6
7
class UploadHandlerServiceProvider extends ServiceProvider
8
{
9
    /**
10
     * Bootstrap any package services.
11
     *
12
     * @return void
13
     */
14 156
    public function boot()
15
    {
16 156
        $this->setupConfig();
17 156
    }
18
19
    /**
20
     * Setup the config.
21
     *
22
     * @return void
23
     */
24 156
    protected function setupConfig()
25
    {
26 156
        $source = realpath(__DIR__ . '/../config/upload-handler.php');
27 156
        $this->publishes([$source => config_path('upload-handler.php')]);
28
29 156
        $this->mergeConfigFrom($source, 'upload-handler');
30 156
    }
31
32
    /**
33
     * Register any package services.
34
     *
35
     * @return void
36
     */
37 156
    public function register()
38
    {
39 156
        $this->registerUploadHandler();
40 156
    }
41
42
    /**
43
     * Register the Upload Handler instance.
44
     *
45
     * @return void
46
     */
47 156
    protected function registerUploadHandler()
48
    {
49 156
        $this->registerUploadManager();
50 156
        $this->registerIdentityManager();
51
52 156
        $this->app->singleton(UploadHandler::class, function () {
53
            /** @var \Illuminate\Support\Manager $uploadManager */
54 153
            $uploadManager = $this->app['upload-handler.upload-manager'];
55
56 153
            $storageConfig = new StorageConfig($this->app->make('config')->get('upload-handler'));
57
58 153
            return new UploadHandler($uploadManager->driver(), $storageConfig);
59 156
        });
60 156
    }
61
62
    /**
63
     * Register the Upload Manager instance.
64
     *
65
     * @return void
66
     */
67 156
    protected function registerUploadManager()
68
    {
69 156
        $this->app->singleton('upload-handler.upload-manager', function () {
70 153
            return new UploadManager($this->app);
71 156
        });
72 156
    }
73
74
    /**
75
     * Register the Upload Manager instance.
76
     *
77
     * @return void
78
     */
79 156
    protected function registerIdentityManager()
80
    {
81 156
        $this->app->singleton('upload-handler.identity-manager', function () {
82 131
            return new IdentityManager($this->app);
83 156
        });
84 156
    }
85
86
    /**
87
     * Get the services provided by the provider.
88
     *
89
     * @return array
90
     */
91
    public function provides()
92
    {
93
        return [
94
            UploadHandler::class,
95
            'upload-handler.upload-manager',
96
        ];
97
    }
98
}
99