Test Failed
Pull Request — master (#70)
by Alex
04:13
created

MetadataRouteProvider::setupRoute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 15
rs 9.4285
cc 1
eloc 10
nc 1
nop 0
1
<?php
2
3
namespace AlgoWeb\PODataLaravel\Providers;
4
5
use Illuminate\Support\Facades\App;
6
use Illuminate\Support\Facades\Route;
7
use Illuminate\Support\ServiceProvider;
8
9
class MetadataRouteProvider extends ServiceProvider
10
{
11
    /**
12
     * Bootstrap the application services.
13
     *
14
     * @return void
15
     */
16
    public function boot()
17
    {
18
        self::setupRoute();
19
    }
20
21
    private static function setupRoute()
22
    {
23
        $auth_middleware = self::getAuthMiddleware();
24
        $controllerMethod = 'AlgoWeb\PODataLaravel\Controllers\ODataController@index';
25
26
        Route::any(
27
            'odata.svc/{section}',
28
            ['uses' => $controllerMethod, 'middleware' => $auth_middleware]
29
        )
30
            ->where(['section' => '.*']);
31
        Route::any(
32
            'odata.svc',
33
            ['uses' => $controllerMethod, 'middleware' => $auth_middleware]
34
        );
35
    }
36
37
    /**
38
     * Register the application services.
39
     *
40
     * @return void
41
     */
42
    public function register()
43
    {
44
        //
45
    }
46
47
    private static function getAuthMiddleware()
48
    {
49
        $auth_middleware = 'auth.basic';
50
51
        if (interface_exists(\Illuminate\Contracts\Auth\Factory::class)) {
52
            $manager = App::make(\Illuminate\Contracts\Auth\Factory::class);
53
            if ($manager->guard('api')) {
54
                $auth_middleware = 'auth:api';
55
            }
56
        }
57
58
        return $auth_middleware;
59
    }
60
}
61