Subversion-Projekte lars-tiefland.laravel_shop

Revision

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