1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Te7aHoudini\Laroute; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\ServiceProvider; |
6
|
|
|
use Te7aHoudini\Laroute\Routes\Collection as Routes; |
7
|
|
|
use Te7aHoudini\Laroute\Console\Commands\LarouteGeneratorCommand; |
8
|
|
|
|
9
|
|
|
class LarouteServiceProvider extends ServiceProvider |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* Bootstrap the application events. |
13
|
|
|
* |
14
|
|
|
* @return void |
15
|
|
|
*/ |
16
|
|
|
public function boot() |
17
|
|
|
{ |
18
|
|
|
$source = $this->getConfigPath(); |
19
|
|
|
$this->publishes([$source => config_path('laroute.php')], 'config'); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Register the service provider. |
24
|
|
|
* |
25
|
|
|
* @return void |
26
|
|
|
*/ |
27
|
|
|
public function register() |
28
|
|
|
{ |
29
|
|
|
$source = $this->getConfigPath(); |
30
|
|
|
$this->mergeConfigFrom($source, 'laroute'); |
31
|
|
|
|
32
|
|
|
$this->registerGenerator(); |
33
|
|
|
|
34
|
|
|
$this->registerCompiler(); |
35
|
|
|
|
36
|
|
|
$this->registerCommand(); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Get the config path. |
41
|
|
|
* |
42
|
|
|
* @return string |
43
|
|
|
*/ |
44
|
|
|
protected function getConfigPath() |
45
|
|
|
{ |
46
|
|
|
return realpath(__DIR__.'/../config/laroute.php'); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Register the generator. |
51
|
|
|
* |
52
|
|
|
* @return void |
53
|
|
|
*/ |
54
|
|
|
protected function registerGenerator() |
55
|
|
|
{ |
56
|
|
|
$this->app->bind( |
57
|
|
|
'Te7aHoudini\Laroute\Generators\GeneratorInterface', |
58
|
|
|
'Te7aHoudini\Laroute\Generators\TemplateGenerator' |
59
|
|
|
); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Register the compiler. |
64
|
|
|
* |
65
|
|
|
* @return void |
66
|
|
|
*/ |
67
|
|
|
protected function registerCompiler() |
68
|
|
|
{ |
69
|
|
|
$this->app->bind( |
70
|
|
|
'Te7aHoudini\Laroute\Compilers\CompilerInterface', |
71
|
|
|
'Te7aHoudini\Laroute\Compilers\TemplateCompiler' |
72
|
|
|
); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Register the command. |
77
|
|
|
* |
78
|
|
|
* @return void |
79
|
|
|
*/ |
80
|
|
|
protected function registerCommand() |
81
|
|
|
{ |
82
|
|
|
$this->app->singleton( |
83
|
|
|
'command.laroute.generate', |
84
|
|
|
function ($app) { |
85
|
|
|
$config = $app['config']; |
86
|
|
|
$routes = new Routes($app['router']->getRoutes(), $config->get('laroute.filter', 'all'), $config->get('laroute.action_namespace', '')); |
87
|
|
|
$generator = $app->make('Te7aHoudini\Laroute\Generators\GeneratorInterface'); |
88
|
|
|
|
89
|
|
|
return new LarouteGeneratorCommand($config, $routes, $generator); |
90
|
|
|
} |
91
|
|
|
); |
92
|
|
|
|
93
|
|
|
$this->commands('command.laroute.generate'); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|