Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit bbea1e6

Browse filesBrowse files
minor #33191 [Routing] Add more parameter types (derrabus)
This PR was merged into the 5.0-dev branch. Discussion ---------- [Routing] Add more parameter types | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #32179 | License | MIT | Doc PR | N/A Commits ------- daf402e [Routing] Add more parameter types.
2 parents 0b6f45e + daf402e commit bbea1e6
Copy full SHA for bbea1e6

13 files changed

+42
-73
lines changed

‎src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php
+6-9Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,19 +74,16 @@ public function __construct(Reader $reader)
7474

7575
/**
7676
* Sets the annotation class to read route properties from.
77-
*
78-
* @param string $class A fully-qualified class name
7977
*/
80-
public function setRouteAnnotationClass($class)
78+
public function setRouteAnnotationClass(string $class)
8179
{
8280
$this->routeAnnotationClass = $class;
8381
}
8482

8583
/**
8684
* Loads from annotations from a class.
8785
*
88-
* @param string $class A class name
89-
* @param string|null $type The resource type
86+
* @param string $class A class name
9087
*
9188
* @return RouteCollection A RouteCollection instance
9289
*
@@ -129,7 +126,7 @@ public function load($class, string $type = null)
129126
return $collection;
130127
}
131128

132-
protected function addRoute(RouteCollection $collection, $annot, $globals, \ReflectionClass $class, \ReflectionMethod $method)
129+
protected function addRoute(RouteCollection $collection, $annot, array $globals, \ReflectionClass $class, \ReflectionMethod $method)
133130
{
134131
$name = $annot->getName();
135132
if (null === $name) {
@@ -217,7 +214,7 @@ protected function addRoute(RouteCollection $collection, $annot, $globals, \Refl
217214
/**
218215
* {@inheritdoc}
219216
*/
220-
public function supports($resource, $type = null)
217+
public function supports($resource, string $type = null)
221218
{
222219
return \is_string($resource) && preg_match('/^(?:\\\\?[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)+$/', $resource) && (!$type || 'annotation' === $type);
223220
}
@@ -306,7 +303,7 @@ protected function getGlobals(\ReflectionClass $class)
306303
return $globals;
307304
}
308305

309-
private function resetGlobals()
306+
private function resetGlobals(): array
310307
{
311308
return [
312309
'path' => null,
@@ -322,7 +319,7 @@ private function resetGlobals()
322319
];
323320
}
324321

325-
protected function createRoute($path, $defaults, $requirements, $options, $host, $schemes, $methods, $condition)
322+
protected function createRoute(string $path, array $defaults, array $requirements, array $options, ?string $host, array $schemes, array $methods, ?string $condition)
326323
{
327324
return new Route($path, $defaults, $requirements, $options, $host, $schemes, $methods, $condition);
328325
}

‎src/Symfony/Component/Routing/Loader/AnnotationFileLoader.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/Loader/AnnotationFileLoader.php
+1-3Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,9 @@ public function supports($resource, string $type = null)
8181
/**
8282
* Returns the full class name for the first class in the file.
8383
*
84-
* @param string $file A PHP file path
85-
*
8684
* @return string|false Full class name if found, false otherwise
8785
*/
88-
protected function findClass($file)
86+
protected function findClass(string $file)
8987
{
9088
$class = false;
9189
$namespace = false;

‎src/Symfony/Component/Routing/Loader/Configurator/RoutingConfigurator.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/Loader/Configurator/RoutingConfigurator.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function __construct(RouteCollection $collection, PhpFileLoader $loader,
3333
$this->file = $file;
3434
}
3535

36-
final public function import($resource, $type = null, $ignoreErrors = false): ImportConfigurator
36+
final public function import($resource, string $type = null, bool $ignoreErrors = false): ImportConfigurator
3737
{
3838
$this->loader->setCurrentDir(\dirname($this->path));
3939
$imported = $this->loader->import($resource, $type, $ignoreErrors, $this->file);
@@ -49,7 +49,7 @@ final public function import($resource, $type = null, $ignoreErrors = false): Im
4949
return new ImportConfigurator($this->collection, $mergedCollection);
5050
}
5151

52-
final public function collection($name = ''): CollectionConfigurator
52+
final public function collection(string $name = ''): CollectionConfigurator
5353
{
5454
return new CollectionConfigurator($this->collection, $name);
5555
}

‎src/Symfony/Component/Routing/Loader/XmlFileLoader.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/Loader/XmlFileLoader.php
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function load($file, string $type = null)
6969
*
7070
* @throws \InvalidArgumentException When the XML is invalid
7171
*/
72-
protected function parseNode(RouteCollection $collection, \DOMElement $node, $path, $file)
72+
protected function parseNode(RouteCollection $collection, \DOMElement $node, string $path, string $file)
7373
{
7474
if (self::NAMESPACE_URI !== $node->namespaceURI) {
7575
return;
@@ -103,7 +103,7 @@ public function supports($resource, string $type = null)
103103
*
104104
* @throws \InvalidArgumentException When the XML is invalid
105105
*/
106-
protected function parseRoute(RouteCollection $collection, \DOMElement $node, $path)
106+
protected function parseRoute(RouteCollection $collection, \DOMElement $node, string $path)
107107
{
108108
if ('' === $id = $node->getAttribute('id')) {
109109
throw new \InvalidArgumentException(sprintf('The <route> element in file "%s" must have an "id" attribute.', $path));
@@ -144,7 +144,7 @@ protected function parseRoute(RouteCollection $collection, \DOMElement $node, $p
144144
*
145145
* @throws \InvalidArgumentException When the XML is invalid
146146
*/
147-
protected function parseImport(RouteCollection $collection, \DOMElement $node, $path, $file)
147+
protected function parseImport(RouteCollection $collection, \DOMElement $node, string $path, string $file)
148148
{
149149
if ('' === $resource = $node->getAttribute('resource')) {
150150
throw new \InvalidArgumentException(sprintf('The <import> element in file "%s" must have a "resource" attribute.', $path));
@@ -242,7 +242,7 @@ protected function parseImport(RouteCollection $collection, \DOMElement $node, $
242242
* or when the XML structure is not as expected by the scheme -
243243
* see validate()
244244
*/
245-
protected function loadFile($file)
245+
protected function loadFile(string $file)
246246
{
247247
return XmlUtils::loadFile($file, __DIR__.static::SCHEME_PATH);
248248
}

‎src/Symfony/Component/Routing/Loader/YamlFileLoader.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/Loader/YamlFileLoader.php
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public function load($file, string $type = null)
9393
/**
9494
* {@inheritdoc}
9595
*/
96-
public function supports($resource, $type = null)
96+
public function supports($resource, string $type = null)
9797
{
9898
return \is_string($resource) && \in_array(pathinfo($resource, PATHINFO_EXTENSION), ['yml', 'yaml'], true) && (!$type || 'yaml' === $type);
9999
}
@@ -105,7 +105,7 @@ public function supports($resource, $type = null)
105105
* @param array $config Route definition
106106
* @param string $path Full path of the YAML file being processed
107107
*/
108-
protected function parseRoute(RouteCollection $collection, $name, array $config, $path)
108+
protected function parseRoute(RouteCollection $collection, string $name, array $config, string $path)
109109
{
110110
$defaults = isset($config['defaults']) ? $config['defaults'] : [];
111111
$requirements = isset($config['requirements']) ? $config['requirements'] : [];
@@ -157,7 +157,7 @@ protected function parseRoute(RouteCollection $collection, $name, array $config,
157157
* @param string $path Full path of the YAML file being processed
158158
* @param string $file Loaded file name
159159
*/
160-
protected function parseImport(RouteCollection $collection, array $config, $path, $file)
160+
protected function parseImport(RouteCollection $collection, array $config, string $path, string $file)
161161
{
162162
$type = isset($config['type']) ? $config['type'] : null;
163163
$prefix = isset($config['prefix']) ? $config['prefix'] : '';
@@ -260,7 +260,7 @@ protected function parseImport(RouteCollection $collection, array $config, $path
260260
* @throws \InvalidArgumentException If one of the provided config keys is not supported,
261261
* something is missing or the combination is nonsense
262262
*/
263-
protected function validate($config, $name, $path)
263+
protected function validate($config, string $name, string $path)
264264
{
265265
if (!\is_array($config)) {
266266
throw new \InvalidArgumentException(sprintf('The definition of "%s" in "%s" must be a YAML array.', $name, $path));

‎src/Symfony/Component/Routing/Matcher/Dumper/CompiledUrlMatcherTrait.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/Matcher/Dumper/CompiledUrlMatcherTrait.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ trait CompiledUrlMatcherTrait
3232
private $dynamicRoutes = [];
3333
private $checkCondition;
3434

35-
public function match($pathinfo)
35+
public function match(string $pathinfo)
3636
{
3737
$allow = $allowSchemes = [];
3838
if ($ret = $this->doMatch($pathinfo, $allow, $allowSchemes)) {

‎src/Symfony/Component/Routing/Matcher/TraceableUrlMatcher.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/Matcher/TraceableUrlMatcher.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class TraceableUrlMatcher extends UrlMatcher
2929

3030
protected $traces;
3131

32-
public function getTraces($pathinfo)
32+
public function getTraces(string $pathinfo)
3333
{
3434
$this->traces = [];
3535

@@ -50,7 +50,7 @@ public function getTracesForRequest(Request $request)
5050
return $traces;
5151
}
5252

53-
protected function matchCollection($pathinfo, RouteCollection $routes)
53+
protected function matchCollection(string $pathinfo, RouteCollection $routes)
5454
{
5555
foreach ($routes as $name => $route) {
5656
$compiledRoute = $route->compile();

‎src/Symfony/Component/Routing/Matcher/UrlMatcher.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/Matcher/UrlMatcher.php
+5-14Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public function addExpressionLanguageProvider(ExpressionFunctionProviderInterfac
128128
* @throws ResourceNotFoundException If the resource could not be found
129129
* @throws MethodNotAllowedException If the resource was found but the request method is not allowed
130130
*/
131-
protected function matchCollection($pathinfo, RouteCollection $routes)
131+
protected function matchCollection(string $pathinfo, RouteCollection $routes)
132132
{
133133
// HEAD and GET are equivalent as per RFC
134134
if ('HEAD' === $method = $this->context->getMethod()) {
@@ -207,12 +207,9 @@ protected function matchCollection($pathinfo, RouteCollection $routes)
207207
* in matchers that do not have access to the matched Route instance
208208
* (like the PHP and Apache matcher dumpers).
209209
*
210-
* @param string $name The name of the route
211-
* @param array $attributes An array of attributes from the matcher
212-
*
213210
* @return array An array of parameters
214211
*/
215-
protected function getAttributes(Route $route, $name, array $attributes)
212+
protected function getAttributes(Route $route, string $name, array $attributes)
216213
{
217214
$defaults = $route->getDefaults();
218215
if (isset($defaults['_canonical_route'])) {
@@ -227,12 +224,9 @@ protected function getAttributes(Route $route, $name, array $attributes)
227224
/**
228225
* Handles specific route requirements.
229226
*
230-
* @param string $pathinfo The path
231-
* @param string $name The route name
232-
*
233227
* @return array The first element represents the status, the second contains additional information
234228
*/
235-
protected function handleRouteRequirements($pathinfo, $name, Route $route)
229+
protected function handleRouteRequirements(string $pathinfo, string $name, Route $route)
236230
{
237231
// expression condition
238232
if ($route->getCondition() && !$this->getExpressionLanguage()->evaluate($route->getCondition(), ['context' => $this->context, 'request' => $this->request ?: $this->createRequest($pathinfo)])) {
@@ -245,12 +239,9 @@ protected function handleRouteRequirements($pathinfo, $name, Route $route)
245239
/**
246240
* Get merged default parameters.
247241
*
248-
* @param array $params The parameters
249-
* @param array $defaults The defaults
250-
*
251242
* @return array Merged default parameters
252243
*/
253-
protected function mergeDefaults($params, $defaults)
244+
protected function mergeDefaults(array $params, array $defaults)
254245
{
255246
foreach ($params as $key => $value) {
256247
if (!\is_int($key) && null !== $value) {
@@ -276,7 +267,7 @@ protected function getExpressionLanguage()
276267
/**
277268
* @internal
278269
*/
279-
protected function createRequest($pathinfo)
270+
protected function createRequest(string $pathinfo)
280271
{
281272
if (!class_exists('Symfony\Component\HttpFoundation\Request')) {
282273
return null;

‎src/Symfony/Component/Routing/RouteCollectionBuilder.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/RouteCollectionBuilder.php
+13-30Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,13 @@ public function __construct(LoaderInterface $loader = null)
4848
*
4949
* $routes->import('blog.yml', '/blog');
5050
*
51-
* @param mixed $resource
52-
* @param string|null $prefix
53-
* @param string $type
51+
* @param mixed $resource
5452
*
5553
* @return self
5654
*
5755
* @throws LoaderLoadException
5856
*/
59-
public function import($resource, $prefix = '/', $type = null)
57+
public function import($resource, string $prefix = '/', string $type = null)
6058
{
6159
/** @var RouteCollection[] $collections */
6260
$collections = $this->load($resource, $type);
@@ -87,13 +85,9 @@ public function import($resource, $prefix = '/', $type = null)
8785
/**
8886
* Adds a route and returns it for future modification.
8987
*
90-
* @param string $path The route path
91-
* @param string $controller The route's controller
92-
* @param string|null $name The name to give this route
93-
*
9488
* @return Route
9589
*/
96-
public function add($path, $controller, $name = null)
90+
public function add(string $path, string $controller, string $name = null)
9791
{
9892
$route = new Route($path);
9993
$route->setDefault('_controller', $controller);
@@ -114,10 +108,8 @@ public function createBuilder()
114108

115109
/**
116110
* Add a RouteCollectionBuilder.
117-
*
118-
* @param string $prefix
119111
*/
120-
public function mount($prefix, self $builder)
112+
public function mount(string $prefix, self $builder)
121113
{
122114
$builder->prefix = trim(trim($prefix), '/');
123115
$this->routes[] = $builder;
@@ -126,11 +118,9 @@ public function mount($prefix, self $builder)
126118
/**
127119
* Adds a Route object to the builder.
128120
*
129-
* @param string|null $name
130-
*
131121
* @return $this
132122
*/
133-
public function addRoute(Route $route, $name = null)
123+
public function addRoute(Route $route, string $name = null)
134124
{
135125
if (null === $name) {
136126
// used as a flag to know which routes will need a name later
@@ -145,11 +135,9 @@ public function addRoute(Route $route, $name = null)
145135
/**
146136
* Sets the host on all embedded routes (unless already set).
147137
*
148-
* @param string $pattern
149-
*
150138
* @return $this
151139
*/
152-
public function setHost($pattern)
140+
public function setHost(?string $pattern)
153141
{
154142
$this->host = $pattern;
155143

@@ -159,11 +147,9 @@ public function setHost($pattern)
159147
/**
160148
* Sets a condition on all embedded routes (unless already set).
161149
*
162-
* @param string $condition
163-
*
164150
* @return $this
165151
*/
166-
public function setCondition($condition)
152+
public function setCondition(?string $condition)
167153
{
168154
$this->condition = $condition;
169155

@@ -174,12 +160,11 @@ public function setCondition($condition)
174160
* Sets a default value that will be added to all embedded routes (unless that
175161
* default value is already set).
176162
*
177-
* @param string $key
178-
* @param mixed $value
163+
* @param mixed $value
179164
*
180165
* @return $this
181166
*/
182-
public function setDefault($key, $value)
167+
public function setDefault(string $key, $value)
183168
{
184169
$this->defaults[$key] = $value;
185170

@@ -190,12 +175,11 @@ public function setDefault($key, $value)
190175
* Sets a requirement that will be added to all embedded routes (unless that
191176
* requirement is already set).
192177
*
193-
* @param string $key
194-
* @param mixed $regex
178+
* @param mixed $regex
195179
*
196180
* @return $this
197181
*/
198-
public function setRequirement($key, $regex)
182+
public function setRequirement(string $key, $regex)
199183
{
200184
$this->requirements[$key] = $regex;
201185

@@ -206,12 +190,11 @@ public function setRequirement($key, $regex)
206190
* Sets an option that will be added to all embedded routes (unless that
207191
* option is already set).
208192
*
209-
* @param string $key
210-
* @param mixed $value
193+
* @param mixed $value
211194
*
212195
* @return $this
213196
*/
214-
public function setOption($key, $value)
197+
public function setOption(string $key, $value)
215198
{
216199
$this->options[$key] = $value;
217200

‎src/Symfony/Component/Routing/Tests/Fixtures/CustomXmlFileLoader.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/Tests/Fixtures/CustomXmlFileLoader.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*/
2020
class CustomXmlFileLoader extends XmlFileLoader
2121
{
22-
protected function loadFile($file)
22+
protected function loadFile(string $file)
2323
{
2424
return XmlUtils::loadFile($file, function () { return true; });
2525
}

‎src/Symfony/Component/Routing/Tests/Loader/FileLocatorStub.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/Tests/Loader/FileLocatorStub.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
class FileLocatorStub implements FileLocatorInterface
88
{
9-
public function locate($name, $currentPath = null, $first = true)
9+
public function locate(string $name, string $currentPath = null, bool $first = true)
1010
{
1111
if (0 === strpos($name, 'http')) {
1212
return $name;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.