Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commitd321a1a

Browse files
committed
[Routing] Add type-hints RequestContext and Route classes.
1 parent1d57b80 commitd321a1a

File tree

6 files changed

+51
-140
lines changed

6 files changed

+51
-140
lines changed

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

Lines changed: 14 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,9 @@ public function getBaseUrl()
7777
/**
7878
* Sets the base URL.
7979
*
80-
* @param string $baseUrl The base URL
81-
*
8280
* @return $this
8381
*/
84-
publicfunctionsetBaseUrl($baseUrl)
82+
publicfunctionsetBaseUrl(string$baseUrl)
8583
{
8684
$this->baseUrl =$baseUrl;
8785

@@ -101,11 +99,9 @@ public function getPathInfo()
10199
/**
102100
* Sets the path info.
103101
*
104-
* @param string $pathInfo The path info
105-
*
106102
* @return $this
107103
*/
108-
publicfunctionsetPathInfo($pathInfo)
104+
publicfunctionsetPathInfo(string$pathInfo)
109105
{
110106
$this->pathInfo =$pathInfo;
111107

@@ -127,11 +123,9 @@ public function getMethod()
127123
/**
128124
* Sets the HTTP method.
129125
*
130-
* @param string $method The HTTP method
131-
*
132126
* @return $this
133127
*/
134-
publicfunctionsetMethod($method)
128+
publicfunctionsetMethod(string$method)
135129
{
136130
$this->method =strtoupper($method);
137131

@@ -153,11 +147,9 @@ public function getHost()
153147
/**
154148
* Sets the HTTP host.
155149
*
156-
* @param string $host The HTTP host
157-
*
158150
* @return $this
159151
*/
160-
publicfunctionsetHost($host)
152+
publicfunctionsetHost(string$host)
161153
{
162154
$this->host =strtolower($host);
163155

@@ -177,11 +169,9 @@ public function getScheme()
177169
/**
178170
* Sets the HTTP scheme.
179171
*
180-
* @param string $scheme The HTTP scheme
181-
*
182172
* @return $this
183173
*/
184-
publicfunctionsetScheme($scheme)
174+
publicfunctionsetScheme(string$scheme)
185175
{
186176
$this->scheme =strtolower($scheme);
187177

@@ -201,13 +191,11 @@ public function getHttpPort()
201191
/**
202192
* Sets the HTTP port.
203193
*
204-
* @param int $httpPort The HTTP port
205-
*
206194
* @return $this
207195
*/
208-
publicfunctionsetHttpPort($httpPort)
196+
publicfunctionsetHttpPort(int$httpPort)
209197
{
210-
$this->httpPort =(int)$httpPort;
198+
$this->httpPort =$httpPort;
211199

212200
return$this;
213201
}
@@ -225,13 +213,11 @@ public function getHttpsPort()
225213
/**
226214
* Sets the HTTPS port.
227215
*
228-
* @param int $httpsPort The HTTPS port
229-
*
230216
* @return $this
231217
*/
232-
publicfunctionsetHttpsPort($httpsPort)
218+
publicfunctionsetHttpsPort(int$httpsPort)
233219
{
234-
$this->httpsPort =(int)$httpsPort;
220+
$this->httpsPort =$httpsPort;
235221

236222
return$this;
237223
}
@@ -249,11 +235,9 @@ public function getQueryString()
249235
/**
250236
* Sets the query string.
251237
*
252-
* @param string $queryString The query string (after "?")
253-
*
254238
* @return $this
255239
*/
256-
publicfunctionsetQueryString($queryString)
240+
publicfunctionsetQueryString(?string$queryString)
257241
{
258242
// string cast to be fault-tolerant, accepting null
259243
$this->queryString = (string)$queryString;
@@ -288,36 +272,31 @@ public function setParameters(array $parameters)
288272
/**
289273
* Gets a parameter value.
290274
*
291-
* @param string $name A parameter name
292-
*
293275
* @return mixed The parameter value or null if nonexistent
294276
*/
295-
publicfunctiongetParameter($name)
277+
publicfunctiongetParameter(string$name)
296278
{
297279
returnisset($this->parameters[$name]) ?$this->parameters[$name] :null;
298280
}
299281

300282
/**
301283
* Checks if a parameter value is set for the given parameter.
302284
*
303-
* @param string $name A parameter name
304-
*
305285
* @return bool True if the parameter value is set, false otherwise
306286
*/
307-
publicfunctionhasParameter($name)
287+
publicfunctionhasParameter(string$name)
308288
{
309289
return\array_key_exists($name,$this->parameters);
310290
}
311291

312292
/**
313293
* Sets a parameter value.
314294
*
315-
* @param string $name A parameter name
316-
* @param mixed $parameter The parameter value
295+
* @param mixed $parameter The parameter value
317296
*
318297
* @return $this
319298
*/
320-
publicfunctionsetParameter($name,$parameter)
299+
publicfunctionsetParameter(string$name,$parameter)
321300
{
322301
$this->parameters[$name] =$parameter;
323302

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

Lines changed: 16 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,9 @@ public function getPath()
126126
*
127127
* This method implements a fluent interface.
128128
*
129-
* @param string $pattern The path pattern
130-
*
131129
* @return $this
132130
*/
133-
publicfunctionsetPath($pattern)
131+
publicfunctionsetPath(string$pattern)
134132
{
135133
if (false !==strpbrk($pattern,'?<')) {
136134
$pattern =preg_replace_callback('#\{(\w++)(<.*?>)?(\?[^\}]*+)?\}#',function ($m) {
@@ -168,11 +166,9 @@ public function getHost()
168166
*
169167
* This method implements a fluent interface.
170168
*
171-
* @param string $pattern The host pattern
172-
*
173169
* @return $this
174170
*/
175-
publicfunctionsetHost($pattern)
171+
publicfunctionsetHost(?string$pattern)
176172
{
177173
$this->host = (string)$pattern;
178174
$this->compiled =null;
@@ -212,11 +208,9 @@ public function setSchemes($schemes)
212208
/**
213209
* Checks if a scheme requirement has been set.
214210
*
215-
* @param string $scheme
216-
*
217211
* @return bool true if the scheme requirement exists, otherwise false
218212
*/
219-
publicfunctionhasScheme($scheme)
213+
publicfunctionhasScheme(string$scheme)
220214
{
221215
return\in_array(strtolower($scheme),$this->schemes,true);
222216
}
@@ -302,12 +296,11 @@ public function addOptions(array $options)
302296
*
303297
* This method implements a fluent interface.
304298
*
305-
* @param string $name An option name
306-
* @param mixed $value The option value
299+
* @param mixed $value The option value
307300
*
308301
* @return $this
309302
*/
310-
publicfunctionsetOption($name,$value)
303+
publicfunctionsetOption(string$name,$value)
311304
{
312305
$this->options[$name] =$value;
313306
$this->compiled =null;
@@ -318,23 +311,19 @@ public function setOption($name, $value)
318311
/**
319312
* Get an option value.
320313
*
321-
* @param string $name An option name
322-
*
323314
* @return mixed The option value or null when not given
324315
*/
325-
publicfunctiongetOption($name)
316+
publicfunctiongetOption(string$name)
326317
{
327318
returnisset($this->options[$name]) ?$this->options[$name] :null;
328319
}
329320

330321
/**
331322
* Checks if an option has been set.
332323
*
333-
* @param string $name An option name
334-
*
335324
* @return bool true if the option is set, false otherwise
336325
*/
337-
publicfunctionhasOption($name)
326+
publicfunctionhasOption(string$name)
338327
{
339328
return\array_key_exists($name,$this->options);
340329
}
@@ -387,36 +376,31 @@ public function addDefaults(array $defaults)
387376
/**
388377
* Gets a default value.
389378
*
390-
* @param string $name A variable name
391-
*
392379
* @return mixed The default value or null when not given
393380
*/
394-
publicfunctiongetDefault($name)
381+
publicfunctiongetDefault(string$name)
395382
{
396383
returnisset($this->defaults[$name]) ?$this->defaults[$name] :null;
397384
}
398385

399386
/**
400387
* Checks if a default value is set for the given variable.
401388
*
402-
* @param string $name A variable name
403-
*
404389
* @return bool true if the default value is set, false otherwise
405390
*/
406-
publicfunctionhasDefault($name)
391+
publicfunctionhasDefault(string$name)
407392
{
408393
return\array_key_exists($name,$this->defaults);
409394
}
410395

411396
/**
412397
* Sets a default value.
413398
*
414-
* @param string $name A variable name
415-
* @param mixed $default The default value
399+
* @param mixed $default The default value
416400
*
417401
* @return $this
418402
*/
419-
publicfunctionsetDefault($name,$default)
403+
publicfunctionsetDefault(string$name,$default)
420404
{
421405
$this->defaults[$name] =$default;
422406
$this->compiled =null;
@@ -472,36 +456,29 @@ public function addRequirements(array $requirements)
472456
/**
473457
* Returns the requirement for the given key.
474458
*
475-
* @param string $key The key
476-
*
477459
* @return string|null The regex or null when not given
478460
*/
479-
publicfunctiongetRequirement($key)
461+
publicfunctiongetRequirement(string$key)
480462
{
481463
returnisset($this->requirements[$key]) ?$this->requirements[$key] :null;
482464
}
483465

484466
/**
485467
* Checks if a requirement is set for the given key.
486468
*
487-
* @param string $key A variable name
488-
*
489469
* @return bool true if a requirement is specified, false otherwise
490470
*/
491-
publicfunctionhasRequirement($key)
471+
publicfunctionhasRequirement(string$key)
492472
{
493473
return\array_key_exists($key,$this->requirements);
494474
}
495475

496476
/**
497477
* Sets a requirement for the given key.
498478
*
499-
* @param string $key The key
500-
* @param string $regex The regex
501-
*
502479
* @return $this
503480
*/
504-
publicfunctionsetRequirement($key,$regex)
481+
publicfunctionsetRequirement(string$key,string$regex)
505482
{
506483
$this->requirements[$key] =$this->sanitizeRequirement($key,$regex);
507484
$this->compiled =null;
@@ -524,11 +501,9 @@ public function getCondition()
524501
*
525502
* This method implements a fluent interface.
526503
*
527-
* @param string $condition The condition
528-
*
529504
* @return $this
530505
*/
531-
publicfunctionsetCondition($condition)
506+
publicfunctionsetCondition(?string$condition)
532507
{
533508
$this->condition = (string)$condition;
534509
$this->compiled =null;
@@ -557,12 +532,8 @@ public function compile()
557532
return$this->compiled =$class::compile($this);
558533
}
559534

560-
privatefunctionsanitizeRequirement($key,$regex)
535+
privatefunctionsanitizeRequirement(string$key,string$regex)
561536
{
562-
if (!\is_string($regex)) {
563-
thrownew \InvalidArgumentException(sprintf('Routing requirement for "%s" must be a string.',$key));
564-
}
565-
566537
if ('' !==$regex &&'^' ===$regex[0]) {
567538
$regex = (string)substr($regex,1);// returns false for a single character
568539
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp