LarouteServiceProvider::boot()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 0
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