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

ServiceProvider::addMiddlewareAlias()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 2
eloc 5
nc 2
nop 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