1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Micheledamo\LaravelWebArtisan; |
4
|
|
|
|
5
|
|
|
use Illuminate\Contracts\Http\Kernel; |
6
|
|
|
use Illuminate\Support\ServiceProvider; |
7
|
|
|
use Illuminate\Routing\Router; |
8
|
|
|
use Micheledamo\LaravelWebArtisan\Middleware\WebArtisanEnabled; |
9
|
|
|
|
10
|
|
|
class LaravelWebArtisanServiceProvider extends ServiceProvider |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* Perform post-registration booting of services. |
14
|
|
|
* |
15
|
|
|
* @return void |
16
|
|
|
*/ |
17
|
|
|
public function boot() |
18
|
|
|
{ |
19
|
|
|
$this->publishes([ |
20
|
|
|
__DIR__.'/../config/config.php' => config_path('webartisan.php'), |
21
|
|
|
], 'config'); |
22
|
|
|
|
23
|
|
|
$routeConfig = [ |
24
|
|
|
'namespace' => 'Micheledamo\LaravelWebArtisan\Controllers', |
25
|
|
|
'prefix' => $this->app['config']->get('webartisan.route_prefix'), |
26
|
|
|
'domain' => $this->app['config']->get('webartisan.route_domain'), |
27
|
|
|
'middleware' => 'web' |
28
|
|
|
]; |
29
|
|
|
|
30
|
|
|
$this->getRouter()->group($routeConfig, function($router) { |
31
|
|
|
$router->post('run', [ |
32
|
|
|
'uses' => 'WebArtisanCommandController@run', |
|
|
|
|
33
|
|
|
'as' => 'webartisan.run', |
34
|
|
|
]); |
35
|
|
|
$router->post('auth', [ |
36
|
|
|
'uses' => 'WebArtisanAuthController@auth', |
|
|
|
|
37
|
|
|
'as' => 'webartisan.auth', |
38
|
|
|
]); |
39
|
|
|
$router->post('logout', [ |
40
|
|
|
'uses' => 'WebArtisanAuthController@logout', |
|
|
|
|
41
|
|
|
'as' => 'webartisan.logout', |
42
|
|
|
]); |
43
|
|
|
}); |
44
|
|
|
|
45
|
|
|
$this->loadViewsFrom(__DIR__.'/Resources/Views', 'webartisan'); |
46
|
|
|
|
47
|
|
|
$this->registerMiddleware(WebArtisanEnabled::class); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Register any package services. |
52
|
|
|
* |
53
|
|
|
* @return void |
54
|
|
|
*/ |
55
|
|
|
public function register() |
56
|
|
|
{ |
57
|
|
|
$this->mergeConfigFrom(__DIR__.'/../config/config.php', 'webartisan'); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Register the Web Artisan Middleware |
62
|
|
|
* |
63
|
|
|
* @param string $middleware |
64
|
|
|
*/ |
65
|
|
|
protected function registerMiddleware($middleware) |
66
|
|
|
{ |
67
|
|
|
$kernel = $this->app[Kernel::class]; |
68
|
|
|
$kernel->pushMiddleware($middleware); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Get the active router. |
73
|
|
|
* |
74
|
|
|
* @return Router |
75
|
|
|
*/ |
76
|
|
|
protected function getRouter() |
77
|
|
|
{ |
78
|
|
|
return $this->app['router']; |
79
|
|
|
} |
80
|
|
|
} |
If there is a route defined but the controller class cannot be found there are two options: 1. the controller class needs to be implemented or 2. the route is outdated and can be removed.
If ?FooController? was found and ?BarController? is missing for the following example, either the controller should be implemented or the route should be removed: