Subversion Repositories php-qbpwcf

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
3 liveuser 1
<?php
2
 
3
/*
4
 * This file is part of the Symfony package.
5
 *
6
 * (c) Fabien Potencier <fabien@symfony.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
 
12
namespace Symfony\Component\Routing\Annotation;
13
 
14
/**
15
 * Annotation class for @Route().
16
 *
17
 * @Annotation
18
 * @Target({"CLASS", "METHOD"})
19
 *
20
 * @author Fabien Potencier <fabien@symfony.com>
21
 */
22
class Route
23
{
24
    private $path;
25
    private $localizedPaths = [];
26
    private $name;
27
    private $requirements = [];
28
    private $options = [];
29
    private $defaults = [];
30
    private $host;
31
    private $methods = [];
32
    private $schemes = [];
33
    private $condition;
34
    private $priority;
35
 
36
    /**
37
     * @param array $data An array of key/value parameters
38
     *
39
     * @throws \BadMethodCallException
40
     */
41
    public function __construct(array $data)
42
    {
43
        if (isset($data['localized_paths'])) {
44
            throw new \BadMethodCallException(sprintf('Unknown property "localized_paths" on annotation "%s".', static::class));
45
        }
46
 
47
        if (isset($data['value'])) {
48
            $data[\is_array($data['value']) ? 'localized_paths' : 'path'] = $data['value'];
49
            unset($data['value']);
50
        }
51
 
52
        if (isset($data['path']) && \is_array($data['path'])) {
53
            $data['localized_paths'] = $data['path'];
54
            unset($data['path']);
55
        }
56
 
57
        if (isset($data['locale'])) {
58
            $data['defaults']['_locale'] = $data['locale'];
59
            unset($data['locale']);
60
        }
61
 
62
        if (isset($data['format'])) {
63
            $data['defaults']['_format'] = $data['format'];
64
            unset($data['format']);
65
        }
66
 
67
        if (isset($data['utf8'])) {
68
            $data['options']['utf8'] = filter_var($data['utf8'], \FILTER_VALIDATE_BOOLEAN) ?: false;
69
            unset($data['utf8']);
70
        }
71
 
72
        if (isset($data['stateless'])) {
73
            $data['defaults']['_stateless'] = filter_var($data['stateless'], \FILTER_VALIDATE_BOOLEAN) ?: false;
74
            unset($data['stateless']);
75
        }
76
 
77
        foreach ($data as $key => $value) {
78
            $method = 'set'.str_replace('_', '', $key);
79
            if (!method_exists($this, $method)) {
80
                throw new \BadMethodCallException(sprintf('Unknown property "%s" on annotation "%s".', $key, static::class));
81
            }
82
            $this->$method($value);
83
        }
84
    }
85
 
86
    public function setPath($path)
87
    {
88
        $this->path = $path;
89
    }
90
 
91
    public function getPath()
92
    {
93
        return $this->path;
94
    }
95
 
96
    public function setLocalizedPaths(array $localizedPaths)
97
    {
98
        $this->localizedPaths = $localizedPaths;
99
    }
100
 
101
    public function getLocalizedPaths(): array
102
    {
103
        return $this->localizedPaths;
104
    }
105
 
106
    public function setHost($pattern)
107
    {
108
        $this->host = $pattern;
109
    }
110
 
111
    public function getHost()
112
    {
113
        return $this->host;
114
    }
115
 
116
    public function setName($name)
117
    {
118
        $this->name = $name;
119
    }
120
 
121
    public function getName()
122
    {
123
        return $this->name;
124
    }
125
 
126
    public function setRequirements($requirements)
127
    {
128
        $this->requirements = $requirements;
129
    }
130
 
131
    public function getRequirements()
132
    {
133
        return $this->requirements;
134
    }
135
 
136
    public function setOptions($options)
137
    {
138
        $this->options = $options;
139
    }
140
 
141
    public function getOptions()
142
    {
143
        return $this->options;
144
    }
145
 
146
    public function setDefaults($defaults)
147
    {
148
        $this->defaults = $defaults;
149
    }
150
 
151
    public function getDefaults()
152
    {
153
        return $this->defaults;
154
    }
155
 
156
    public function setSchemes($schemes)
157
    {
158
        $this->schemes = \is_array($schemes) ? $schemes : [$schemes];
159
    }
160
 
161
    public function getSchemes()
162
    {
163
        return $this->schemes;
164
    }
165
 
166
    public function setMethods($methods)
167
    {
168
        $this->methods = \is_array($methods) ? $methods : [$methods];
169
    }
170
 
171
    public function getMethods()
172
    {
173
        return $this->methods;
174
    }
175
 
176
    public function setCondition($condition)
177
    {
178
        $this->condition = $condition;
179
    }
180
 
181
    public function getCondition()
182
    {
183
        return $this->condition;
184
    }
185
 
186
    public function setPriority(int $priority): void
187
    {
188
        $this->priority = $priority;
189
    }
190
 
191
    public function getPriority(): ?int
192
    {
193
        return $this->priority;
194
    }
195
}