Test Failed
Pull Request — master (#64)
by
unknown
06:49 queued 02:17
created

MetadataRouteProvider::boot()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
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
25
        Route::any(
26
            'odata.svc/{section}',
27
            ['uses' => 'AlgoWeb\PODataLaravel\Controllers\ODataController@index', 'middleware' => $auth_middleware]
28
        )
29
            ->where(['section' => '.*']);
30
        Route::any(
31
            'odata.svc',
32
            ['uses' => 'AlgoWeb\PODataLaravel\Controllers\ODataController@index', 'middleware' => $auth_middleware]
33
        );
34
    }
35
36
    /**
37
     * Register the application services.
38
     *
39
     * @return void
40
     */
41
    public function register()
42
    {
43
        //
44
    }
45
46
    private static function getAuthMiddleware()
47
    {
48
        $auth_middleware = 'auth.basic';
49
50
        if (class_exists(\Illuminate\Contracts\Auth\Factory::class)) {
51
            $manager = App::make(\Illuminate\Contracts\Auth\Factory::class);
52
            if ($manager->guard('api')) {
53
                $auth_middleware = 'auth:api';
54
            }
55
        }
56
57
        return $auth_middleware;
58
    }
59
}
60