Spaces:
Runtime error

File size: 9,581 Bytes
7a66774
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Routing\Attribute;

use Symfony\Component\Routing\Exception\LogicException;

/**
 * @author Fabien Potencier <fabien@symfony.com>
 * @author Alexander M. Turek <me@derrabus.de>
 */
#[\Attribute(\Attribute::IS_REPEATABLE | \Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD)]
class Route
{
    /** @var string[] */
    public array $methods;

    /** @var string[] */
    public array $envs;

    /** @var string[] */
    public array $schemes;

    /** @var (string|DeprecatedAlias)[] */
    public array $aliases = [];

    /**
     * @param string|array<string,string>|null                  $path         The route path (i.e. "/user/login")
     * @param string|null                                       $name         The route name (i.e. "app_user_login")
     * @param array<string|\Stringable>                         $requirements Requirements for the route attributes, @see https://symfony.com/doc/current/routing.html#parameters-validation
     * @param array<string, mixed>                              $options      Options for the route (i.e. ['prefix' => '/api'])
     * @param array<string, mixed>                              $defaults     Default values for the route attributes and query parameters
     * @param string|null                                       $host         The host for which this route should be active (i.e. "localhost")
     * @param string|string[]                                   $methods      The list of HTTP methods allowed by this route
     * @param string|string[]                                   $schemes      The list of schemes allowed by this route (i.e. "https")
     * @param string|null                                       $condition    An expression that must evaluate to true for the route to be matched, @see https://symfony.com/doc/current/routing.html#matching-expressions
     * @param int|null                                          $priority     The priority of the route if multiple ones are defined for the same path
     * @param string|null                                       $locale       The locale accepted by the route
     * @param string|null                                       $format       The format returned by the route (i.e. "json", "xml")
     * @param bool|null                                         $utf8         Whether the route accepts UTF-8 in its parameters
     * @param bool|null                                         $stateless    Whether the route is defined as stateless or stateful, @see https://symfony.com/doc/current/routing.html#stateless-routes
     * @param string|string[]|null                              $env          The env(s) in which the route is defined (i.e. "dev", "test", "prod", ["dev", "test"])
     * @param string|DeprecatedAlias|(string|DeprecatedAlias)[] $alias        The list of aliases for this route
     */
    public function __construct(
        public string|array|null $path = null,
        public ?string $name = null,
        public array $requirements = [],
        public array $options = [],
        public array $defaults = [],
        public ?string $host = null,
        array|string $methods = [],
        array|string $schemes = [],
        public ?string $condition = null,
        public ?int $priority = null,
        ?string $locale = null,
        ?string $format = null,
        ?bool $utf8 = null,
        ?bool $stateless = null,
        string|array|null $env = null,
        string|DeprecatedAlias|array $alias = [],
    ) {
        $this->path = $path;
        $this->methods = (array) $methods;
        $this->schemes = (array) $schemes;
        $this->envs = (array) $env;
        $this->aliases = \is_array($alias) ? $alias : [$alias];

        if (null !== $locale) {
            $this->defaults['_locale'] = $locale;
        }

        if (null !== $format) {
            $this->defaults['_format'] = $format;
        }

        if (null !== $utf8) {
            $this->options['utf8'] = $utf8;
        }

        if (null !== $stateless) {
            $this->defaults['_stateless'] = $stateless;
        }
    }

    #[\Deprecated('Use the "path" property instead', 'symfony/routing:7.4')]
    public function setPath(string $path): void
    {
        $this->path = $path;
    }

    #[\Deprecated('Use the "path" property instead', 'symfony/routing:7.4')]
    public function getPath(): ?string
    {
        return \is_array($this->path) ? null : $this->path;
    }

    #[\Deprecated('Use the "path" property instead', 'symfony/routing:7.4')]
    public function setLocalizedPaths(array $localizedPaths): void
    {
        $this->path = $localizedPaths;
    }

    #[\Deprecated('Use the "path" property instead', 'symfony/routing:7.4')]
    public function getLocalizedPaths(): array
    {
        return \is_array($this->path) ? $this->path : [];
    }

    #[\Deprecated('Use the "host" property instead', 'symfony/routing:7.4')]
    public function setHost(string $pattern): void
    {
        $this->host = $pattern;
    }

    #[\Deprecated('Use the "host" property instead', 'symfony/routing:7.4')]
    public function getHost(): ?string
    {
        return $this->host;
    }

    #[\Deprecated('Use the "name" property instead', 'symfony/routing:7.4')]
    public function setName(string $name): void
    {
        $this->name = $name;
    }

    #[\Deprecated('Use the "name" property instead', 'symfony/routing:7.4')]
    public function getName(): ?string
    {
        return $this->name;
    }

    #[\Deprecated('Use the "requirements" property instead', 'symfony/routing:7.4')]
    public function setRequirements(array $requirements): void
    {
        $this->requirements = $requirements;
    }

    #[\Deprecated('Use the "requirements" property instead', 'symfony/routing:7.4')]
    public function getRequirements(): array
    {
        return $this->requirements;
    }

    #[\Deprecated('Use the "options" property instead', 'symfony/routing:7.4')]
    public function setOptions(array $options): void
    {
        $this->options = $options;
    }

    #[\Deprecated('Use the "options" property instead', 'symfony/routing:7.4')]
    public function getOptions(): array
    {
        return $this->options;
    }

    #[\Deprecated('Use the "defaults" property instead', 'symfony/routing:7.4')]
    public function setDefaults(array $defaults): void
    {
        $this->defaults = $defaults;
    }

    #[\Deprecated('Use the "defaults" property instead', 'symfony/routing:7.4')]
    public function getDefaults(): array
    {
        return $this->defaults;
    }

    #[\Deprecated('Use the "schemes" property instead', 'symfony/routing:7.4')]
    public function setSchemes(array|string $schemes): void
    {
        $this->schemes = (array) $schemes;
    }

    #[\Deprecated('Use the "schemes" property instead', 'symfony/routing:7.4')]
    public function getSchemes(): array
    {
        return $this->schemes;
    }

    #[\Deprecated('Use the "methods" property instead', 'symfony/routing:7.4')]
    public function setMethods(array|string $methods): void
    {
        $this->methods = (array) $methods;
    }

    #[\Deprecated('Use the "methods" property instead', 'symfony/routing:7.4')]
    public function getMethods(): array
    {
        return $this->methods;
    }

    #[\Deprecated('Use the "condition" property instead', 'symfony/routing:7.4')]
    public function setCondition(?string $condition): void
    {
        $this->condition = $condition;
    }

    #[\Deprecated('Use the "condition" property instead', 'symfony/routing:7.4')]
    public function getCondition(): ?string
    {
        return $this->condition;
    }

    #[\Deprecated('Use the "priority" property instead', 'symfony/routing:7.4')]
    public function setPriority(int $priority): void
    {
        $this->priority = $priority;
    }

    #[\Deprecated('Use the "priority" property instead', 'symfony/routing:7.4')]
    public function getPriority(): ?int
    {
        return $this->priority;
    }

    #[\Deprecated('Use the "envs" property instead', 'symfony/routing:7.4')]
    public function setEnv(?string $env): void
    {
        $this->envs = (array) $env;
    }

    #[\Deprecated('Use the "envs" property instead', 'symfony/routing:7.4')]
    public function getEnv(): ?string
    {
        if (!$this->envs) {
            return null;
        }
        if (\count($this->envs) > 1) {
            throw new LogicException(\sprintf('The "env" property has %d environments. Use "getEnvs()" to get all of them.', \count($this->envs)));
        }

        return $this->envs[0];
    }

    /**
     * @return (string|DeprecatedAlias)[]
     */
    #[\Deprecated('Use the "aliases" property instead', 'symfony/routing:7.4')]
    public function getAliases(): array
    {
        return $this->aliases;
    }

    /**
     * @param string|DeprecatedAlias|(string|DeprecatedAlias)[] $aliases
     */
    #[\Deprecated('Use the "aliases" property instead', 'symfony/routing:7.4')]
    public function setAliases(string|DeprecatedAlias|array $aliases): void
    {
        $this->aliases = \is_array($aliases) ? $aliases : [$aliases];
    }
}

if (!class_exists(\Symfony\Component\Routing\Annotation\Route::class, false)) {
    class_alias(Route::class, \Symfony\Component\Routing\Annotation\Route::class);
}