1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Loadsman\LaravelPlugin\Providers; |
4
|
|
|
|
5
|
|
|
use Loadsman\LaravelPlugin\Http\Middleware\DebugState; |
6
|
|
|
use Loadsman\LaravelPlugin\Http\Middleware\DetectRoute; |
7
|
|
|
use Loadsman\LaravelPlugin\Http\Middleware\PreventRedirect; |
8
|
|
|
use Illuminate\Contracts\Http\Kernel; |
9
|
|
|
use Illuminate\Routing\Router; |
10
|
|
|
use Illuminate\Support\ServiceProvider; |
11
|
|
|
|
12
|
|
|
class RouteServiceProvider extends ServiceProvider |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @type \Illuminate\Foundation\Http\Kernel |
16
|
|
|
*/ |
17
|
|
|
protected $kernel; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Define the routes for the application. |
21
|
|
|
* |
22
|
|
|
* @param Router $router |
23
|
|
|
* |
24
|
|
|
* @return void |
25
|
|
|
*/ |
26
|
|
|
public function map(Router $router) |
27
|
|
|
{ |
28
|
|
|
$router->group([ |
29
|
|
|
'as' => 'api-tester.', |
30
|
|
|
'prefix' => config('api-tester.route'), |
31
|
|
|
'namespace' => $this->getNamespace(), |
32
|
|
|
'middleware' => $this->getMiddleware(), |
33
|
|
|
], function () { |
34
|
|
|
$this->requireRoutes(); |
35
|
|
|
}); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @param Router $router |
40
|
|
|
* @param Kernel|\Illuminate\Foundation\Http\Kernel $kernel |
41
|
|
|
*/ |
42
|
|
|
public function boot(Router $router, Kernel $kernel) |
43
|
|
|
{ |
44
|
|
|
$this->map($router); |
45
|
|
|
|
46
|
|
|
$this->kernel = $kernel; |
|
|
|
|
47
|
|
|
|
48
|
|
|
// The middleware is used to intercept every request with specific header |
49
|
|
|
// so that laravel can tell us, which route the request belongs to. |
50
|
|
|
$kernel->prependMiddleware(DetectRoute::class); |
51
|
|
|
$kernel->prependMiddleware(PreventRedirect::class); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
protected function getMiddleware() |
55
|
|
|
{ |
56
|
|
|
$middleware = config('api-tester.middleware'); |
57
|
|
|
|
58
|
|
|
return $middleware; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Get module namespace |
63
|
|
|
* |
64
|
|
|
* @return string |
65
|
|
|
*/ |
66
|
|
|
protected function getNamespace() |
67
|
|
|
{ |
68
|
|
|
return 'Loadsman\Laravel\Http\Controllers'; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @return string |
73
|
|
|
*/ |
74
|
|
|
protected function requireRoutes() |
75
|
|
|
{ |
76
|
|
|
require __DIR__ . '/../Http/routes.php'; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Register the service provider. |
81
|
|
|
* |
82
|
|
|
* @return void |
83
|
|
|
*/ |
84
|
|
|
public function register() |
85
|
|
|
{ |
86
|
|
|
|
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.