Completed
Push — master ( 630443...dd0f05 )
by Yaro
01:43
created

ServiceProvider   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 4
c 3
b 0
f 1
lcom 1
cbo 2
dl 0
loc 43
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 15 1
A register() 0 9 1
A addMiddlewareAlias() 0 10 2
1
<?php 
2
3
namespace Yaro\ApiDocs;
4
5
use Yaro\ApiDocs\Commands\BlueprintCreate;
6
use Yaro\ApiDocs\Http\Middleware\BasicAuth;
7
use Illuminate\Support\ServiceProvider as IlluminateServiceProvider;
8
9
class ServiceProvider extends IlluminateServiceProvider
10
{
11
12
    protected $defer = false;
13
14
    public function boot()
15
    {
16
        $this->publishes([
17
            __DIR__ . '/../config/apidocs.php' => config_path('yaro.apidocs.php'),
18
        ], 'config');
19
        
20
        $this->app['view']->addNamespace('apidocs', __DIR__ . '/../resources/views');
21
        
22
        $this->app->bind('command.apidocs:blueprint-create', BlueprintCreate::class);
23
        $this->commands([
24
            'command.apidocs:blueprint-create',
25
        ]);
26
        
27
        $this->addMiddlewareAlias('apidocs.auth.basic', BasicAuth::class);
28
    } // end boot
29
30
    public function register()
31
    {
32
        $configPath = __DIR__ . '/../config/apidocs.php';
33
        $this->mergeConfigFrom($configPath, 'yaro.apidocs');
34
        
35
        $this->app->singleton('yaro.apidocs', function($app) {
36
            return $app->make(ApiDocs::class);
37
        });
38
    } // end register
39
    
40
    private function addMiddlewareAlias($name, $class)
41
    {
42
        $router = $this->app['router'];
43
44
        if (method_exists($router, 'aliasMiddleware')) {
45
            return $router->aliasMiddleware($name, $class);
46
        }
47
48
        return $router->middleware($name, $class);
49
    }
50
    
51
}
52