MediaRecognitionServiceProvider::boot()   A
last analyzed

Complexity

Conditions 4
Paths 8

Size

Total Lines 20
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 12
c 1
b 0
f 0
nc 8
nop 0
dl 0
loc 20
rs 9.8666
1
<?php
2
3
namespace Meema\MediaRecognition\Providers;
4
5
use Illuminate\Routing\Router;
6
use Illuminate\Support\ServiceProvider;
7
use Meema\MediaRecognition\Facades\Recognize;
8
use Meema\MediaRecognition\Http\Middleware\VerifySignature;
9
use Meema\MediaRecognition\MediaRecognitionManager;
10
11
class MediaRecognitionServiceProvider 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-recognition.php'),
23
            ], 'config');
24
        }
25
26
        if (! class_exists('CreateMediaRecognitionsTable')) {
27
            $this->publishes([
28
                __DIR__.'/../../database/migrations/create_media_recognitions_table.php.stub' => database_path('migrations/'.date('Y_m_d_His', time()).'_create_media_recognitions_table.php'),
29
            ], 'migrations');
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-recognition');
47
48
        $this->registerMediaRecognitionManager();
49
50
        $this->registerAliases();
51
    }
52
53
    /**
54
     * Registers the Text to speech manager.
55
     *
56
     * @return void
57
     */
58
    protected function registerMediaRecognitionManager()
59
    {
60
        $this->app->singleton('recognize', function ($app) {
61
            return new MediaRecognitionManager($app);
62
        });
63
    }
64
65
    /**
66
     * Register aliases.
67
     *
68
     * @return void
69
     */
70
    protected function registerAliases()
71
    {
72
        $this->app->alias(Recognize::class, 'Recognize');
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
            'recognize',
84
        ];
85
    }
86
}
87