Skip to content

Commit c142b26

Browse files
Merge branch '5.3' into 5.4
* 5.3: Leverage str_contains/str_starts_with Leverage str_ends_with
2 parents 361aa90 + 9d983fd commit c142b26

File tree

10 files changed

+14
-14
lines changed

10 files changed

+14
-14
lines changed

Generator/UrlGenerator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,9 @@ protected function doGenerate(array $variables, array $defaults, array $requirem
222222
// so we need to encode them as they are not used for this purpose here
223223
// otherwise we would generate a URI that, when followed by a user agent (e.g. browser), does not match this route
224224
$url = strtr($url, ['/../' => '/%2E%2E/', '/./' => '/%2E/']);
225-
if ('/..' === substr($url, -3)) {
225+
if (str_ends_with($url, '/..')) {
226226
$url = substr($url, 0, -2).'%2E%2E';
227-
} elseif ('/.' === substr($url, -2)) {
227+
} elseif (str_ends_with($url, '/.')) {
228228
$url = substr($url, 0, -1).'%2E';
229229
}
230230

Loader/AnnotationDirectoryLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ function (\SplFileInfo $current) {
5454
});
5555

5656
foreach ($files as $file) {
57-
if (!$file->isFile() || '.php' !== substr($file->getFilename(), -4)) {
57+
if (!$file->isFile() || !str_ends_with($file->getFilename(), '.php')) {
5858
continue;
5959
}
6060

Matcher/Dumper/CompiledUrlMatcherDumper.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ private function groupStaticRoutes(RouteCollection $collection): array
187187
$url = substr($url, 0, -1);
188188
}
189189
foreach ($dynamicRegex as [$hostRx, $rx, $prefix]) {
190-
if (('' === $prefix || 0 === strpos($url, $prefix)) && (preg_match($rx, $url) || preg_match($rx, $url.'/')) && (!$host || !$hostRx || preg_match($hostRx, $host))) {
190+
if (('' === $prefix || str_starts_with($url, $prefix)) && (preg_match($rx, $url) || preg_match($rx, $url.'/')) && (!$host || !$hostRx || preg_match($hostRx, $host))) {
191191
$dynamicRegex[] = [$hostRegex, $regex, $staticPrefix];
192192
$dynamicRoutes->add($name, $route);
193193
continue 2;
@@ -349,7 +349,7 @@ private function compileDynamicRoutes(RouteCollection $collection, bool $matchHo
349349
$state->markTail = 0;
350350

351351
// if the regex is too large, throw a signaling exception to recompute with smaller chunk size
352-
set_error_handler(function ($type, $message) { throw false !== strpos($message, $this->signalingException->getMessage()) ? $this->signalingException : new \ErrorException($message); });
352+
set_error_handler(function ($type, $message) { throw str_contains($message, $this->signalingException->getMessage()) ? $this->signalingException : new \ErrorException($message); });
353353
try {
354354
preg_match($state->regex, '');
355355
} finally {
@@ -427,7 +427,7 @@ private function compileRoute(Route $route, string $name, $vars, bool $hasTraili
427427

428428
if ($condition = $route->getCondition()) {
429429
$condition = $this->getExpressionLanguage()->compile($condition, ['context', 'request']);
430-
$condition = $conditions[$condition] ?? $conditions[$condition] = (false !== strpos($condition, '$request') ? 1 : -1) * \count($conditions);
430+
$condition = $conditions[$condition] ?? $conditions[$condition] = (str_contains($condition, '$request') ? 1 : -1) * \count($conditions);
431431
} else {
432432
$condition = null;
433433
}

Matcher/Dumper/StaticPrefixCollection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,6 @@ private function getCommonPrefix(string $prefix, string $anotherPrefix): array
197197

198198
public static function handleError(int $type, string $msg)
199199
{
200-
return false !== strpos($msg, 'Compilation failed: lookbehind assertion is not fixed length');
200+
return str_contains($msg, 'Compilation failed: lookbehind assertion is not fixed length');
201201
}
202202
}

Matcher/TraceableUrlMatcher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ protected function matchCollection(string $pathinfo, RouteCollection $routes)
6565
$requiredMethods = $route->getMethods();
6666

6767
// check the static prefix of the URL first. Only use the more expensive preg_match when it matches
68-
if ('' !== $staticPrefix && 0 !== strpos($trimmedPathinfo, $staticPrefix)) {
68+
if ('' !== $staticPrefix && !str_starts_with($trimmedPathinfo, $staticPrefix)) {
6969
$this->addTrace(sprintf('Path "%s" does not match', $route->getPath()), self::ROUTE_DOES_NOT_MATCH, $name, $route);
7070
continue;
7171
}

Matcher/UrlMatcher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ protected function matchCollection(string $pathinfo, RouteCollection $routes)
141141
$requiredMethods = $route->getMethods();
142142

143143
// check the static prefix of the URL first. Only use the more expensive preg_match when it matches
144-
if ('' !== $staticPrefix && 0 !== strpos($trimmedPathinfo, $staticPrefix)) {
144+
if ('' !== $staticPrefix && !str_starts_with($trimmedPathinfo, $staticPrefix)) {
145145
continue;
146146
}
147147
$regex = $compiledRoute->getRegex();

Route.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ private function sanitizeRequirement(string $key, string $regex)
485485
}
486486
}
487487

488-
if ('$' === substr($regex, -1)) {
488+
if (str_ends_with($regex, '$')) {
489489
$regex = substr($regex, 0, -1);
490490
} elseif (\strlen($regex) - 2 === strpos($regex, '\\z')) {
491491
$regex = substr($regex, 0, -2);

RouteCompiler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ private static function compilePattern(Route $route, string $pattern, bool $isHo
138138
} else {
139139
$precedingChar = substr($precedingText, -1);
140140
}
141-
$isSeparator = '' !== $precedingChar && false !== strpos(static::SEPARATORS, $precedingChar);
141+
$isSeparator = '' !== $precedingChar && str_contains(static::SEPARATORS, $precedingChar);
142142

143143
// A PCRE subpattern name must start with a non-digit. Also a PHP variable cannot start with a digit so the
144144
// variable would not be usable as a Controller action argument.
@@ -283,7 +283,7 @@ private static function findNextSeparator(string $pattern, bool $useUtf8): strin
283283
preg_match('/^./u', $pattern, $pattern);
284284
}
285285

286-
return false !== strpos(static::SEPARATORS, $pattern[0]) ? $pattern[0] : '';
286+
return str_contains(static::SEPARATORS, $pattern[0]) ? $pattern[0] : '';
287287
}
288288

289289
/**

Tests/Loader/FileLocatorStub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class FileLocatorStub implements FileLocatorInterface
88
{
99
public function locate(string $name, string $currentPath = null, bool $first = true)
1010
{
11-
if (0 === strpos($name, 'http')) {
11+
if (str_starts_with($name, 'http')) {
1212
return $name;
1313
}
1414

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"require": {
1919
"php": ">=7.2.5",
2020
"symfony/deprecation-contracts": "^2.1",
21-
"symfony/polyfill-php80": "^1.15"
21+
"symfony/polyfill-php80": "^1.16"
2222
},
2323
"require-dev": {
2424
"symfony/config": "^5.3|^6.0",

0 commit comments

Comments
 (0)