Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Illuminate\Routing;
4
 
5
use Illuminate\Support\Arr;
6
use Illuminate\Support\Traits\Macroable;
7
 
8
class PendingResourceRegistration
9
{
10
    use CreatesRegularExpressionRouteConstraints, Macroable;
11
 
12
    /**
13
     * The resource registrar.
14
     *
15
     * @var \Illuminate\Routing\ResourceRegistrar
16
     */
17
    protected $registrar;
18
 
19
    /**
20
     * The resource name.
21
     *
22
     * @var string
23
     */
24
    protected $name;
25
 
26
    /**
27
     * The resource controller.
28
     *
29
     * @var string
30
     */
31
    protected $controller;
32
 
33
    /**
34
     * The resource options.
35
     *
36
     * @var array
37
     */
38
    protected $options = [];
39
 
40
    /**
41
     * The resource's registration status.
42
     *
43
     * @var bool
44
     */
45
    protected $registered = false;
46
 
47
    /**
48
     * Create a new pending resource registration instance.
49
     *
50
     * @param  \Illuminate\Routing\ResourceRegistrar  $registrar
51
     * @param  string  $name
52
     * @param  string  $controller
53
     * @param  array  $options
54
     * @return void
55
     */
56
    public function __construct(ResourceRegistrar $registrar, $name, $controller, array $options)
57
    {
58
        $this->name = $name;
59
        $this->options = $options;
60
        $this->registrar = $registrar;
61
        $this->controller = $controller;
62
    }
63
 
64
    /**
65
     * Set the methods the controller should apply to.
66
     *
67
     * @param  array|string|dynamic  $methods
68
     * @return \Illuminate\Routing\PendingResourceRegistration
69
     */
70
    public function only($methods)
71
    {
72
        $this->options['only'] = is_array($methods) ? $methods : func_get_args();
73
 
74
        return $this;
75
    }
76
 
77
    /**
78
     * Set the methods the controller should exclude.
79
     *
80
     * @param  array|string|dynamic  $methods
81
     * @return \Illuminate\Routing\PendingResourceRegistration
82
     */
83
    public function except($methods)
84
    {
85
        $this->options['except'] = is_array($methods) ? $methods : func_get_args();
86
 
87
        return $this;
88
    }
89
 
90
    /**
91
     * Set the route names for controller actions.
92
     *
93
     * @param  array|string  $names
94
     * @return \Illuminate\Routing\PendingResourceRegistration
95
     */
96
    public function names($names)
97
    {
98
        $this->options['names'] = $names;
99
 
100
        return $this;
101
    }
102
 
103
    /**
104
     * Set the route name for a controller action.
105
     *
106
     * @param  string  $method
107
     * @param  string  $name
108
     * @return \Illuminate\Routing\PendingResourceRegistration
109
     */
110
    public function name($method, $name)
111
    {
112
        $this->options['names'][$method] = $name;
113
 
114
        return $this;
115
    }
116
 
117
    /**
118
     * Override the route parameter names.
119
     *
120
     * @param  array|string  $parameters
121
     * @return \Illuminate\Routing\PendingResourceRegistration
122
     */
123
    public function parameters($parameters)
124
    {
125
        $this->options['parameters'] = $parameters;
126
 
127
        return $this;
128
    }
129
 
130
    /**
131
     * Override a route parameter's name.
132
     *
133
     * @param  string  $previous
134
     * @param  string  $new
135
     * @return \Illuminate\Routing\PendingResourceRegistration
136
     */
137
    public function parameter($previous, $new)
138
    {
139
        $this->options['parameters'][$previous] = $new;
140
 
141
        return $this;
142
    }
143
 
144
    /**
145
     * Add middleware to the resource routes.
146
     *
147
     * @param  mixed  $middleware
148
     * @return \Illuminate\Routing\PendingResourceRegistration
149
     */
150
    public function middleware($middleware)
151
    {
152
        $middleware = Arr::wrap($middleware);
153
 
154
        foreach ($middleware as $key => $value) {
155
            $middleware[$key] = (string) $value;
156
        }
157
 
158
        $this->options['middleware'] = $middleware;
159
 
160
        return $this;
161
    }
162
 
163
    /**
164
     * Specify middleware that should be removed from the resource routes.
165
     *
166
     * @param  array|string  $middleware
167
     * @return $this|array
168
     */
169
    public function withoutMiddleware($middleware)
170
    {
171
        $this->options['excluded_middleware'] = array_merge(
172
            (array) ($this->options['excluded_middleware'] ?? []), Arr::wrap($middleware)
173
        );
174
 
175
        return $this;
176
    }
177
 
178
    /**
179
     * Add "where" constraints to the resource routes.
180
     *
181
     * @param  mixed  $wheres
182
     * @return \Illuminate\Routing\PendingResourceRegistration
183
     */
184
    public function where($wheres)
185
    {
186
        $this->options['wheres'] = $wheres;
187
 
188
        return $this;
189
    }
190
 
191
    /**
192
     * Indicate that the resource routes should have "shallow" nesting.
193
     *
194
     * @param  bool  $shallow
195
     * @return \Illuminate\Routing\PendingResourceRegistration
196
     */
197
    public function shallow($shallow = true)
198
    {
199
        $this->options['shallow'] = $shallow;
200
 
201
        return $this;
202
    }
203
 
204
    /**
205
     * Define the callable that should be invoked on a missing model exception.
206
     *
207
     * @param  callable  $callback
208
     * @return $this
209
     */
210
    public function missing($callback)
211
    {
212
        $this->options['missing'] = $callback;
213
 
214
        return $this;
215
    }
216
 
217
    /**
218
     * Indicate that the resource routes should be scoped using the given binding fields.
219
     *
220
     * @param  array  $fields
221
     * @return \Illuminate\Routing\PendingResourceRegistration
222
     */
223
    public function scoped(array $fields = [])
224
    {
225
        $this->options['bindingFields'] = $fields;
226
 
227
        return $this;
228
    }
229
 
230
    /**
231
     * Define which routes should allow "trashed" models to be retrieved when resolving implicit model bindings.
232
     *
233
     * @param  array  $methods
234
     * @return \Illuminate\Routing\PendingResourceRegistration
235
     */
236
    public function withTrashed(array $methods = [])
237
    {
238
        $this->options['trashed'] = $methods;
239
 
240
        return $this;
241
    }
242
 
243
    /**
244
     * Register the resource route.
245
     *
246
     * @return \Illuminate\Routing\RouteCollection
247
     */
248
    public function register()
249
    {
250
        $this->registered = true;
251
 
252
        return $this->registrar->register(
253
            $this->name, $this->controller, $this->options
254
        );
255
    }
256
 
257
    /**
258
     * Handle the object's destruction.
259
     *
260
     * @return void
261
     */
262
    public function __destruct()
263
    {
264
        if (! $this->registered) {
265
            $this->register();
266
        }
267
    }
268
}