@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | // Toujours là ? Ensuite, nous pouvons essayer de faire correspondre l'URI avec |
| 176 | 176 | // Contrôleurs/répertoires, mais l'application peut ne pas |
| 177 | 177 | // vouloir ceci, comme dans le cas des API. |
| 178 | - if (! $this->collection->shouldAutoRoute()) { |
|
| 178 | + if (!$this->collection->shouldAutoRoute()) { |
|
| 179 | 179 | throw new PageNotFoundException("Impossible de trouver une route pour '{$this->collection->getHTTPVerb()}: {$uri}'."); |
| 180 | 180 | } |
| 181 | 181 | |
@@ -205,7 +205,7 @@ discard block |
||
| 205 | 205 | */ |
| 206 | 206 | public function controllerName() |
| 207 | 207 | { |
| 208 | - if (! is_string($this->controller)) { |
|
| 208 | + if (!is_string($this->controller)) { |
|
| 209 | 209 | return $this->controller; |
| 210 | 210 | } |
| 211 | 211 | |
@@ -250,7 +250,7 @@ discard block |
||
| 250 | 250 | |
| 251 | 251 | return [ |
| 252 | 252 | $routeArray[0], // Controller |
| 253 | - $routeArray[1] ?? 'index', // Method |
|
| 253 | + $routeArray[1] ?? 'index', // Method |
|
| 254 | 254 | ]; |
| 255 | 255 | } |
| 256 | 256 | |
@@ -374,7 +374,7 @@ discard block |
||
| 374 | 374 | // Cette route est-elle censée rediriger vers une autre ? |
| 375 | 375 | if ($this->collection->isRedirect($routeKey)) { |
| 376 | 376 | // remplacement des groupes de routes correspondants par des références : post/([0-9]+) -> post/$1 |
| 377 | - $redirectTo = preg_replace_callback('/(\([^\(]+\))/', static function () { |
|
| 377 | + $redirectTo = preg_replace_callback('/(\([^\(]+\))/', static function() { |
|
| 378 | 378 | static $i = 1; |
| 379 | 379 | |
| 380 | 380 | return '$' . $i++; |
@@ -394,7 +394,7 @@ discard block |
||
| 394 | 394 | ); |
| 395 | 395 | |
| 396 | 396 | if ($this->collection->shouldUseSupportedLocalesOnly() |
| 397 | - && ! in_array($matched['locale'], config('app.supported_locales'), true)) { |
|
| 397 | + && !in_array($matched['locale'], config('app.supported_locales'), true)) { |
|
| 398 | 398 | // Lancer une exception pour empêcher l'autorouteur, |
| 399 | 399 | // si activé, essayer de trouver une route |
| 400 | 400 | throw PageNotFoundException::localeNotSupported($matched['locale']); |
@@ -406,7 +406,7 @@ discard block |
||
| 406 | 406 | |
| 407 | 407 | // Utilisons-nous Closures ? Si tel est le cas, nous devons collecter les paramètres dans un tableau |
| 408 | 408 | // afin qu'ils puissent être transmis ultérieurement à la méthode du contrôleur. |
| 409 | - if (! is_string($handler) && is_callable($handler)) { |
|
| 409 | + if (!is_string($handler) && is_callable($handler)) { |
|
| 410 | 410 | $this->controller = $handler; |
| 411 | 411 | |
| 412 | 412 | // Supprime la chaîne d'origine du tableau matches |
@@ -483,7 +483,7 @@ discard block |
||
| 483 | 483 | |
| 484 | 484 | return preg_replace_callback( |
| 485 | 485 | $pattern, |
| 486 | - static function ($match) use ($matches) { |
|
| 486 | + static function($match) use ($matches) { |
|
| 487 | 487 | $index = (int) $match[1]; |
| 488 | 488 | |
| 489 | 489 | return $matches[$index] ?? ''; |
@@ -523,7 +523,7 @@ discard block |
||
| 523 | 523 | |
| 524 | 524 | // $this->method contient déjà le nom de la méthode par défaut, |
| 525 | 525 | // donc ne l'écrasez pas avec le vide. |
| 526 | - if (! empty($method)) { |
|
| 526 | + if (!empty($method)) { |
|
| 527 | 527 | $this->setMethod($method); |
| 528 | 528 | } |
| 529 | 529 | |
@@ -258,7 +258,7 @@ discard block |
||
| 258 | 258 | // Incluez le fichier routesFile s'il n'existe pas. |
| 259 | 259 | // Ne conserver que pour les fins BC pour l'instant. |
| 260 | 260 | $routeFiles = $this->routeFiles; |
| 261 | - if (! in_array($routesFile, $routeFiles, true)) { |
|
| 261 | + if (!in_array($routesFile, $routeFiles, true)) { |
|
| 262 | 262 | $routeFiles[] = $routesFile; |
| 263 | 263 | } |
| 264 | 264 | |
@@ -266,7 +266,7 @@ discard block |
||
| 266 | 266 | $routes = $this; |
| 267 | 267 | |
| 268 | 268 | foreach ($routeFiles as $routesFile) { |
| 269 | - if (! is_file($routesFile)) { |
|
| 269 | + if (!is_file($routesFile)) { |
|
| 270 | 270 | logger()->warning(sprintf('Fichier de route introuvable : "%s"', $routesFile)); |
| 271 | 271 | |
| 272 | 272 | continue; |
@@ -315,7 +315,7 @@ discard block |
||
| 315 | 315 | */ |
| 316 | 316 | public function placeholder(array|string $placeholder, ?string $pattern = null): self |
| 317 | 317 | { |
| 318 | - if (! is_array($placeholder)) { |
|
| 318 | + if (!is_array($placeholder)) { |
|
| 319 | 319 | $placeholder = [$placeholder => $pattern]; |
| 320 | 320 | } |
| 321 | 321 | |
@@ -1031,7 +1031,7 @@ discard block |
||
| 1031 | 1031 | * |
| 1032 | 1032 | * @param array|(Closure(mixed...): (ResponseInterface|string|void))|string $to |
| 1033 | 1033 | */ |
| 1034 | - public function match(array $verbs = [], string $from = '', $to = '', ?array $options = null): self |
|
| 1034 | + public function match(array $verbs = [], string $from = '', $to = '', ?array $options = null) : self |
|
| 1035 | 1035 | { |
| 1036 | 1036 | if (empty($from) || empty($to)) { |
| 1037 | 1037 | throw new InvalidArgumentException('Vous devez fournir les paramètres : $from, $to.'); |
@@ -1222,7 +1222,7 @@ discard block |
||
| 1222 | 1222 | $from = $route['from']; |
| 1223 | 1223 | |
| 1224 | 1224 | // on ignore les closures |
| 1225 | - if (! is_string($to)) { |
|
| 1225 | + if (!is_string($to)) { |
|
| 1226 | 1226 | continue; |
| 1227 | 1227 | } |
| 1228 | 1228 | |
@@ -1233,7 +1233,7 @@ discard block |
||
| 1233 | 1233 | |
| 1234 | 1234 | // S'il y a une chance de correspondance, alors ce sera |
| 1235 | 1235 | // soit avec $search au début de la chaîne $to. |
| 1236 | - if (! str_starts_with($to, $search)) { |
|
| 1236 | + if (!str_starts_with($to, $search)) { |
|
| 1237 | 1237 | continue; |
| 1238 | 1238 | } |
| 1239 | 1239 | |
@@ -1309,7 +1309,7 @@ discard block |
||
| 1309 | 1309 | |
| 1310 | 1310 | // Construisez notre chaîne résultante, en insérant les $params aux endroits appropriés. |
| 1311 | 1311 | foreach ($matches[0] as $index => $placeholder) { |
| 1312 | - if (! isset($params[$index])) { |
|
| 1312 | + if (!isset($params[$index])) { |
|
| 1313 | 1313 | throw new InvalidArgumentException( |
| 1314 | 1314 | 'Argument manquant pour "' . $placeholder . '" dans la route "' . $from . '".' |
| 1315 | 1315 | ); |
@@ -1320,7 +1320,7 @@ discard block |
||
| 1320 | 1320 | // ou peut-être que $placeholder n'est pas un espace réservé, mais une regex. |
| 1321 | 1321 | $pattern = $this->placeholders[$placeholderName] ?? $placeholder; |
| 1322 | 1322 | |
| 1323 | - if (! preg_match('#^' . $pattern . '$#u', (string) $params[$index])) { |
|
| 1323 | + if (!preg_match('#^' . $pattern . '$#u', (string) $params[$index])) { |
|
| 1324 | 1324 | throw RouterException::invalidParameterType(); |
| 1325 | 1325 | } |
| 1326 | 1326 | |
@@ -1377,7 +1377,7 @@ discard block |
||
| 1377 | 1377 | $from = trim($from, '/'); |
| 1378 | 1378 | } |
| 1379 | 1379 | |
| 1380 | - if (is_string($to) && ! str_contains($to, '::') && class_exists($to) && method_exists($to, '__invoke')) { |
|
| 1380 | + if (is_string($to) && !str_contains($to, '::') && class_exists($to) && method_exists($to, '__invoke')) { |
|
| 1381 | 1381 | $to = [$to, '__invoke']; |
| 1382 | 1382 | } |
| 1383 | 1383 | |
@@ -1389,7 +1389,7 @@ discard block |
||
| 1389 | 1389 | $options = array_merge($this->currentOptions ?? [], $options ?? []); |
| 1390 | 1390 | |
| 1391 | 1391 | if (isset($options['middleware'])) { |
| 1392 | - if (! isset($options['middlewares'])) { |
|
| 1392 | + if (!isset($options['middlewares'])) { |
|
| 1393 | 1393 | $options['middlewares'] = (array) $options['middleware']; |
| 1394 | 1394 | } |
| 1395 | 1395 | unset($options['middleware']); |
@@ -1410,9 +1410,9 @@ discard block |
||
| 1410 | 1410 | } |
| 1411 | 1411 | |
| 1412 | 1412 | // Limitation du nom d'hôte ? |
| 1413 | - if (! empty($options['hostname'])) { |
|
| 1413 | + if (!empty($options['hostname'])) { |
|
| 1414 | 1414 | // @todo déterminer s'il existe un moyen de mettre les hôtes sur liste blanche ? |
| 1415 | - if (! $this->checkHostname($options['hostname'])) { |
|
| 1415 | + if (!$this->checkHostname($options['hostname'])) { |
|
| 1416 | 1416 | return; |
| 1417 | 1417 | } |
| 1418 | 1418 | |
@@ -1420,10 +1420,10 @@ discard block |
||
| 1420 | 1420 | } |
| 1421 | 1421 | |
| 1422 | 1422 | // Limitation du nom sous-domaine ? |
| 1423 | - elseif (! empty($options['subdomain'])) { |
|
| 1423 | + elseif (!empty($options['subdomain'])) { |
|
| 1424 | 1424 | // Si nous ne correspondons pas au sous-domaine actuel, alors |
| 1425 | 1425 | // nous n'avons pas besoin d'ajouter la route. |
| 1426 | - if (! $this->checkSubdomains($options['subdomain'])) { |
|
| 1426 | + if (!$this->checkSubdomains($options['subdomain'])) { |
|
| 1427 | 1427 | return; |
| 1428 | 1428 | } |
| 1429 | 1429 | |
@@ -1456,9 +1456,9 @@ discard block |
||
| 1456 | 1456 | } |
| 1457 | 1457 | |
| 1458 | 1458 | // S'il s'agit d'une redirection, aucun traitement |
| 1459 | - if (! isset($options['redirect']) && is_string($to)) { |
|
| 1459 | + if (!isset($options['redirect']) && is_string($to)) { |
|
| 1460 | 1460 | // Si aucun espace de noms n'est trouvé, ajouter l'espace de noms par défaut |
| 1461 | - if (! str_contains($to, '\\') || strpos($to, '\\') > 0) { |
|
| 1461 | + if (!str_contains($to, '\\') || strpos($to, '\\') > 0) { |
|
| 1462 | 1462 | $namespace = $options['namespace'] ?? $this->defaultNamespace; |
| 1463 | 1463 | $to = trim($namespace, '\\') . '\\' . $to; |
| 1464 | 1464 | } |
@@ -1475,7 +1475,7 @@ discard block |
||
| 1475 | 1475 | // cela ne fonctionne que parce que les routes découvertes sont ajoutées juste avant |
| 1476 | 1476 | // pour tenter de router la requête. |
| 1477 | 1477 | $routeKeyExists = isset($this->routes[$verb][$routeKey]); |
| 1478 | - if ((isset($this->routesNames[$verb][$name]) || $routeKeyExists) && ! $overwrite) { |
|
| 1478 | + if ((isset($this->routesNames[$verb][$name]) || $routeKeyExists) && !$overwrite) { |
|
| 1479 | 1479 | return; |
| 1480 | 1480 | } |
| 1481 | 1481 | |
@@ -1501,7 +1501,7 @@ discard block |
||
| 1501 | 1501 | private function checkHostname(string $hostname): bool |
| 1502 | 1502 | { |
| 1503 | 1503 | // Les appels CLI ne peuvent pas être sur le nom d'hôte. |
| 1504 | - if (! isset($this->httpHost)) { |
|
| 1504 | + if (!isset($this->httpHost)) { |
|
| 1505 | 1505 | return false; |
| 1506 | 1506 | } |
| 1507 | 1507 | |
@@ -1517,7 +1517,7 @@ discard block |
||
| 1517 | 1517 | private function checkSubdomains($subdomains): bool |
| 1518 | 1518 | { |
| 1519 | 1519 | // Les appels CLI ne peuvent pas être sur le sous-domaine. |
| 1520 | - if (! isset($this->httpHost)) { |
|
| 1520 | + if (!isset($this->httpHost)) { |
|
| 1521 | 1521 | return false; |
| 1522 | 1522 | } |
| 1523 | 1523 | |
@@ -1525,13 +1525,13 @@ discard block |
||
| 1525 | 1525 | $this->currentSubdomain = $this->determineCurrentSubdomain(); |
| 1526 | 1526 | } |
| 1527 | 1527 | |
| 1528 | - if (! is_array($subdomains)) { |
|
| 1528 | + if (!is_array($subdomains)) { |
|
| 1529 | 1529 | $subdomains = [$subdomains]; |
| 1530 | 1530 | } |
| 1531 | 1531 | |
| 1532 | 1532 | // Les routes peuvent être limitées à n'importe quel sous-domaine. Dans ce cas, cependant, |
| 1533 | 1533 | // il nécessite la présence d'un sous-domaine. |
| 1534 | - if (! empty($this->currentSubdomain) && in_array('*', $subdomains, true)) { |
|
| 1534 | + if (!empty($this->currentSubdomain) && in_array('*', $subdomains, true)) { |
|
| 1535 | 1535 | return true; |
| 1536 | 1536 | } |
| 1537 | 1537 | |
@@ -1553,7 +1553,7 @@ discard block |
||
| 1553 | 1553 | // sur l'URL sinon parse_url sera mal interprété |
| 1554 | 1554 | // 'hôte' comme 'chemin'. |
| 1555 | 1555 | $url = $this->httpHost; |
| 1556 | - if (! str_starts_with($url, 'http')) { |
|
| 1556 | + if (!str_starts_with($url, 'http')) { |
|
| 1557 | 1557 | $url = 'http://' . $url; |
| 1558 | 1558 | } |
| 1559 | 1559 | |
@@ -1597,7 +1597,7 @@ discard block |
||
| 1597 | 1597 | */ |
| 1598 | 1598 | private function getControllerName(Closure|string $handler): ?string |
| 1599 | 1599 | { |
| 1600 | - if (! is_string($handler)) { |
|
| 1600 | + if (!is_string($handler)) { |
|
| 1601 | 1601 | return null; |
| 1602 | 1602 | } |
| 1603 | 1603 | |
@@ -1656,13 +1656,13 @@ discard block |
||
| 1656 | 1656 | */ |
| 1657 | 1657 | private function replaceLocale(string $route, ?string $locale = null): string |
| 1658 | 1658 | { |
| 1659 | - if (! str_contains($route, '{locale}')) { |
|
| 1659 | + if (!str_contains($route, '{locale}')) { |
|
| 1660 | 1660 | return $route; |
| 1661 | 1661 | } |
| 1662 | 1662 | |
| 1663 | 1663 | // Vérifier les paramètres régionaux non valides |
| 1664 | 1664 | if ($locale !== null) { |
| 1665 | - if (! in_array($locale, config('app.supported_locales'), true)) { |
|
| 1665 | + if (!in_array($locale, config('app.supported_locales'), true)) { |
|
| 1666 | 1666 | $locale = null; |
| 1667 | 1667 | } |
| 1668 | 1668 | } |