Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 148 | Details | Vergleich mit vorheriger | 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 PendingSingletonResourceRegistration
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 singleton 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\PendingSingletonResourceRegistration
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\PendingSingletonResourceRegistration
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
     * Indicate that the resource should have creation and storage routes.
92
     *
93
     * @return $this
94
     */
1464 lars 95
    public function creatable()
148 lars 96
    {
1464 lars 97
        $this->options['creatable'] = true;
148 lars 98
 
99
        return $this;
100
    }
101
 
102
    /**
103
     * Indicate that the resource should have a deletion route.
104
     *
105
     * @return $this
106
     */
1464 lars 107
    public function destroyable()
148 lars 108
    {
1464 lars 109
        $this->options['destroyable'] = true;
148 lars 110
 
111
        return $this;
112
    }
113
 
114
    /**
115
     * Set the route names for controller actions.
116
     *
117
     * @param  array|string  $names
118
     * @return \Illuminate\Routing\PendingSingletonResourceRegistration
119
     */
120
    public function names($names)
121
    {
122
        $this->options['names'] = $names;
123
 
124
        return $this;
125
    }
126
 
127
    /**
128
     * Set the route name for a controller action.
129
     *
130
     * @param  string  $method
131
     * @param  string  $name
132
     * @return \Illuminate\Routing\PendingSingletonResourceRegistration
133
     */
134
    public function name($method, $name)
135
    {
136
        $this->options['names'][$method] = $name;
137
 
138
        return $this;
139
    }
140
 
141
    /**
142
     * Override the route parameter names.
143
     *
144
     * @param  array|string  $parameters
145
     * @return \Illuminate\Routing\PendingSingletonResourceRegistration
146
     */
147
    public function parameters($parameters)
148
    {
149
        $this->options['parameters'] = $parameters;
150
 
151
        return $this;
152
    }
153
 
154
    /**
155
     * Override a route parameter's name.
156
     *
157
     * @param  string  $previous
158
     * @param  string  $new
159
     * @return \Illuminate\Routing\PendingSingletonResourceRegistration
160
     */
161
    public function parameter($previous, $new)
162
    {
163
        $this->options['parameters'][$previous] = $new;
164
 
165
        return $this;
166
    }
167
 
168
    /**
169
     * Add middleware to the resource routes.
170
     *
171
     * @param  mixed  $middleware
172
     * @return \Illuminate\Routing\PendingSingletonResourceRegistration
173
     */
174
    public function middleware($middleware)
175
    {
176
        $middleware = Arr::wrap($middleware);
177
 
178
        foreach ($middleware as $key => $value) {
179
            $middleware[$key] = (string) $value;
180
        }
181
 
182
        $this->options['middleware'] = $middleware;
183
 
184
        return $this;
185
    }
186
 
187
    /**
188
     * Specify middleware that should be removed from the resource routes.
189
     *
190
     * @param  array|string  $middleware
191
     * @return $this|array
192
     */
193
    public function withoutMiddleware($middleware)
194
    {
195
        $this->options['excluded_middleware'] = array_merge(
196
            (array) ($this->options['excluded_middleware'] ?? []), Arr::wrap($middleware)
197
        );
198
 
199
        return $this;
200
    }
201
 
202
    /**
203
     * Add "where" constraints to the resource routes.
204
     *
205
     * @param  mixed  $wheres
206
     * @return \Illuminate\Routing\PendingSingletonResourceRegistration
207
     */
208
    public function where($wheres)
209
    {
210
        $this->options['wheres'] = $wheres;
211
 
212
        return $this;
213
    }
214
 
215
    /**
216
     * Register the singleton resource route.
217
     *
218
     * @return \Illuminate\Routing\RouteCollection
219
     */
220
    public function register()
221
    {
222
        $this->registered = true;
223
 
224
        return $this->registrar->singleton(
225
            $this->name, $this->controller, $this->options
226
        );
227
    }
228
 
229
    /**
230
     * Handle the object's destruction.
231
     *
232
     * @return void
233
     */
234
    public function __destruct()
235
    {
236
        if (! $this->registered) {
237
            $this->register();
238
        }
239
    }
240
}