Completed
Push — master ( a9dadd...cf2495 )
by ARCANEDEV
9s
created

RouteRegistrar::map()

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
nc 1
dl 0
loc 1
ccs 0
cts 0
cp 0
c 0
b 0
f 0
1
<?php namespace Arcanedev\Support\Routing;
2
3
use Closure;
4
use Illuminate\Routing\Router;
5
use Illuminate\Routing\RouteRegistrar as IlluminateRouteRegistrar;
6
7
/**
8
 * Class     RouteRegistrar
9
 *
10
 * @package  Arcanedev\Support\Laravel
11
 * @author   ARCANEDEV <[email protected]>
12
 *
13
 * @method  \Arcanedev\Support\Routing\RouteRegistrar  prefix(string $prefix)
14
 * @method  \Arcanedev\Support\Routing\RouteRegistrar  name(string $name)
15
 * @method  \Arcanedev\Support\Routing\RouteRegistrar  as(string $name)
16
 * @method  \Arcanedev\Support\Routing\RouteRegistrar  namespace(string $namespace)
17
 * @method  \Arcanedev\Support\Routing\RouteRegistrar  domain(string $domain)
18
 */
19
abstract class RouteRegistrar extends IlluminateRouteRegistrar
20
{
21
    /* ------------------------------------------------------------------------------------------------
22
     |  Properties
23
     | ------------------------------------------------------------------------------------------------
24
     */
25
    /**
26
     * The router instance.
27
     *
28
     * @var \Illuminate\Routing\Router
29
     */
30
    protected $router;
31
32
    /* ------------------------------------------------------------------------------------------------
33
     |  Main Functions
34
     | ------------------------------------------------------------------------------------------------
35
     */
36
    /**
37
     * Register and map routes.
38
     *
39
     * @param  \Illuminate\Routing\Router  $router
40
     */
41
    public static function register(Router $router)
42
    {
43
        (new static($router))->map();
44
    }
45
46
    /**
47
     * Map routes.
48
     */
49
    abstract public function map();
50
51
    /* ------------------------------------------------------------------------------------------------
52
     |  Getter & Setters
53
     | ------------------------------------------------------------------------------------------------
54
     */
55
    /**
56
     * Set a global where pattern on all routes.
57
     *
58
     * @param  string  $key
59
     * @param  string  $pattern
60
     */
61
    public function pattern($key, $pattern)
62
    {
63
        $this->router->pattern($key, $pattern);
64
    }
65
66
    /**
67
     * Set a group of global where patterns on all routes.
68
     *
69
     * @param  array  $patterns
70
     */
71
    public function patterns($patterns)
72
    {
73
        $this->router->patterns($patterns);
74
    }
75
76
    /* ------------------------------------------------------------------------------------------------
77
     |  Main Functions
78
     | ------------------------------------------------------------------------------------------------
79
     */
80
    /**
81
     * Register a new GET route with the router.
82
     *
83
     * @param  string                      $uri
84
     * @param  \Closure|array|string|null  $action
85
     *
86
     * @return \Illuminate\Routing\Route
87
     */
88
    protected function get($uri, $action = null)
89
    {
90
        return $this->router->get($uri, $action);
91
    }
92
93
    /**
94
     * Register a new POST route with the router.
95
     *
96
     * @param  string                      $uri
97
     * @param  \Closure|array|string|null  $action
98
     *
99
     * @return \Illuminate\Routing\Route
100
     */
101
    protected function post($uri, $action = null)
102
    {
103
        return $this->router->post($uri, $action);
104
    }
105
106
    /**
107
     * Register a new PUT route with the router.
108
     *
109
     * @param  string  $uri
110
     * @param  \Closure|array|string|null  $action
111
     * @return \Illuminate\Routing\Route
112
     */
113
    protected function put($uri, $action = null)
114
    {
115
        return $this->router->put($uri, $action);
116
    }
117
118
    /**
119
     * Register a new PATCH route with the router.
120
     *
121
     * @param  string                      $uri
122
     * @param  \Closure|array|string|null  $action
123
     *
124
     * @return \Illuminate\Routing\Route
125
     */
126
    protected function patch($uri, $action = null)
127
    {
128
        return $this->router->patch($uri, $action);
129
    }
130
131
    /**
132
     * Register a new DELETE route with the router.
133
     *
134
     * @param  string                      $uri
135
     * @param  \Closure|array|string|null  $action
136
     *
137
     * @return \Illuminate\Routing\Route
138
     */
139
    protected function delete($uri, $action = null)
140
    {
141
        return $this->router->delete($uri, $action);
142
    }
143
144
    /**
145
     * Register a new OPTIONS route with the router.
146
     *
147
     * @param  string                      $uri
148
     * @param  \Closure|array|string|null  $action
149
     *
150
     * @return \Illuminate\Routing\Route
151
     */
152
    protected function options($uri, $action = null)
153
    {
154
        return $this->router->options($uri, $action);
155
    }
156
157
    /**
158
     * Register a new route responding to all verbs.
159
     *
160
     * @param  string                      $uri
161
     * @param  \Closure|array|string|null  $action
162
     *
163
     * @return \Illuminate\Routing\Route
164
     */
165
    protected function any($uri, $action = null)
166
    {
167
        return $this->router->any($uri, $action);
168
    }
169
170
    /**
171
     * Add a new route parameter binder.
172
     *
173
     * @param  string           $key
174
     * @param  string|callable  $binder
175
     */
176
    protected function bind($key, $binder)
177
    {
178
        $this->router->bind($key, $binder);
179
    }
180
181
    /**
182
     * Register a model binder for a wildcard.
183
     *
184
     * @param  string         $key
185
     * @param  string         $class
186
     * @param  \Closure|null  $callback
187
     *
188
     * @throws \Illuminate\Database\Eloquent\ModelNotFoundException
189
     */
190
    public function model($key, $class, Closure $callback = null)
191
    {
192
        $this->router->model($key, $class, $callback);
193
    }
194
}
195