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\Loader\Configurator\Traits;
13
 
14
use Symfony\Component\Routing\Route;
15
use Symfony\Component\Routing\RouteCollection;
16
 
17
trait RouteTrait
18
{
19
    /**
20
     * @var RouteCollection|Route
21
     */
22
    protected $route;
23
 
24
    /**
25
     * Adds defaults.
26
     *
27
     * @return $this
28
     */
29
    final public function defaults(array $defaults): self
30
    {
31
        $this->route->addDefaults($defaults);
32
 
33
        return $this;
34
    }
35
 
36
    /**
37
     * Adds requirements.
38
     *
39
     * @return $this
40
     */
41
    final public function requirements(array $requirements): self
42
    {
43
        $this->route->addRequirements($requirements);
44
 
45
        return $this;
46
    }
47
 
48
    /**
49
     * Adds options.
50
     *
51
     * @return $this
52
     */
53
    final public function options(array $options): self
54
    {
55
        $this->route->addOptions($options);
56
 
57
        return $this;
58
    }
59
 
60
    /**
61
     * Whether paths should accept utf8 encoding.
62
     *
63
     * @return $this
64
     */
65
    final public function utf8(bool $utf8 = true): self
66
    {
67
        $this->route->addOptions(['utf8' => $utf8]);
68
 
69
        return $this;
70
    }
71
 
72
    /**
73
     * Sets the condition.
74
     *
75
     * @return $this
76
     */
77
    final public function condition(string $condition): self
78
    {
79
        $this->route->setCondition($condition);
80
 
81
        return $this;
82
    }
83
 
84
    /**
85
     * Sets the pattern for the host.
86
     *
87
     * @return $this
88
     */
89
    final public function host(string $pattern): self
90
    {
91
        $this->route->setHost($pattern);
92
 
93
        return $this;
94
    }
95
 
96
    /**
97
     * Sets the schemes (e.g. 'https') this route is restricted to.
98
     * So an empty array means that any scheme is allowed.
99
     *
100
     * @param string[] $schemes
101
     *
102
     * @return $this
103
     */
104
    final public function schemes(array $schemes): self
105
    {
106
        $this->route->setSchemes($schemes);
107
 
108
        return $this;
109
    }
110
 
111
    /**
112
     * Sets the HTTP methods (e.g. 'POST') this route is restricted to.
113
     * So an empty array means that any method is allowed.
114
     *
115
     * @param string[] $methods
116
     *
117
     * @return $this
118
     */
119
    final public function methods(array $methods): self
120
    {
121
        $this->route->setMethods($methods);
122
 
123
        return $this;
124
    }
125
 
126
    /**
127
     * Adds the "_controller" entry to defaults.
128
     *
129
     * @param callable|string $controller a callable or parseable pseudo-callable
130
     *
131
     * @return $this
132
     */
133
    final public function controller($controller): self
134
    {
135
        $this->route->addDefaults(['_controller' => $controller]);
136
 
137
        return $this;
138
    }
139
 
140
    /**
141
     * Adds the "_locale" entry to defaults.
142
     *
143
     * @return $this
144
     */
145
    final public function locale(string $locale): self
146
    {
147
        $this->route->addDefaults(['_locale' => $locale]);
148
 
149
        return $this;
150
    }
151
 
152
    /**
153
     * Adds the "_format" entry to defaults.
154
     *
155
     * @return $this
156
     */
157
    final public function format(string $format): self
158
    {
159
        $this->route->addDefaults(['_format' => $format]);
160
 
161
        return $this;
162
    }
163
 
164
    /**
165
     * Adds the "_stateless" entry to defaults.
166
     *
167
     * @return $this
168
     */
169
    final public function stateless(bool $stateless = true): self
170
    {
171
        $this->route->addDefaults(['_stateless' => $stateless]);
172
 
173
        return $this;
174
    }
175
}