Completed
Push — master ( 416b5c...1e089b )
by Fumio
07:08
created

RouteServiceProvider::addon()

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
nc 1
dl 0
loc 1
ccs 0
cts 0
cp 0
1
<?php
2
3
namespace Jumilla\Addomnipot\Laravel\Support;
4
5
use Illuminate\Routing\Router;
6
use Illuminate\Support\ServiceProvider;
7
8
abstract class RouteServiceProvider extends ServiceProvider
9
{
10
    /**
11
     * Bootstrap any application services.
12
     *
13
     * @param  \Illuminate\Routing\Router  $router
14
     * @return void
15
     */
16
    public function boot(Router $router)
0 ignored issues
show
Unused Code introduced by
The parameter $router is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
17
    {
18
        $this->app->call([$this, 'map']);
19
    }
20
21
    /**
22
     * Define the routes for the addon.
23
     *
24
     * @param  \Illuminate\Routing\Router  $router  (injection)
25
     * @return void
26
     */
27
    public function map(Router $router)
28
    {
29
        $addon = $this->addon();
30
        $config = $addon->config('addon.routes');
31
32
        $attributes = [
33
            'domain' => array_get($config, 'domain', null),
34
            'prefix' => array_get($config, 'prefix', ''),
35
            'middleware' => array_get($config, 'middleware', []),
36
            'namespace' => $addon->phpNamespace().'\Http\Controllers',
37
        ];
38
39
        $files = array_map(function ($file) use ($addon) {
40
            return $addon->path($file);
41
        }, array_get($config, 'files', ['classes/Http/routes.php']));
42
43
        $router->group($attributes, function ($router) use ($files) {
44
            foreach ($files as $file) {
45
                require $file;
46
            }
47
        });
48
    }
49
50
    /**
51
     * Get addon.
52
     *
53
     * @return \Jumilla\Addomnipot\Laravel\Addon
54
     */
55
    abstract protected function addon();
56
57
    /**
58
     * Register the service provider.
59
     *
60
     * @return void
61
     */
62
    public function register()
63
    {
64
        //
65
    }
66
67
    /**
68
     * Pass dynamic methods onto the router instance.
69
     *
70
     * @param  string  $method
71
     * @param  array  $parameters
72
     * @return mixed
73
     */
74
    public function __call($method, $parameters)
75
    {
76
        return call_user_func_array([$this->app->make(Router::class), $method], $parameters);
77
    }
78
}
79