ApiDocGeneratorServiceProvider::boot()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 26
rs 9.504
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
namespace Mpociot\ApiDoc;
4
5
use Illuminate\Support\ServiceProvider;
6
use Mpociot\ApiDoc\Commands\GenerateDocumentation;
7
use Mpociot\ApiDoc\Commands\RebuildDocumentation;
8
use Mpociot\ApiDoc\Matching\RouteMatcher;
9
use Mpociot\ApiDoc\Matching\RouteMatcherInterface;
10
11
class ApiDocGeneratorServiceProvider extends ServiceProvider
12
{
13
    /**
14
     * Bootstrap the application events.
15
     *
16
     * @return void
17
     */
18
    public function boot()
19
    {
20
        $this->loadViewsFrom(__DIR__ . '/../resources/views/', 'apidoc');
21
22
        $this->publishes([
23
            __DIR__ . '/../resources/views' => $this->app->basePath('resources/views/vendor/apidoc'),
24
        ], 'apidoc-views');
25
26
        $this->publishes([
27
            __DIR__ . '/../config/apidoc.php' => $this->app->configPath('apidoc.php'),
28
        ], 'apidoc-config');
29
30
        $this->mergeConfigFrom(__DIR__ . '/../config/apidoc.php', 'apidoc');
31
32
        $this->bootRoutes();
33
34
        if ($this->app->runningInConsole()) {
35
            $this->commands([
36
                GenerateDocumentation::class,
37
                RebuildDocumentation::class,
38
            ]);
39
        }
40
41
        // Bind the route matcher implementation
42
        $this->app->bind(RouteMatcherInterface::class, config('apidoc.routeMatcher', RouteMatcher::class));
43
    }
44
45
    /**
46
     * Initializing routes in the application.
47
     */
48
    protected function bootRoutes()
49
    {
50
        if (
51
            config('apidoc.type', 'static') === 'laravel' &&
52
            config('apidoc.laravel.autoload', false)
53
        ) {
54
            $this->loadRoutesFrom(
55
                __DIR__ . '/../routes/laravel.php'
56
            );
57
        }
58
    }
59
}
60