MediaConverterServiceProvider   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 21
dl 0
loc 73
rs 10
c 1
b 0
f 0
wmc 9

5 Methods

Rating   Name   Duplication   Size   Complexity  
A registerAliases() 0 3 1
A registerMediaConverterManager() 0 4 1
A boot() 0 20 5
A register() 0 7 1
A provides() 0 4 1
1
<?php
2
3
namespace Meema\MediaConverter\Providers;
4
5
use Illuminate\Routing\Router;
6
use Illuminate\Support\ServiceProvider;
7
use Meema\MediaConverter\Facades\MediaConvert;
8
use Meema\MediaConverter\Http\Middleware\VerifySignature;
9
use Meema\MediaConverter\MediaConverterManager;
10
11
class MediaConverterServiceProvider extends ServiceProvider
12
{
13
    /**
14
     * Bootstrap the application services.
15
     *
16
     * @throws \Illuminate\Contracts\Container\BindingResolutionException
17
     */
18
    public function boot()
19
    {
20
        if ($this->app->runningInConsole()) {
21
            $this->publishes([
22
                __DIR__.'/../../config/config.php' => config_path('media-converter.php'),
23
            ], 'config');
24
25
            if (config('media-converter.track_media_conversions') && ! class_exists('CreateMediaConversionsTable')) {
26
                $this->publishes([
27
                    __DIR__.'/../../database/migrations/create_media_conversions_table.php.stub' => database_path('migrations/'.date('Y_m_d_His', time()).'_create_media_conversions_table.php'),
28
                ], 'migrations');
29
            }
30
        }
31
32
        $this->loadRoutesFrom(__DIR__.'/../routes.php');
33
34
        $router = $this->app->make(Router::class);
35
36
        if (! in_array('verify-signature', $router->getMiddleware())) {
37
            $router->aliasMiddleware('verify-signature', VerifySignature::class);
38
        }
39
    }
40
41
    /**
42
     * Register the application services.
43
     */
44
    public function register()
45
    {
46
        $this->mergeConfigFrom(__DIR__.'/../../config/config.php', 'media-converter');
47
48
        $this->registerMediaConverterManager();
49
50
        $this->registerAliases();
51
    }
52
53
    /**
54
     * Registers the Text to speech manager.
55
     *
56
     * @return void
57
     */
58
    protected function registerMediaConverterManager()
59
    {
60
        $this->app->singleton('media-converter', function ($app) {
61
            return new MediaConverterManager($app);
62
        });
63
    }
64
65
    /**
66
     * Register aliases.
67
     *
68
     * @return void
69
     */
70
    protected function registerAliases()
71
    {
72
        $this->app->alias(MediaConvert::class, 'MediaConvert');
73
    }
74
75
    /**
76
     * Get the services provided by the provider.
77
     *
78
     * @return array
79
     */
80
    public function provides(): array
81
    {
82
        return [
83
            'media-converter',
84
        ];
85
    }
86
}
87