|
1
|
|
|
<?php namespace App\Providers; |
|
2
|
|
|
|
|
3
|
|
|
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider; |
|
4
|
|
|
use Illuminate\Http\Request; |
|
5
|
|
|
use Illuminate\Routing\Router; |
|
6
|
|
|
|
|
7
|
|
|
class RouteServiceProvider extends ServiceProvider |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* This namespace is applied to the controller routes in your routes file. |
|
11
|
|
|
* In addition, it is set as the URL generator's root namespace. |
|
12
|
|
|
* |
|
13
|
|
|
* @var string |
|
14
|
|
|
*/ |
|
15
|
|
|
protected $namespace = 'App\Http\Controllers'; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Define your route model bindings, pattern filters, etc. |
|
19
|
|
|
* |
|
20
|
|
|
* @return void |
|
21
|
|
|
*/ |
|
22
|
|
|
public function boot() |
|
23
|
|
|
{ |
|
24
|
|
|
app('router')->patterns([ |
|
25
|
|
|
'provider' => 'twitter|google|facebook', |
|
26
|
|
|
'token' => '[a-zA-Z0-9-]+' |
|
27
|
|
|
]); |
|
28
|
|
|
|
|
29
|
|
|
parent::boot(); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Define the routes for the application. |
|
34
|
|
|
*/ |
|
35
|
|
|
public function map() |
|
36
|
|
|
{ |
|
37
|
|
|
$this->mapApiRoutes(); |
|
38
|
|
|
$this->mapWebRoutes(); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Define the "api" routes for the application. |
|
43
|
|
|
* These routes are typically stateless. |
|
44
|
|
|
* |
|
45
|
|
|
* @return void |
|
46
|
|
|
*/ |
|
47
|
|
|
protected function mapApiRoutes() |
|
48
|
|
|
{ |
|
49
|
|
|
app('router')->group([ |
|
50
|
|
|
'middleware' => 'api', |
|
51
|
|
|
'namespace' => $this->namespace, |
|
52
|
|
|
'prefix' => 'api/v1', |
|
53
|
|
|
], function (Router $router) { |
|
54
|
|
|
$router->post('login', 'Auth\LoginController@login'); |
|
55
|
|
|
$router->post('logout', 'Auth\LoginController@logout')->middleware('auth:api'); |
|
56
|
|
|
$router->post('register', 'Auth\RegisterController@register'); |
|
57
|
|
|
|
|
58
|
|
|
$router->post('password/email', 'Auth\PasswordController@sendPasswordResetLink'); |
|
59
|
|
|
$router->post('password/reset', 'Auth\PasswordController@resetPassword'); |
|
60
|
|
|
|
|
61
|
|
|
$router->get('activation', 'Auth\ActivateController@requestActivationCode')->middleware('auth:api'); |
|
62
|
|
|
$router->get('activation/{token}', 'Auth\ActivateController@activate')->middleware('auth:api'); |
|
63
|
|
|
$router->post('activation', 'Auth\ActivateController@activate')->middleware('auth:api'); |
|
64
|
|
|
}); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Define the "web" routes for the application. |
|
69
|
|
|
* These routes all receive session state, CSRF protection, etc. |
|
70
|
|
|
* |
|
71
|
|
|
* @return void |
|
72
|
|
|
*/ |
|
73
|
|
|
protected function mapWebRoutes() |
|
74
|
|
|
{ |
|
75
|
|
|
app('router')->group([ |
|
76
|
|
|
'middleware' => 'web', |
|
77
|
|
|
'namespace' => $this->namespace, |
|
78
|
|
|
], function (Router $router) { |
|
79
|
|
|
$defaultLocale = config('app.locale'); |
|
|
|
|
|
|
80
|
|
|
|
|
81
|
|
|
//----------------------------------------------------------------------- |
|
82
|
|
|
// Non-localized, generic routes (such as those for admin panel etc). |
|
83
|
|
|
//----------------------------------------------------------------------- |
|
84
|
|
|
|
|
85
|
|
|
$router->get('/oauth/to/{provider}', ['uses' => 'Auth\LoginController@handleOAuthRedirect', 'as' => 'oauth.to']); |
|
86
|
|
|
$router->get('/oauth/from/{provider}', ['uses' => 'Auth\LoginController@handleOAuthReturn', 'as' => 'oauth.from']); |
|
87
|
|
|
|
|
88
|
|
|
//----------------------------------------------------------------------------------------------------- |
|
89
|
|
|
// Register localized routes with locale-prefices (in case of default locale, no prefix is attached). |
|
90
|
|
|
//----------------------------------------------------------------------------------------------------- |
|
91
|
|
|
|
|
92
|
|
|
foreach (config('app.locales') as $prefix => $localeName) { |
|
93
|
|
|
app('translator')->setLocale($prefix); |
|
94
|
|
|
// Localized routes. |
|
95
|
|
|
$router->group(compact('namespace', 'middleware', 'prefix'), function (Router $router) use ($prefix) { |
|
96
|
|
|
$this->localizeWebRoutes($router, $prefix); |
|
97
|
|
|
}); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/*------------------------------------ |
|
101
|
|
|
| Default, non-localized home |
|
102
|
|
|
*-----------------------------------*/ |
|
103
|
|
|
|
|
104
|
|
|
$router->get('', 'HomeController@index'); |
|
105
|
|
|
}); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* @param \Illuminate\Routing\Router $router |
|
110
|
|
|
* @param string $prefix |
|
111
|
|
|
*/ |
|
112
|
|
|
protected function localizeWebRoutes(Router $router, $prefix = '') |
|
113
|
|
|
{ |
|
114
|
|
|
$router->get('login', ['uses' => 'Auth\LoginController@showLoginForm', 'as' => empty($prefix) ?: $prefix . '.login']); |
|
115
|
|
|
$router->post('login', 'Auth\LoginController@loginViaWeb'); |
|
116
|
|
|
$router->get('logout', ['uses' => 'Auth\LoginController@logout', 'as' => empty($prefix) ?: $prefix . '.logout']); |
|
117
|
|
|
$router->get('register', ['uses' => 'Auth\RegisterController@showRegistrationForm', 'as' => empty($prefix) ?: $prefix . '.register']); |
|
118
|
|
|
$router->post('register', 'Auth\RegisterController@register'); |
|
119
|
|
|
|
|
120
|
|
|
$router->get('password/email', ['uses' => 'Auth\PasswordController@requestPasswordResetLink', 'as' => empty($prefix) ?: $prefix . '.password.email']); |
|
121
|
|
|
$router->post('password/email', 'Auth\PasswordController@sendPasswordResetLink'); |
|
122
|
|
|
$router->get('password/reset/{token}', ['uses' => 'Auth\PasswordController@showPasswordResetForm', 'as' => empty($prefix) ?: $prefix . '.password.reset']); |
|
123
|
|
|
$router->post('password/reset', 'Auth\PasswordController@resetPassword'); |
|
124
|
|
|
|
|
125
|
|
|
$router->get('activation', ['uses' => 'Auth\ActivateController@requestActivationCode', 'as' => empty($prefix) ?: $prefix . '.activation.request']); |
|
126
|
|
|
$router->get('activation/{token}', ['uses' => 'Auth\ActivateController@activate', 'as' => empty($prefix) ?: $prefix . '.activation.complete']); |
|
127
|
|
|
$router->post('activation', 'Auth\ActivateController@activate'); |
|
128
|
|
|
|
|
129
|
|
|
$router->resource('files', 'FilesController', ['only' => ['index', 'create', 'store', 'show', 'destroy']]); |
|
130
|
|
|
|
|
131
|
|
|
$router->get('', ['uses' => 'HomeController@index', 'as' => empty($prefix) ?: $prefix . '.home']); |
|
132
|
|
|
} |
|
133
|
|
|
} |
|
134
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.