@@ -57,11 +57,11 @@ discard block |
||
| 57 | 57 | $group = on_test() ? 'test' : (on_prod() ? 'production' : 'development'); |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | - if (! isset($config[$group]) && strpos($group, 'custom-') === false) { |
|
| 60 | + if (!isset($config[$group]) && strpos($group, 'custom-') === false) { |
|
| 61 | 61 | $group = 'default'; |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - if (is_string($group) && ! isset($config[$group]) && strpos($group, 'custom-') !== 0) { |
|
| 64 | + if (is_string($group) && !isset($config[$group]) && strpos($group, 'custom-') !== 0) { |
|
| 65 | 65 | throw new InvalidArgumentException($group . ' is not a valid database connection group.'); |
| 66 | 66 | } |
| 67 | 67 | |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | |
| 72 | 72 | $config = $config[$group]; |
| 73 | 73 | |
| 74 | - if (str_contains($config['driver'], 'sqlite') && $config['database'] !== ':memory:' && ! str_contains($config['database'], DS)) { |
|
| 74 | + if (str_contains($config['driver'], 'sqlite') && $config['database'] !== ':memory:' && !str_contains($config['database'], DS)) { |
|
| 75 | 75 | $config['database'] = APP_STORAGE_PATH . $config['database']; |
| 76 | 76 | } |
| 77 | 77 | |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | |
| 94 | 94 | // Si le package "blitz-php/database" n'existe pas on renvoi une fake connection |
| 95 | 95 | // Ceci est utile juste pour eviter le bug avec le service provider |
| 96 | - if (! class_exists(Db::class)) { |
|
| 96 | + if (!class_exists(Db::class)) { |
|
| 97 | 97 | return static::createMockConnection(); |
| 98 | 98 | } |
| 99 | 99 | |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | { |
| 53 | 53 | $debugger = new Run(); |
| 54 | 54 | |
| 55 | - if (! is_online()) { |
|
| 55 | + if (!is_online()) { |
|
| 56 | 56 | if (Misc::isCommandLine()) { |
| 57 | 57 | $debugger->pushHandler(new PlainTextHandler()); |
| 58 | 58 | } elseif (Misc::isAjaxRequest()) { |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | /** |
| 66 | 66 | * On log toutes les erreurs |
| 67 | 67 | */ |
| 68 | - $debugger->pushHandler(static function (Throwable $exception, Inspector $inspector, RunInterface $run) { |
|
| 68 | + $debugger->pushHandler(static function(Throwable $exception, Inspector $inspector, RunInterface $run) { |
|
| 69 | 69 | Services::logger()->error($exception); |
| 70 | 70 | |
| 71 | 71 | return Handler::DONE; |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | $debugger = Ignition::make(); |
| 85 | 85 | |
| 86 | 86 | $debugger->applicationPath(ROOTPATH) |
| 87 | - ->shouldDisplayException(! on_prod()) |
|
| 87 | + ->shouldDisplayException(!on_prod()) |
|
| 88 | 88 | ->register(); |
| 89 | 89 | } |
| 90 | 90 | } |
@@ -20,10 +20,10 @@ discard block |
||
| 20 | 20 | { |
| 21 | 21 | private RouteCollection $routeCollection; |
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * Routes deja collectees (pour eviter de faire la meme chose plusieurs fois) |
|
| 25 | - */ |
|
| 26 | - private array $cachedRoutes = []; |
|
| 23 | + /** |
|
| 24 | + * Routes deja collectees (pour eviter de faire la meme chose plusieurs fois) |
|
| 25 | + */ |
|
| 26 | + private array $cachedRoutes = []; |
|
| 27 | 27 | |
| 28 | 28 | public function __construct(RouteCollection $routes) |
| 29 | 29 | { |
@@ -35,9 +35,9 @@ discard block |
||
| 35 | 35 | */ |
| 36 | 36 | public function collect(bool $reset = true): array |
| 37 | 37 | { |
| 38 | - if (! $reset && $this->cachedRoutes !== []) { |
|
| 39 | - return $this->cachedRoutes; |
|
| 40 | - } |
|
| 38 | + if (! $reset && $this->cachedRoutes !== []) { |
|
| 39 | + return $this->cachedRoutes; |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | 42 | $methods = [ |
| 43 | 43 | 'get', |
@@ -52,12 +52,12 @@ discard block |
||
| 52 | 52 | 'cli', |
| 53 | 53 | ]; |
| 54 | 54 | |
| 55 | - $definedRoutes = []; |
|
| 55 | + $definedRoutes = []; |
|
| 56 | 56 | |
| 57 | 57 | foreach ($methods as $method) { |
| 58 | 58 | $routes = $this->routeCollection->getRoutes($method); |
| 59 | 59 | |
| 60 | - foreach ($routes as $route => $handler) { |
|
| 60 | + foreach ($routes as $route => $handler) { |
|
| 61 | 61 | if (is_string($handler) || $handler instanceof Closure) { |
| 62 | 62 | if ($handler instanceof Closure) { |
| 63 | 63 | $view = $this->routeCollection->getRoutesOptions($route, $method)['view'] ?? false; |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | |
| 68 | 68 | $routeName = $this->routeCollection->getRoutesOptions($route, $method)['as'] ?? $route; |
| 69 | 69 | |
| 70 | - $definedRoutes[] = [ |
|
| 70 | + $definedRoutes[] = [ |
|
| 71 | 71 | 'method' => $method, |
| 72 | 72 | 'route' => $route, |
| 73 | 73 | 'name' => $routeName, |
@@ -77,6 +77,6 @@ discard block |
||
| 77 | 77 | } |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | - return $this->cachedRoutes = $definedRoutes; |
|
| 80 | + return $this->cachedRoutes = $definedRoutes; |
|
| 81 | 81 | } |
| 82 | 82 | } |
@@ -35,7 +35,7 @@ |
||
| 35 | 35 | */ |
| 36 | 36 | public function collect(bool $reset = true): array |
| 37 | 37 | { |
| 38 | - if (! $reset && $this->cachedRoutes !== []) { |
|
| 38 | + if (!$reset && $this->cachedRoutes !== []) { |
|
| 39 | 39 | return $this->cachedRoutes; |
| 40 | 40 | } |
| 41 | 41 | |
@@ -257,7 +257,7 @@ discard block |
||
| 257 | 257 | // Incluez le fichier routesFile s'il n'existe pas. |
| 258 | 258 | // Ne conserver que pour les fins BC pour l'instant. |
| 259 | 259 | $routeFiles = $this->routeFiles; |
| 260 | - if (! in_array($routesFile, $routeFiles, true)) { |
|
| 260 | + if (!in_array($routesFile, $routeFiles, true)) { |
|
| 261 | 261 | $routeFiles[] = $routesFile; |
| 262 | 262 | } |
| 263 | 263 | |
@@ -265,7 +265,7 @@ discard block |
||
| 265 | 265 | $routes = $this; |
| 266 | 266 | |
| 267 | 267 | foreach ($routeFiles as $routesFile) { |
| 268 | - if (! is_file($routesFile)) { |
|
| 268 | + if (!is_file($routesFile)) { |
|
| 269 | 269 | logger()->warning(sprintf('Fichier de route introuvable : "%s"', $routesFile)); |
| 270 | 270 | |
| 271 | 271 | continue; |
@@ -303,7 +303,7 @@ discard block |
||
| 303 | 303 | */ |
| 304 | 304 | public function addPlaceholder($placeholder, ?string $pattern = null): self |
| 305 | 305 | { |
| 306 | - if (! is_array($placeholder)) { |
|
| 306 | + if (!is_array($placeholder)) { |
|
| 307 | 307 | $placeholder = [$placeholder => $pattern]; |
| 308 | 308 | } |
| 309 | 309 | |
@@ -394,7 +394,7 @@ discard block |
||
| 394 | 394 | // Nous avons besoin de cette variable dans la portée locale pour que les fichiers de route puissent y accéder. |
| 395 | 395 | $routes = $this; |
| 396 | 396 | |
| 397 | - $files = $this->locator->search('Config/routes.php'); |
|
| 397 | + $files = $this->locator->search('Config/routes.php'); |
|
| 398 | 398 | |
| 399 | 399 | foreach ($files as $file) { |
| 400 | 400 | // N'incluez plus notre fichier principal... |
@@ -538,7 +538,7 @@ discard block |
||
| 538 | 538 | // que nous pourrions avoir besoin de faire. |
| 539 | 539 | $this->discoverRoutes(); |
| 540 | 540 | |
| 541 | - $routes = []; |
|
| 541 | + $routes = []; |
|
| 542 | 542 | if (isset($this->routes[$verb])) { |
| 543 | 543 | // Conserve les itinéraires du verbe actuel au début afin qu'ils soient |
| 544 | 544 | // mis en correspondance avant l'un des itinéraires génériques "add". |
@@ -631,7 +631,7 @@ discard block |
||
| 631 | 631 | { |
| 632 | 632 | // Utilisez le modèle de la route nommée s'il s'agit d'une route nommée. |
| 633 | 633 | if (array_key_exists($to, $this->routesNames['*'])) { |
| 634 | - $routeName = $to; |
|
| 634 | + $routeName = $to; |
|
| 635 | 635 | $routeKey = $this->routesNames['*'][$routeName]; |
| 636 | 636 | $redirectTo = [$routeKey => $this->routes['*'][$routeKey]['handler']]; |
| 637 | 637 | |
@@ -966,7 +966,7 @@ discard block |
||
| 966 | 966 | * |
| 967 | 967 | * @param array|Closure|string $to |
| 968 | 968 | */ |
| 969 | - public function match(array $verbs = [], string $from = '', $to = '', ?array $options = null): self |
|
| 969 | + public function match(array $verbs = [], string $from = '', $to = '', ?array $options = null) : self |
|
| 970 | 970 | { |
| 971 | 971 | if (empty($from) || empty($to)) { |
| 972 | 972 | throw new InvalidArgumentException('Vous devez fournir les paramètres : $from, $to.'); |
@@ -1150,7 +1150,7 @@ discard block |
||
| 1150 | 1150 | $to = $route['handler']; |
| 1151 | 1151 | |
| 1152 | 1152 | // on ignore les closures |
| 1153 | - if (! is_string($to)) { |
|
| 1153 | + if (!is_string($to)) { |
|
| 1154 | 1154 | continue; |
| 1155 | 1155 | } |
| 1156 | 1156 | |
@@ -1239,12 +1239,12 @@ discard block |
||
| 1239 | 1239 | |
| 1240 | 1240 | // Construisez notre chaîne résultante, en insérant les $params aux endroits appropriés. |
| 1241 | 1241 | foreach ($matches[0] as $index => $pattern) { |
| 1242 | - if (! isset($params[$index])) { |
|
| 1242 | + if (!isset($params[$index])) { |
|
| 1243 | 1243 | throw new InvalidArgumentException( |
| 1244 | 1244 | 'Argument manquant pour "' . $pattern . '" dans la route "' . $routeKey . '".' |
| 1245 | 1245 | ); |
| 1246 | 1246 | } |
| 1247 | - if (! preg_match('#^' . $pattern . '$#u', $params[$index])) { |
|
| 1247 | + if (!preg_match('#^' . $pattern . '$#u', $params[$index])) { |
|
| 1248 | 1248 | throw RouterException::invalidParameterType(); |
| 1249 | 1249 | } |
| 1250 | 1250 | |
@@ -1322,9 +1322,9 @@ discard block |
||
| 1322 | 1322 | } |
| 1323 | 1323 | |
| 1324 | 1324 | // Limitation du nom d'hôte ? |
| 1325 | - if (! empty($options['hostname'])) { |
|
| 1325 | + if (!empty($options['hostname'])) { |
|
| 1326 | 1326 | // @todo déterminer s'il existe un moyen de mettre les hôtes sur liste blanche ? |
| 1327 | - if (! $this->checkHostname($options['hostname'])) { |
|
| 1327 | + if (!$this->checkHostname($options['hostname'])) { |
|
| 1328 | 1328 | return; |
| 1329 | 1329 | } |
| 1330 | 1330 | |
@@ -1332,10 +1332,10 @@ discard block |
||
| 1332 | 1332 | } |
| 1333 | 1333 | |
| 1334 | 1334 | // Limitation du nom sous-domaine ? |
| 1335 | - elseif (! empty($options['subdomain'])) { |
|
| 1335 | + elseif (!empty($options['subdomain'])) { |
|
| 1336 | 1336 | // Si nous ne correspondons pas au sous-domaine actuel, alors |
| 1337 | 1337 | // nous n'avons pas besoin d'ajouter la route. |
| 1338 | - if (! $this->checkSubdomains($options['subdomain'])) { |
|
| 1338 | + if (!$this->checkSubdomains($options['subdomain'])) { |
|
| 1339 | 1339 | return; |
| 1340 | 1340 | } |
| 1341 | 1341 | |
@@ -1368,7 +1368,7 @@ discard block |
||
| 1368 | 1368 | } |
| 1369 | 1369 | |
| 1370 | 1370 | // S'il s'agit d'une redirection, aucun traitement |
| 1371 | - if (! isset($options['redirect']) && is_string($to)) { |
|
| 1371 | + if (!isset($options['redirect']) && is_string($to)) { |
|
| 1372 | 1372 | // Si aucun espace de noms n'est trouvé, ajouter l'espace de noms par défaut |
| 1373 | 1373 | if (strpos($to, '\\') === false || strpos($to, '\\') > 0) { |
| 1374 | 1374 | $namespace = $options['namespace'] ?? $this->defaultNamespace; |
@@ -1387,7 +1387,7 @@ discard block |
||
| 1387 | 1387 | // cela ne fonctionne que parce que les routes découvertes sont ajoutées juste avant |
| 1388 | 1388 | // pour tenter de router la requête. |
| 1389 | 1389 | $routeKeyExists = isset($this->routes[$verb][$routeKey]); |
| 1390 | - if ((isset($this->routesNames[$verb][$name]) || $routeKeyExists) && ! $overwrite) { |
|
| 1390 | + if ((isset($this->routesNames[$verb][$name]) || $routeKeyExists) && !$overwrite) { |
|
| 1391 | 1391 | return; |
| 1392 | 1392 | } |
| 1393 | 1393 | |
@@ -1413,7 +1413,7 @@ discard block |
||
| 1413 | 1413 | private function checkHostname(string $hostname): bool |
| 1414 | 1414 | { |
| 1415 | 1415 | // Les appels CLI ne peuvent pas être sur le nom d'hôte. |
| 1416 | - if (! isset($this->httpHost) || is_cli()) { |
|
| 1416 | + if (!isset($this->httpHost) || is_cli()) { |
|
| 1417 | 1417 | return false; |
| 1418 | 1418 | } |
| 1419 | 1419 | |
@@ -1429,7 +1429,7 @@ discard block |
||
| 1429 | 1429 | private function checkSubdomains($subdomains): bool |
| 1430 | 1430 | { |
| 1431 | 1431 | // Les appels CLI ne peuvent pas être sur le sous-domaine. |
| 1432 | - if (! isset($this->httpHost)) { |
|
| 1432 | + if (!isset($this->httpHost)) { |
|
| 1433 | 1433 | return false; |
| 1434 | 1434 | } |
| 1435 | 1435 | |
@@ -1437,13 +1437,13 @@ discard block |
||
| 1437 | 1437 | $this->currentSubdomain = $this->determineCurrentSubdomain(); |
| 1438 | 1438 | } |
| 1439 | 1439 | |
| 1440 | - if (! is_array($subdomains)) { |
|
| 1440 | + if (!is_array($subdomains)) { |
|
| 1441 | 1441 | $subdomains = [$subdomains]; |
| 1442 | 1442 | } |
| 1443 | 1443 | |
| 1444 | 1444 | // Les routes peuvent être limitées à n'importe quel sous-domaine. Dans ce cas, cependant, |
| 1445 | 1445 | // il nécessite la présence d'un sous-domaine. |
| 1446 | - if (! empty($this->currentSubdomain) && in_array('*', $subdomains, true)) { |
|
| 1446 | + if (!empty($this->currentSubdomain) && in_array('*', $subdomains, true)) { |
|
| 1447 | 1447 | return true; |
| 1448 | 1448 | } |
| 1449 | 1449 | |
@@ -1506,7 +1506,7 @@ discard block |
||
| 1506 | 1506 | |
| 1507 | 1507 | private function getControllerName(Closure|string $handler): ?string |
| 1508 | 1508 | { |
| 1509 | - if (! is_string($handler)) { |
|
| 1509 | + if (!is_string($handler)) { |
|
| 1510 | 1510 | return null; |
| 1511 | 1511 | } |
| 1512 | 1512 | |
@@ -1571,7 +1571,7 @@ discard block |
||
| 1571 | 1571 | |
| 1572 | 1572 | // Vérifier les paramètres régionaux non valides |
| 1573 | 1573 | if ($locale !== null) { |
| 1574 | - if (! in_array($locale, config('app.supported_locales'), true)) { |
|
| 1574 | + if (!in_array($locale, config('app.supported_locales'), true)) { |
|
| 1575 | 1575 | $locale = null; |
| 1576 | 1576 | } |
| 1577 | 1577 | } |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | |
| 123 | 123 | /** |
| 124 | 124 | * Tableau des noms des routes |
| 125 | - * |
|
| 125 | + * |
|
| 126 | 126 | * [ |
| 127 | 127 | * verb => [ |
| 128 | 128 | * routeName => routeKey(regex) |
@@ -221,14 +221,14 @@ discard block |
||
| 221 | 221 | |
| 222 | 222 | /** |
| 223 | 223 | * Constructor |
| 224 | - * |
|
| 225 | - * @var Locator $locator Descripteur du localisateur de fichiers à utiliser. |
|
| 224 | + * |
|
| 225 | + * @var Locator $locator Descripteur du localisateur de fichiers à utiliser. |
|
| 226 | 226 | */ |
| 227 | 227 | public function __construct(protected Locator $locator, object $routing) |
| 228 | 228 | { |
| 229 | 229 | $this->httpHost = Services::request()->getEnv('HTTP_HOST'); |
| 230 | 230 | |
| 231 | - // Configuration basée sur le fichier de config. Laissez le fichier routes substituer. |
|
| 231 | + // Configuration basée sur le fichier de config. Laissez le fichier routes substituer. |
|
| 232 | 232 | $this->defaultNamespace = rtrim($routing->default_namespace ?: $this->defaultNamespace, '\\') . '\\'; |
| 233 | 233 | $this->defaultController = $routing->default_controller ?: $this->defaultController; |
| 234 | 234 | $this->defaultMethod = $routing->default_method ?: $this->defaultMethod; |
@@ -238,7 +238,7 @@ discard block |
||
| 238 | 238 | $this->routeFiles = $routing->route_files ?: $this->routeFiles; |
| 239 | 239 | $this->prioritize = $routing->prioritize ?: $this->prioritize; |
| 240 | 240 | |
| 241 | - // Normaliser la chaîne de path dans le tableau routeFiles. |
|
| 241 | + // Normaliser la chaîne de path dans le tableau routeFiles. |
|
| 242 | 242 | foreach ($this->routeFiles as $routeKey => $routesFile) { |
| 243 | 243 | $this->routeFiles[$routeKey] = realpath($routesFile) ?: $routesFile; |
| 244 | 244 | } |
@@ -256,18 +256,18 @@ discard block |
||
| 256 | 256 | } |
| 257 | 257 | |
| 258 | 258 | // Incluez le fichier routesFile s'il n'existe pas. |
| 259 | - // Ne conserver que pour les fins BC pour l'instant. |
|
| 259 | + // Ne conserver que pour les fins BC pour l'instant. |
|
| 260 | 260 | $routeFiles = $this->routeFiles; |
| 261 | 261 | if (! in_array($routesFile, $routeFiles, true)) { |
| 262 | 262 | $routeFiles[] = $routesFile; |
| 263 | 263 | } |
| 264 | 264 | |
| 265 | - // Nous avons besoin de cette variable dans la portée locale pour que les fichiers de route puissent y accéder. |
|
| 265 | + // Nous avons besoin de cette variable dans la portée locale pour que les fichiers de route puissent y accéder. |
|
| 266 | 266 | $routes = $this; |
| 267 | 267 | |
| 268 | - foreach ($routeFiles as $routesFile) { |
|
| 268 | + foreach ($routeFiles as $routesFile) { |
|
| 269 | 269 | if (! is_file($routesFile)) { |
| 270 | - logger()->warning(sprintf('Fichier de route introuvable : "%s"', $routesFile)); |
|
| 270 | + logger()->warning(sprintf('Fichier de route introuvable : "%s"', $routesFile)); |
|
| 271 | 271 | |
| 272 | 272 | continue; |
| 273 | 273 | } |
@@ -289,11 +289,11 @@ discard block |
||
| 289 | 289 | $this->routes = $this->routesNames = ['*' => []]; |
| 290 | 290 | |
| 291 | 291 | foreach ($this->defaultHTTPMethods as $verb) { |
| 292 | - $this->routes[$verb] = []; |
|
| 293 | - $this->routesNames[$verb] = []; |
|
| 292 | + $this->routes[$verb] = []; |
|
| 293 | + $this->routesNames[$verb] = []; |
|
| 294 | 294 | } |
| 295 | 295 | |
| 296 | - $this->routesOptions = []; |
|
| 296 | + $this->routesOptions = []; |
|
| 297 | 297 | |
| 298 | 298 | $this->prioritizeDetected = false; |
| 299 | 299 | $this->didDiscover = false; |
@@ -543,9 +543,9 @@ discard block |
||
| 543 | 543 | if (isset($this->routes[$verb])) { |
| 544 | 544 | // Conserve les itinéraires du verbe actuel au début afin qu'ils soient |
| 545 | 545 | // mis en correspondance avant l'un des itinéraires génériques "add". |
| 546 | - $collection = $includeWildcard ? $this->routes[$verb] + ($this->routes['*'] ?? []) : $this->routes[$verb]; |
|
| 546 | + $collection = $includeWildcard ? $this->routes[$verb] + ($this->routes['*'] ?? []) : $this->routes[$verb]; |
|
| 547 | 547 | |
| 548 | - foreach ($collection as $routeKey => $r) { |
|
| 548 | + foreach ($collection as $routeKey => $r) { |
|
| 549 | 549 | $routes[$routeKey] = $r['handler']; |
| 550 | 550 | } |
| 551 | 551 | } |
@@ -632,7 +632,7 @@ discard block |
||
| 632 | 632 | { |
| 633 | 633 | // Utilisez le modèle de la route nommée s'il s'agit d'une route nommée. |
| 634 | 634 | if (array_key_exists($to, $this->routesNames['*'])) { |
| 635 | - $routeName = $to; |
|
| 635 | + $routeName = $to; |
|
| 636 | 636 | $routeKey = $this->routesNames['*'][$routeName]; |
| 637 | 637 | $redirectTo = [$routeKey => $this->routes['*'][$routeKey]['handler']]; |
| 638 | 638 | |
@@ -652,18 +652,18 @@ discard block |
||
| 652 | 652 | |
| 653 | 653 | /** |
| 654 | 654 | * {@inheritDoc} |
| 655 | - * |
|
| 656 | - * @param string $routeKey cle de route ou route nommee |
|
| 655 | + * |
|
| 656 | + * @param string $routeKey cle de route ou route nommee |
|
| 657 | 657 | */ |
| 658 | 658 | public function isRedirect(string $routeKey): bool |
| 659 | 659 | { |
| 660 | - return isset($this->routes['*'][$routeKey]['redirect']); |
|
| 660 | + return isset($this->routes['*'][$routeKey]['redirect']); |
|
| 661 | 661 | } |
| 662 | 662 | |
| 663 | 663 | /** |
| 664 | 664 | * {@inheritDoc} |
| 665 | - * |
|
| 666 | - * @param string $routeKey cle de route ou route nommee |
|
| 665 | + * |
|
| 666 | + * @param string $routeKey cle de route ou route nommee |
|
| 667 | 667 | */ |
| 668 | 668 | public function getRedirectCode(string $routeKey): int |
| 669 | 669 | { |
@@ -786,59 +786,59 @@ discard block |
||
| 786 | 786 | } |
| 787 | 787 | } |
| 788 | 788 | |
| 789 | - $routeName = $name; |
|
| 790 | - if (isset($options['as']) || isset($options['name'])) { |
|
| 791 | - $routeName = trim($options['as'] ?? $options['name'], " ."); |
|
| 792 | - unset($options['name'], $options['as']); |
|
| 793 | - } |
|
| 789 | + $routeName = $name; |
|
| 790 | + if (isset($options['as']) || isset($options['name'])) { |
|
| 791 | + $routeName = trim($options['as'] ?? $options['name'], " ."); |
|
| 792 | + unset($options['name'], $options['as']); |
|
| 793 | + } |
|
| 794 | 794 | |
| 795 | 795 | if (in_array('index', $methods, true)) { |
| 796 | 796 | $this->get($name, $newName . '::index', $options + [ |
| 797 | - 'as' => $routeName . '.index', |
|
| 798 | - ]); |
|
| 797 | + 'as' => $routeName . '.index', |
|
| 798 | + ]); |
|
| 799 | 799 | } |
| 800 | 800 | if (in_array('new', $methods, true)) { |
| 801 | 801 | $this->get($name . '/new', $newName . '::new', $options + [ |
| 802 | - 'as' => $routeName . '.new', |
|
| 803 | - ]); |
|
| 802 | + 'as' => $routeName . '.new', |
|
| 803 | + ]); |
|
| 804 | 804 | } |
| 805 | 805 | if (in_array('edit', $methods, true)) { |
| 806 | 806 | $this->get($name . '/' . $id . '/edit', $newName . '::edit/$1', $options + [ |
| 807 | - 'as' => $routeName . '.edit', |
|
| 808 | - ]); |
|
| 807 | + 'as' => $routeName . '.edit', |
|
| 808 | + ]); |
|
| 809 | 809 | } |
| 810 | 810 | if (in_array('show', $methods, true)) { |
| 811 | 811 | $this->get($name . '/' . $id, $newName . '::show/$1', $options + [ |
| 812 | - 'as' => $routeName . '.show', |
|
| 813 | - ]); |
|
| 812 | + 'as' => $routeName . '.show', |
|
| 813 | + ]); |
|
| 814 | 814 | } |
| 815 | 815 | if (in_array('create', $methods, true)) { |
| 816 | 816 | $this->post($name, $newName . '::create', $options + [ |
| 817 | - 'as' => $routeName . '.create', |
|
| 818 | - ]); |
|
| 817 | + 'as' => $routeName . '.create', |
|
| 818 | + ]); |
|
| 819 | 819 | } |
| 820 | 820 | if (in_array('update', $methods, true)) { |
| 821 | - $this->match(['put', 'patch'], $name . '/' . $id, $newName . '::update/$1', $options + [ |
|
| 822 | - 'as' => $routeName . '.update', |
|
| 823 | - ]); |
|
| 821 | + $this->match(['put', 'patch'], $name . '/' . $id, $newName . '::update/$1', $options + [ |
|
| 822 | + 'as' => $routeName . '.update', |
|
| 823 | + ]); |
|
| 824 | 824 | } |
| 825 | 825 | if (in_array('delete', $methods, true)) { |
| 826 | 826 | $this->delete($name . '/' . $id, $newName . '::delete/$1', $options + [ |
| 827 | - 'as' => $routeName . '.delete', |
|
| 828 | - ]); |
|
| 827 | + 'as' => $routeName . '.delete', |
|
| 828 | + ]); |
|
| 829 | 829 | } |
| 830 | 830 | |
| 831 | 831 | // Websafe ? la suppression doit être vérifiée avant la mise à jour en raison du nom de la méthode |
| 832 | 832 | if (isset($options['websafe'])) { |
| 833 | 833 | if (in_array('delete', $methods, true)) { |
| 834 | 834 | $this->post($name . '/' . $id . '/delete', $newName . '::delete/$1', $options + [ |
| 835 | - 'as' => $routeName . '.websafe.delete', |
|
| 836 | - ]); |
|
| 835 | + 'as' => $routeName . '.websafe.delete', |
|
| 836 | + ]); |
|
| 837 | 837 | } |
| 838 | 838 | if (in_array('update', $methods, true)) { |
| 839 | 839 | $this->post($name . '/' . $id, $newName . '::update/$1', $options + [ |
| 840 | - 'as' => $routeName . '.websafe.update', |
|
| 841 | - ]); |
|
| 840 | + 'as' => $routeName . '.websafe.update', |
|
| 841 | + ]); |
|
| 842 | 842 | } |
| 843 | 843 | } |
| 844 | 844 | |
@@ -903,57 +903,57 @@ discard block |
||
| 903 | 903 | } |
| 904 | 904 | } |
| 905 | 905 | |
| 906 | - $routeName = $name; |
|
| 907 | - if (isset($options['as']) || isset($options['name'])) { |
|
| 908 | - $routeName = trim($options['as'] ?? $options['name'], " ."); |
|
| 909 | - unset($options['name'], $options['as']); |
|
| 910 | - } |
|
| 906 | + $routeName = $name; |
|
| 907 | + if (isset($options['as']) || isset($options['name'])) { |
|
| 908 | + $routeName = trim($options['as'] ?? $options['name'], " ."); |
|
| 909 | + unset($options['name'], $options['as']); |
|
| 910 | + } |
|
| 911 | 911 | |
| 912 | 912 | if (in_array('index', $methods, true)) { |
| 913 | 913 | $this->get($name, $newName . '::index', $options + [ |
| 914 | - 'as' => $routeName . '.index', |
|
| 915 | - ]); |
|
| 914 | + 'as' => $routeName . '.index', |
|
| 915 | + ]); |
|
| 916 | 916 | } |
| 917 | 917 | if (in_array('show', $methods, true)) { |
| 918 | 918 | $this->get($name . '/show/' . $id, $newName . '::show/$1', $options + [ |
| 919 | - 'as' => $routeName . '.view' |
|
| 920 | - ]); |
|
| 921 | - $this->get($name . '/' . $id, $newName . '::show/$1', $options + [ |
|
| 922 | - 'as' => $routeName . '.show' |
|
| 923 | - ]); |
|
| 919 | + 'as' => $routeName . '.view' |
|
| 920 | + ]); |
|
| 921 | + $this->get($name . '/' . $id, $newName . '::show/$1', $options + [ |
|
| 922 | + 'as' => $routeName . '.show' |
|
| 923 | + ]); |
|
| 924 | 924 | } |
| 925 | 925 | if (in_array('new', $methods, true)) { |
| 926 | 926 | $this->get($name . '/new', $newName . '::new', $options + [ |
| 927 | - 'as' => $routeName . '.new' |
|
| 928 | - ]); |
|
| 927 | + 'as' => $routeName . '.new' |
|
| 928 | + ]); |
|
| 929 | 929 | } |
| 930 | 930 | if (in_array('create', $methods, true)) { |
| 931 | 931 | $this->post($name . '/create', $newName . '::create', $options + [ |
| 932 | - 'as' => $routeName . '.create' |
|
| 933 | - ]); |
|
| 934 | - $this->post($name, $newName . '::create', $options + [ |
|
| 935 | - 'as' => $routeName . '.store' |
|
| 936 | - ]); |
|
| 932 | + 'as' => $routeName . '.create' |
|
| 933 | + ]); |
|
| 934 | + $this->post($name, $newName . '::create', $options + [ |
|
| 935 | + 'as' => $routeName . '.store' |
|
| 936 | + ]); |
|
| 937 | 937 | } |
| 938 | 938 | if (in_array('edit', $methods, true)) { |
| 939 | 939 | $this->get($name . '/edit/' . $id, $newName . '::edit/$1', $options + [ |
| 940 | - 'as' => $routeName . '.edit' |
|
| 941 | - ]); |
|
| 940 | + 'as' => $routeName . '.edit' |
|
| 941 | + ]); |
|
| 942 | 942 | } |
| 943 | 943 | if (in_array('update', $methods, true)) { |
| 944 | 944 | $this->post($name . '/update/' . $id, $newName . '::update/$1', $options + [ |
| 945 | - 'as' => $routeName . '.update', |
|
| 946 | - ]); |
|
| 945 | + 'as' => $routeName . '.update', |
|
| 946 | + ]); |
|
| 947 | 947 | } |
| 948 | 948 | if (in_array('remove', $methods, true)) { |
| 949 | 949 | $this->get($name . '/remove/' . $id, $newName . '::remove/$1', $options + [ |
| 950 | - 'as' => $routeName . '.remove', |
|
| 951 | - ]); |
|
| 950 | + 'as' => $routeName . '.remove', |
|
| 951 | + ]); |
|
| 952 | 952 | } |
| 953 | 953 | if (in_array('delete', $methods, true)) { |
| 954 | 954 | $this->post($name . '/delete/' . $id, $newName . '::delete/$1', $options + [ |
| 955 | - 'as' => $routeName . '.delete', |
|
| 956 | - ]); |
|
| 955 | + 'as' => $routeName . '.delete', |
|
| 956 | + ]); |
|
| 957 | 957 | } |
| 958 | 958 | |
| 959 | 959 | return $this; |
@@ -1067,17 +1067,17 @@ discard block |
||
| 1067 | 1067 | } |
| 1068 | 1068 | |
| 1069 | 1069 | |
| 1070 | - /** |
|
| 1070 | + /** |
|
| 1071 | 1071 | * Spécifie une route qui n'est disponible que pour les requêtes GET et POST. |
| 1072 | 1072 | * |
| 1073 | 1073 | * @param array|Closure|string $to |
| 1074 | 1074 | */ |
| 1075 | - public function form(string $from, $to, ?array $options = null): self |
|
| 1076 | - { |
|
| 1077 | - return $this->match(['GET', 'POST'], $from, $to, $options); |
|
| 1078 | - } |
|
| 1075 | + public function form(string $from, $to, ?array $options = null): self |
|
| 1076 | + { |
|
| 1077 | + return $this->match(['GET', 'POST'], $from, $to, $options); |
|
| 1078 | + } |
|
| 1079 | 1079 | |
| 1080 | - /** |
|
| 1080 | + /** |
|
| 1081 | 1081 | * Spécifie une route qui n'est disponible que pour les requêtes de ligne de commande. |
| 1082 | 1082 | * |
| 1083 | 1083 | * @param array|Closure|string $to |
@@ -1101,10 +1101,10 @@ discard block |
||
| 1101 | 1101 | ->setOptions($options) |
| 1102 | 1102 | ->render(); |
| 1103 | 1103 | |
| 1104 | - $routeOptions = $options ?? []; |
|
| 1105 | - $routeOptions = array_merge($routeOptions, ['view' => $view]); |
|
| 1104 | + $routeOptions = $options ?? []; |
|
| 1105 | + $routeOptions = array_merge($routeOptions, ['view' => $view]); |
|
| 1106 | 1106 | |
| 1107 | - $this->create('get', $from, $to, $routeOptions); |
|
| 1107 | + $this->create('get', $from, $to, $routeOptions); |
|
| 1108 | 1108 | |
| 1109 | 1109 | return $this; |
| 1110 | 1110 | } |
@@ -1360,7 +1360,7 @@ discard block |
||
| 1360 | 1360 | } |
| 1361 | 1361 | } |
| 1362 | 1362 | |
| 1363 | - $routeKey = $from; |
|
| 1363 | + $routeKey = $from; |
|
| 1364 | 1364 | |
| 1365 | 1365 | // Remplacez nos espaces réservés de regex par la chose réelle |
| 1366 | 1366 | // pour que le routeur n'ait pas besoin de savoir quoi que ce soit. |
@@ -1392,7 +1392,7 @@ discard block |
||
| 1392 | 1392 | return; |
| 1393 | 1393 | } |
| 1394 | 1394 | |
| 1395 | - $this->routes[$verb][$routeKey] = [ |
|
| 1395 | + $this->routes[$verb][$routeKey] = [ |
|
| 1396 | 1396 | 'name' => $name, |
| 1397 | 1397 | 'handler' => $to, |
| 1398 | 1398 | 'from' => $from, |
@@ -1495,15 +1495,15 @@ discard block |
||
| 1495 | 1495 | return array_shift($host); |
| 1496 | 1496 | } |
| 1497 | 1497 | |
| 1498 | - /** |
|
| 1499 | - * Formate le nom des routes |
|
| 1500 | - */ |
|
| 1501 | - private function formatRouteName(string $name): string |
|
| 1502 | - { |
|
| 1503 | - $name = trim($name, '/'); |
|
| 1498 | + /** |
|
| 1499 | + * Formate le nom des routes |
|
| 1500 | + */ |
|
| 1501 | + private function formatRouteName(string $name): string |
|
| 1502 | + { |
|
| 1503 | + $name = trim($name, '/'); |
|
| 1504 | 1504 | |
| 1505 | - return strtolower(str_replace(['/', '\\', '_', '.', ' '], '.', $name)); |
|
| 1506 | - } |
|
| 1505 | + return strtolower(str_replace(['/', '\\', '_', '.', ' '], '.', $name)); |
|
| 1506 | + } |
|
| 1507 | 1507 | |
| 1508 | 1508 | private function getControllerName(Closure|string $handler): ?string |
| 1509 | 1509 | { |
@@ -147,11 +147,11 @@ discard block |
||
| 147 | 147 | $this->middlewaresInfo = $this->collection->getFiltersForRoute($this->matchedRoute[0]); |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | - // met a jour le routeur dans le conteneur car permet notament de recupere les bonnes |
|
| 151 | - // info du routing (route actuelle, controleur et methode mappés) |
|
| 152 | - Services::set(static::class, $this); |
|
| 150 | + // met a jour le routeur dans le conteneur car permet notament de recupere les bonnes |
|
| 151 | + // info du routing (route actuelle, controleur et methode mappés) |
|
| 152 | + Services::set(static::class, $this); |
|
| 153 | 153 | |
| 154 | - return $this->controllerName(); |
|
| 154 | + return $this->controllerName(); |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | // Toujours là ? Ensuite, nous pouvons essayer de faire correspondre l'URI avec |
@@ -163,9 +163,9 @@ discard block |
||
| 163 | 163 | |
| 164 | 164 | $this->autoRoute($uri); |
| 165 | 165 | |
| 166 | - // met a jour le routeur dans le conteneur car permet notament de recupere les bonnes |
|
| 167 | - // info du routing (route actuelle, controleur et methode mappés) |
|
| 168 | - Services::set(static::class, $this); |
|
| 166 | + // met a jour le routeur dans le conteneur car permet notament de recupere les bonnes |
|
| 167 | + // info du routing (route actuelle, controleur et methode mappés) |
|
| 168 | + Services::set(static::class, $this); |
|
| 169 | 169 | |
| 170 | 170 | return $this->controllerName(); |
| 171 | 171 | } |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | // Toujours là ? Ensuite, nous pouvons essayer de faire correspondre l'URI avec |
| 158 | 158 | // Contrôleurs/répertoires, mais l'application peut ne pas |
| 159 | 159 | // vouloir ceci, comme dans le cas des API. |
| 160 | - if (! $this->collection->shouldAutoRoute()) { |
|
| 160 | + if (!$this->collection->shouldAutoRoute()) { |
|
| 161 | 161 | throw new PageNotFoundException("Impossible de trouver une route pour '{$this->collection->getHTTPVerb()}: {$uri}'."); |
| 162 | 162 | } |
| 163 | 163 | |
@@ -187,11 +187,11 @@ discard block |
||
| 187 | 187 | */ |
| 188 | 188 | public function controllerName() |
| 189 | 189 | { |
| 190 | - if (! is_string($this->controller)) { |
|
| 190 | + if (!is_string($this->controller)) { |
|
| 191 | 191 | return $this->controller; |
| 192 | 192 | } |
| 193 | 193 | |
| 194 | - $controller = str_contains($this->controller, '\\') |
|
| 194 | + $controller = str_contains($this->controller, '\\') |
|
| 195 | 195 | ? $this->controller |
| 196 | 196 | : trim($this->collection->getDefaultNamespace(), '\\') . '\\' . $this->controller; |
| 197 | 197 | |
@@ -231,7 +231,7 @@ discard block |
||
| 231 | 231 | |
| 232 | 232 | return [ |
| 233 | 233 | $routeArray[0], // Controller |
| 234 | - $routeArray[1] ?? 'index', // Method |
|
| 234 | + $routeArray[1] ?? 'index', // Method |
|
| 235 | 235 | ]; |
| 236 | 236 | } |
| 237 | 237 | |
@@ -355,7 +355,7 @@ discard block |
||
| 355 | 355 | // Cette route est-elle censée rediriger vers une autre ? |
| 356 | 356 | if ($this->collection->isRedirect($routeKey)) { |
| 357 | 357 | // remplacement des groupes de routes correspondants par des références : post/([0-9]+) -> post/$1 |
| 358 | - $redirectTo = preg_replace_callback('/(\([^\(]+\))/', static function () { |
|
| 358 | + $redirectTo = preg_replace_callback('/(\([^\(]+\))/', static function() { |
|
| 359 | 359 | static $i = 1; |
| 360 | 360 | |
| 361 | 361 | return '$' . $i++; |
@@ -375,7 +375,7 @@ discard block |
||
| 375 | 375 | ); |
| 376 | 376 | |
| 377 | 377 | if ($this->collection->shouldUseSupportedLocalesOnly() |
| 378 | - && ! in_array($matched['locale'], config('App')->supportedLocales, true)) { |
|
| 378 | + && !in_array($matched['locale'], config('App')->supportedLocales, true)) { |
|
| 379 | 379 | // Lancer une exception pour empêcher l'autorouteur, |
| 380 | 380 | // si activé, essayer de trouver une route |
| 381 | 381 | throw PageNotFoundException::localeNotSupported($matched['locale']); |
@@ -387,7 +387,7 @@ discard block |
||
| 387 | 387 | |
| 388 | 388 | // Utilisons-nous Closures ? Si tel est le cas, nous devons collecter les paramètres dans un tableau |
| 389 | 389 | // afin qu'ils puissent être transmis ultérieurement à la méthode du contrôleur. |
| 390 | - if (! is_string($handler) && is_callable($handler)) { |
|
| 390 | + if (!is_string($handler) && is_callable($handler)) { |
|
| 391 | 391 | $this->controller = $handler; |
| 392 | 392 | |
| 393 | 393 | // Supprime la chaîne d'origine du tableau matches |
@@ -463,7 +463,7 @@ discard block |
||
| 463 | 463 | |
| 464 | 464 | // $this->method contient déjà le nom de la méthode par défaut, |
| 465 | 465 | // donc ne l'écrasez pas avec le vide. |
| 466 | - if (! empty($method)) { |
|
| 466 | + if (!empty($method)) { |
|
| 467 | 467 | $this->setMethod($method); |
| 468 | 468 | } |
| 469 | 469 | |
@@ -124,8 +124,8 @@ discard block |
||
| 124 | 124 | * Chemin de requête à utiliser. |
| 125 | 125 | * |
| 126 | 126 | * @var string |
| 127 | - * |
|
| 128 | - * @deprecated No longer used. |
|
| 127 | + * |
|
| 128 | + * @deprecated No longer used. |
|
| 129 | 129 | */ |
| 130 | 130 | protected $path; |
| 131 | 131 | |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | */ |
| 135 | 135 | protected int $bufferLevel = 0; |
| 136 | 136 | |
| 137 | - /** |
|
| 137 | + /** |
|
| 138 | 138 | * Web Page Caching |
| 139 | 139 | */ |
| 140 | 140 | protected ResponseCache $pageCache; |
@@ -147,9 +147,9 @@ discard block |
||
| 147 | 147 | $this->startTime = microtime(true); |
| 148 | 148 | $this->config = (object) config('app'); |
| 149 | 149 | |
| 150 | - $this->pageCache = Services::factory(ResponseCache::class, [ |
|
| 151 | - 'cacheQueryString' => config('cache.cache_query_string') |
|
| 152 | - ]); |
|
| 150 | + $this->pageCache = Services::factory(ResponseCache::class, [ |
|
| 151 | + 'cacheQueryString' => config('cache.cache_query_string') |
|
| 152 | + ]); |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | /** |
@@ -179,7 +179,7 @@ discard block |
||
| 179 | 179 | $controller = $routes->getDefaultController(); |
| 180 | 180 | } |
| 181 | 181 | |
| 182 | - if (! $fullName && is_string($controller)) { |
|
| 182 | + if (! $fullName && is_string($controller)) { |
|
| 183 | 183 | $controller = str_replace($routes->getDefaultNamespace(), '', $controller); |
| 184 | 184 | } |
| 185 | 185 | |
@@ -211,7 +211,7 @@ discard block |
||
| 211 | 211 | |
| 212 | 212 | $this->initMiddlewareQueue(); |
| 213 | 213 | |
| 214 | - try { |
|
| 214 | + try { |
|
| 215 | 215 | $this->response = $this->handleRequest($routes, config('cache')); |
| 216 | 216 | } catch (ResponsableInterface|RedirectException $e) { |
| 217 | 217 | $this->outputBufferingEnd(); |
@@ -243,17 +243,17 @@ discard block |
||
| 243 | 243 | */ |
| 244 | 244 | protected function handleRequest(?RouteCollectionInterface $routes = null, ?array $cacheConfig = null): ResponseInterface |
| 245 | 245 | { |
| 246 | - $this->forceSecureAccess(); |
|
| 246 | + $this->forceSecureAccess(); |
|
| 247 | 247 | |
| 248 | - /** |
|
| 248 | + /** |
|
| 249 | 249 | * Init event manager |
| 250 | 250 | */ |
| 251 | - Services::singleton(EventDiscover::class)->discove(); |
|
| 251 | + Services::singleton(EventDiscover::class)->discove(); |
|
| 252 | 252 | |
| 253 | - $this->event->trigger('pre_system'); |
|
| 253 | + $this->event->trigger('pre_system'); |
|
| 254 | 254 | |
| 255 | - // Check for a cached page. |
|
| 256 | - // Execution will stop if the page has been cached. |
|
| 255 | + // Check for a cached page. |
|
| 256 | + // Execution will stop if the page has been cached. |
|
| 257 | 257 | if (($response = $this->displayCache($cacheConfig)) instanceof ResponseInterface) { |
| 258 | 258 | return $response; |
| 259 | 259 | } |
@@ -261,7 +261,7 @@ discard block |
||
| 261 | 261 | $routeMiddlewares = (array) $this->dispatchRoutes($routes); |
| 262 | 262 | |
| 263 | 263 | // Le bootstrap dans un middleware |
| 264 | - $this->middleware->alias('blitz', $this->bootApp()); |
|
| 264 | + $this->middleware->alias('blitz', $this->bootApp()); |
|
| 265 | 265 | $this->middleware->append('blitz'); |
| 266 | 266 | |
| 267 | 267 | /** |
@@ -384,13 +384,13 @@ discard block |
||
| 384 | 384 | */ |
| 385 | 385 | public function displayCache(?array $config = null) |
| 386 | 386 | { |
| 387 | - if ($cachedResponse = $this->pageCache->get($this->request, $this->response)) { |
|
| 387 | + if ($cachedResponse = $this->pageCache->get($this->request, $this->response)) { |
|
| 388 | 388 | $this->response = $cachedResponse; |
| 389 | 389 | |
| 390 | 390 | $this->totalTime = $this->timer->getElapsedTime('total_execution'); |
| 391 | 391 | $output = $this->displayPerformanceMetrics($cachedResponse->getBody()); |
| 392 | 392 | |
| 393 | - return $this->response->withBody(to_stream($output)); |
|
| 393 | + return $this->response->withBody(to_stream($output)); |
|
| 394 | 394 | } |
| 395 | 395 | |
| 396 | 396 | return false; |
@@ -589,7 +589,7 @@ discard block |
||
| 589 | 589 | |
| 590 | 590 | $this->gatherOutput($returned); |
| 591 | 591 | |
| 592 | - return $this->response; |
|
| 592 | + return $this->response; |
|
| 593 | 593 | } |
| 594 | 594 | |
| 595 | 595 | // Affiche l'erreur 404 |
@@ -659,13 +659,13 @@ discard block |
||
| 659 | 659 | $uri = Services::uri($uri, false); |
| 660 | 660 | } |
| 661 | 661 | |
| 662 | - Services::session()->setPreviousUrl(Uri::createURIString( |
|
| 663 | - $uri->getScheme(), |
|
| 664 | - $uri->getAuthority(), |
|
| 665 | - $uri->getPath(), |
|
| 666 | - $uri->getQuery(), |
|
| 667 | - $uri->getFragment() |
|
| 668 | - )); |
|
| 662 | + Services::session()->setPreviousUrl(Uri::createURIString( |
|
| 663 | + $uri->getScheme(), |
|
| 664 | + $uri->getAuthority(), |
|
| 665 | + $uri->getPath(), |
|
| 666 | + $uri->getQuery(), |
|
| 667 | + $uri->getFragment() |
|
| 668 | + )); |
|
| 669 | 669 | } |
| 670 | 670 | |
| 671 | 671 | /** |
@@ -697,9 +697,9 @@ discard block |
||
| 697 | 697 | return $returned; |
| 698 | 698 | } |
| 699 | 699 | |
| 700 | - if ($returned instanceof Responsable) { |
|
| 701 | - return $returned->toResponse($this->request); |
|
| 702 | - } |
|
| 700 | + if ($returned instanceof Responsable) { |
|
| 701 | + return $returned->toResponse($this->request); |
|
| 702 | + } |
|
| 703 | 703 | |
| 704 | 704 | if (is_object($returned)) { |
| 705 | 705 | if (method_exists($returned, '__toString')) { |
@@ -747,11 +747,11 @@ discard block |
||
| 747 | 747 | $this->middleware->prepend($this->spoofRequestMethod()); |
| 748 | 748 | } |
| 749 | 749 | |
| 750 | - protected function outputBufferingStart(): void |
|
| 750 | + protected function outputBufferingStart(): void |
|
| 751 | 751 | { |
| 752 | 752 | $this->bufferLevel = ob_get_level(); |
| 753 | 753 | |
| 754 | - ob_start(); |
|
| 754 | + ob_start(); |
|
| 755 | 755 | } |
| 756 | 756 | |
| 757 | 757 | protected function outputBufferingEnd(): string |
@@ -821,7 +821,7 @@ discard block |
||
| 821 | 821 | } |
| 822 | 822 | |
| 823 | 823 | if (is_string($this->controller)) { |
| 824 | - if (strtoupper($request->getMethod()) === 'POST') { |
|
| 824 | + if (strtoupper($request->getMethod()) === 'POST') { |
|
| 825 | 825 | if (is_subclass_of($this->controller, RestController::class)) { |
| 826 | 826 | return $this->formatResponse($response->withStatus($code), [ |
| 827 | 827 | 'success' => false, |
@@ -829,7 +829,7 @@ discard block |
||
| 829 | 829 | 'errors' => $errors, |
| 830 | 830 | ]); |
| 831 | 831 | } |
| 832 | - if (is_subclass_of($this->controller, BaseController::class)) { |
|
| 832 | + if (is_subclass_of($this->controller, BaseController::class)) { |
|
| 833 | 833 | return Services::redirection()->back()->withInput()->withErrors($errors)->withStatus($code); |
| 834 | 834 | } |
| 835 | 835 | } |
@@ -179,7 +179,7 @@ discard block |
||
| 179 | 179 | $controller = $routes->getDefaultController(); |
| 180 | 180 | } |
| 181 | 181 | |
| 182 | - if (! $fullName && is_string($controller)) { |
|
| 182 | + if (!$fullName && is_string($controller)) { |
|
| 183 | 183 | $controller = str_replace($routes->getDefaultNamespace(), '', $controller); |
| 184 | 184 | } |
| 185 | 185 | |
@@ -324,14 +324,14 @@ discard block |
||
| 324 | 324 | return; |
| 325 | 325 | } |
| 326 | 326 | |
| 327 | - if (is_cli() && ! on_test()) { |
|
| 327 | + if (is_cli() && !on_test()) { |
|
| 328 | 328 | // @codeCoverageIgnoreStart |
| 329 | 329 | // $this->request = Services::clirequest($this->config); |
| 330 | 330 | // @codeCoverageIgnoreEnd |
| 331 | 331 | } |
| 332 | 332 | |
| 333 | 333 | $version = $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.1'; |
| 334 | - if (! is_numeric($version)) { |
|
| 334 | + if (!is_numeric($version)) { |
|
| 335 | 335 | $version = substr($version, strpos($version, '/') + 1); |
| 336 | 336 | } |
| 337 | 337 | |
@@ -350,7 +350,7 @@ discard block |
||
| 350 | 350 | // Supposons le succès jusqu'à preuve du contraire. |
| 351 | 351 | $this->response = Services::response()->withStatus(200); |
| 352 | 352 | |
| 353 | - if (! is_cli() || on_test()) { |
|
| 353 | + if (!is_cli() || on_test()) { |
|
| 354 | 354 | } |
| 355 | 355 | |
| 356 | 356 | $this->response = $this->response->withProtocolVersion($this->request->getProtocolVersion()); |
@@ -464,7 +464,7 @@ discard block |
||
| 464 | 464 | */ |
| 465 | 465 | protected function determinePath(): string |
| 466 | 466 | { |
| 467 | - if (! empty($this->path)) { |
|
| 467 | + if (!empty($this->path)) { |
|
| 468 | 468 | return $this->path; |
| 469 | 469 | } |
| 470 | 470 | |
@@ -505,7 +505,7 @@ discard block |
||
| 505 | 505 | } |
| 506 | 506 | |
| 507 | 507 | // Essayez de charger automatiquement la classe |
| 508 | - if (! class_exists($this->controller, true) || ($this->method[0] === '_' && $this->method !== '__invoke')) { |
|
| 508 | + if (!class_exists($this->controller, true) || ($this->method[0] === '_' && $this->method !== '__invoke')) { |
|
| 509 | 509 | throw PageNotFoundException::controllerNotFound($this->controller, $this->method); |
| 510 | 510 | } |
| 511 | 511 | |
@@ -598,7 +598,7 @@ discard block |
||
| 598 | 598 | echo $this->outputBufferingEnd(); |
| 599 | 599 | flush(); |
| 600 | 600 | |
| 601 | - throw PageNotFoundException::pageNotFound(! on_prod() || is_cli() ? $e->getMessage() : ''); |
|
| 601 | + throw PageNotFoundException::pageNotFound(!on_prod() || is_cli() ? $e->getMessage() : ''); |
|
| 602 | 602 | } |
| 603 | 603 | |
| 604 | 604 | /** |
@@ -640,7 +640,7 @@ discard block |
||
| 640 | 640 | public function storePreviousURL($uri) |
| 641 | 641 | { |
| 642 | 642 | // Ignorer les requêtes CLI |
| 643 | - if (is_cli() && ! on_test()) { |
|
| 643 | + if (is_cli() && !on_test()) { |
|
| 644 | 644 | return; // @codeCoverageIgnore |
| 645 | 645 | } |
| 646 | 646 | |
@@ -737,7 +737,7 @@ discard block |
||
| 737 | 737 | ]); |
| 738 | 738 | |
| 739 | 739 | $middlewaresFile = CONFIG_PATH . 'middlewares.php'; |
| 740 | - if (file_exists($middlewaresFile) && ! in_array($middlewaresFile, get_included_files(), true)) { |
|
| 740 | + if (file_exists($middlewaresFile) && !in_array($middlewaresFile, get_included_files(), true)) { |
|
| 741 | 741 | $middleware = require $middlewaresFile; |
| 742 | 742 | if (is_callable($middleware)) { |
| 743 | 743 | $middleware($this->middleware, $this->request); |
@@ -772,11 +772,11 @@ discard block |
||
| 772 | 772 | */ |
| 773 | 773 | private function spoofRequestMethod(): callable |
| 774 | 774 | { |
| 775 | - return static function (ServerRequestInterface $request, ResponseInterface $response, callable $next) { |
|
| 775 | + return static function(ServerRequestInterface $request, ResponseInterface $response, callable $next) { |
|
| 776 | 776 | $post = $request->getParsedBody(); |
| 777 | 777 | |
| 778 | 778 | // Ne fonctionne qu'avec les formulaires POST |
| 779 | - if (strtoupper($request->getMethod()) === 'POST' && ! empty($post['_method'])) { |
|
| 779 | + if (strtoupper($request->getMethod()) === 'POST' && !empty($post['_method'])) { |
|
| 780 | 780 | // Accepte seulement PUT, PATCH, DELETE |
| 781 | 781 | if (in_array(strtoupper($post['_method']), ['PUT', 'PATCH', 'DELETE'], true)) { |
| 782 | 782 | $request = $request->withMethod($post['_method']); |
@@ -789,15 +789,15 @@ discard block |
||
| 789 | 789 | |
| 790 | 790 | private function bootApp(): callable |
| 791 | 791 | { |
| 792 | - return function (ServerRequestInterface $request, ResponseInterface $response, callable $next): ResponseInterface { |
|
| 792 | + return function(ServerRequestInterface $request, ResponseInterface $response, callable $next): ResponseInterface { |
|
| 793 | 793 | try { |
| 794 | 794 | $returned = $this->startController($request, $response); |
| 795 | 795 | |
| 796 | 796 | // Closure controller has run in startController(). |
| 797 | - if (! is_callable($this->controller)) { |
|
| 797 | + if (!is_callable($this->controller)) { |
|
| 798 | 798 | $controller = $this->createController($request, $response); |
| 799 | 799 | |
| 800 | - if (! method_exists($controller, '_remap') && ! is_callable([$controller, $this->method], false)) { |
|
| 800 | + if (!method_exists($controller, '_remap') && !is_callable([$controller, $this->method], false)) { |
|
| 801 | 801 | throw PageNotFoundException::methodNotFound($this->method); |
| 802 | 802 | } |
| 803 | 803 | |
@@ -63,19 +63,19 @@ discard block |
||
| 63 | 63 | |
| 64 | 64 | /** |
| 65 | 65 | * Position du contrôleur dans les segments URI. |
| 66 | - * Null pour le contrôleur par défaut. |
|
| 66 | + * Null pour le contrôleur par défaut. |
|
| 67 | 67 | */ |
| 68 | 68 | private ?int $controllerPos = null; |
| 69 | 69 | |
| 70 | 70 | /** |
| 71 | 71 | * Position de la méthode dans les segments URI. |
| 72 | - * Null pour la méthode par défaut. |
|
| 72 | + * Null pour la méthode par défaut. |
|
| 73 | 73 | */ |
| 74 | 74 | private ?int $methodPos = null; |
| 75 | 75 | |
| 76 | 76 | /** |
| 77 | 77 | * Position du premier Paramètre dans les segments URI. |
| 78 | - * Null pour les paramètres non definis. |
|
| 78 | + * Null pour les paramètres non definis. |
|
| 79 | 79 | */ |
| 80 | 80 | private ?int $paramPos = null; |
| 81 | 81 | |
@@ -95,9 +95,9 @@ discard block |
||
| 95 | 95 | private string $defaultMethod, |
| 96 | 96 | private bool $translateURIDashes |
| 97 | 97 | ) { |
| 98 | - $this->namespace = rtrim($namespace, '\\'); |
|
| 98 | + $this->namespace = rtrim($namespace, '\\'); |
|
| 99 | 99 | |
| 100 | - // Definir les valeurs par defaut |
|
| 100 | + // Definir les valeurs par defaut |
|
| 101 | 101 | $this->controller = $this->defaultController; |
| 102 | 102 | } |
| 103 | 103 | |
@@ -114,8 +114,8 @@ discard block |
||
| 114 | 114 | * Recherchez le premier contrôleur correspondant au segment URI. |
| 115 | 115 | * |
| 116 | 116 | * S'il y a un contrôleur correspondant au premier segment, la recherche s'arrête là. |
| 117 | - * Les segments restants sont des paramètres du contrôleur. |
|
| 118 | - * |
|
| 117 | + * Les segments restants sont des paramètres du contrôleur. |
|
| 118 | + * |
|
| 119 | 119 | * @return bool true si une classe de contrôleur est trouvée. |
| 120 | 120 | */ |
| 121 | 121 | private function searchFirstController(): bool |
@@ -156,7 +156,7 @@ discard block |
||
| 156 | 156 | return false; |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | - /** |
|
| 159 | + /** |
|
| 160 | 160 | * Recherchez le dernier contrôleur par défaut correspondant aux segments URI. |
| 161 | 161 | * |
| 162 | 162 | * @return bool true si une classe de contrôleur est trouvée. |
@@ -216,16 +216,16 @@ discard block |
||
| 216 | 216 | return false; |
| 217 | 217 | } |
| 218 | 218 | |
| 219 | - /** |
|
| 219 | + /** |
|
| 220 | 220 | * Recherche contrôleur, méthode et params dans l'URI. |
| 221 | 221 | * |
| 222 | 222 | * @return array [directory_name, controller_name, controller_method, params] |
| 223 | 223 | */ |
| 224 | 224 | public function getRoute(string $uri, string $httpVerb): array |
| 225 | 225 | { |
| 226 | - $httpVerb = strtolower($httpVerb); |
|
| 226 | + $httpVerb = strtolower($httpVerb); |
|
| 227 | 227 | |
| 228 | - // Reinitialise les parametres de la methode du controleur. |
|
| 228 | + // Reinitialise les parametres de la methode du controleur. |
|
| 229 | 229 | $this->params = []; |
| 230 | 230 | |
| 231 | 231 | $defaultMethod = $httpVerb . ucfirst($this->defaultMethod); |
@@ -233,7 +233,7 @@ discard block |
||
| 233 | 233 | |
| 234 | 234 | $this->segments = $this->createSegments($uri); |
| 235 | 235 | |
| 236 | - //Verifier les routes de modules |
|
| 236 | + //Verifier les routes de modules |
|
| 237 | 237 | if ( |
| 238 | 238 | $this->segments !== [] |
| 239 | 239 | && ($routingConfig = (object) config('routing')) |
@@ -243,7 +243,7 @@ discard block |
||
| 243 | 243 | $this->namespace = rtrim($routingConfig->module_routes[$uriSegment], '\\'); |
| 244 | 244 | } |
| 245 | 245 | |
| 246 | - if ($this->searchFirstController()) { |
|
| 246 | + if ($this->searchFirstController()) { |
|
| 247 | 247 | // Le contrôleur a ete trouvé. |
| 248 | 248 | $baseControllerName = Helpers::classBasename($this->controller); |
| 249 | 249 | |
@@ -261,7 +261,7 @@ discard block |
||
| 261 | 261 | throw new PageNotFoundException('Aucun contrôleur trouvé pour: ' . $uri); |
| 262 | 262 | } |
| 263 | 263 | |
| 264 | - // Le premier élément peut être un nom de méthode. |
|
| 264 | + // Le premier élément peut être un nom de méthode. |
|
| 265 | 265 | /** @var string[] $params */ |
| 266 | 266 | $params = $this->params; |
| 267 | 267 | |
@@ -272,7 +272,7 @@ discard block |
||
| 272 | 272 | $method = $httpVerb . ucfirst($this->translateURIDashes($methodParam)); |
| 273 | 273 | } |
| 274 | 274 | |
| 275 | - if ($methodParam !== null && method_exists($this->controller, $method)) { |
|
| 275 | + if ($methodParam !== null && method_exists($this->controller, $method)) { |
|
| 276 | 276 | // Methode trouvee. |
| 277 | 277 | $this->method = $method; |
| 278 | 278 | $this->params = $params; |
@@ -307,14 +307,14 @@ discard block |
||
| 307 | 307 | throw PageNotFoundException::controllerNotFound($this->controller, $method); |
| 308 | 308 | } |
| 309 | 309 | |
| 310 | - // Vérifiez le contrôleur n'est pas défini dans les routes. |
|
| 310 | + // Vérifiez le contrôleur n'est pas défini dans les routes. |
|
| 311 | 311 | $this->protectDefinedRoutes(); |
| 312 | 312 | |
| 313 | 313 | // Assurez-vous que le contrôleur n'a pas la méthode _remap(). |
| 314 | 314 | $this->checkRemap(); |
| 315 | 315 | |
| 316 | 316 | // Assurez-vous que les segments URI pour le contrôleur et la méthode |
| 317 | - // ne contiennent pas de soulignement lorsque $translateURIDashes est true. |
|
| 317 | + // ne contiennent pas de soulignement lorsque $translateURIDashes est true. |
|
| 318 | 318 | $this->checkUnderscore($uri); |
| 319 | 319 | |
| 320 | 320 | // Verifier le nombre de parametres |
@@ -326,7 +326,7 @@ discard block |
||
| 326 | 326 | |
| 327 | 327 | $this->setDirectory(); |
| 328 | 328 | |
| 329 | - return [$this->directory, $this->controllerName(), $this->methodName(), $this->params]; |
|
| 329 | + return [$this->directory, $this->controllerName(), $this->methodName(), $this->params]; |
|
| 330 | 330 | } |
| 331 | 331 | |
| 332 | 332 | private function checkParameters(string $uri): void |
@@ -434,7 +434,7 @@ discard block |
||
| 434 | 434 | } |
| 435 | 435 | } |
| 436 | 436 | |
| 437 | - private function protectDefinedRoutes(): void |
|
| 437 | + private function protectDefinedRoutes(): void |
|
| 438 | 438 | { |
| 439 | 439 | $controller = strtolower($this->controller); |
| 440 | 440 | |
@@ -452,8 +452,8 @@ discard block |
||
| 452 | 452 | /** |
| 453 | 453 | * Renvoie le nom du sous-répertoire dans lequel se trouve le contrôleur. |
| 454 | 454 | * Relatif à CONTROLLER_PATH |
| 455 | - * |
|
| 456 | - * @deprecated 1.0 |
|
| 455 | + * |
|
| 456 | + * @deprecated 1.0 |
|
| 457 | 457 | */ |
| 458 | 458 | public function directory(): string |
| 459 | 459 | { |
@@ -488,8 +488,8 @@ discard block |
||
| 488 | 488 | |
| 489 | 489 | /** |
| 490 | 490 | * Construit un nom de contrôleur valide |
| 491 | - * |
|
| 492 | - * @deprecated 1.0 |
|
| 491 | + * |
|
| 492 | + * @deprecated 1.0 |
|
| 493 | 493 | */ |
| 494 | 494 | public function makeController(string $name): string |
| 495 | 495 | { |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | $class = $this->translateURIDashes(ucfirst($segment)); |
| 134 | 134 | |
| 135 | 135 | // dès que nous rencontrons un segment qui n'est pas compatible PSR-4, arrêter la recherche |
| 136 | - if (! $this->isValidSegment($class)) { |
|
| 136 | + if (!$this->isValidSegment($class)) { |
|
| 137 | 137 | return false; |
| 138 | 138 | } |
| 139 | 139 | |
@@ -344,7 +344,7 @@ discard block |
||
| 344 | 344 | throw new MethodNotFoundException(); |
| 345 | 345 | } |
| 346 | 346 | |
| 347 | - if (! $refMethod->isPublic()) { |
|
| 347 | + if (!$refMethod->isPublic()) { |
|
| 348 | 348 | throw new MethodNotFoundException(); |
| 349 | 349 | } |
| 350 | 350 | |
@@ -457,7 +457,7 @@ discard block |
||
| 457 | 457 | */ |
| 458 | 458 | public function directory(): string |
| 459 | 459 | { |
| 460 | - return ! empty($this->directory) ? $this->directory : ''; |
|
| 460 | + return !empty($this->directory) ? $this->directory : ''; |
|
| 461 | 461 | } |
| 462 | 462 | |
| 463 | 463 | /** |
@@ -467,7 +467,7 @@ discard block |
||
| 467 | 467 | */ |
| 468 | 468 | private function controllerName() |
| 469 | 469 | { |
| 470 | - if (! is_string($this->controller)) { |
|
| 470 | + if (!is_string($this->controller)) { |
|
| 471 | 471 | return $this->controller; |
| 472 | 472 | } |
| 473 | 473 | |
@@ -20,17 +20,17 @@ discard block |
||
| 20 | 20 | { |
| 21 | 21 | /** |
| 22 | 22 | * @param string $namespace Namespace dans lequel on recherche |
| 23 | - * @param array<class-string> $protectedControllers Liste des contrôleurs dans les routes définis qui ne doivent pas être consultés via Auto-Routing. |
|
| 24 | - * @param string $prefix Préfixe URI pour Module Routing |
|
| 23 | + * @param array<class-string> $protectedControllers Liste des contrôleurs dans les routes définis qui ne doivent pas être consultés via Auto-Routing. |
|
| 24 | + * @param string $prefix Préfixe URI pour Module Routing |
|
| 25 | 25 | */ |
| 26 | 26 | public function __construct( |
| 27 | - private string $namespace, |
|
| 28 | - private string $defaultController, |
|
| 29 | - private string $defaultMethod, |
|
| 30 | - private array $httpMethods, |
|
| 27 | + private string $namespace, |
|
| 28 | + private string $defaultController, |
|
| 29 | + private string $defaultMethod, |
|
| 30 | + private array $httpMethods, |
|
| 31 | 31 | private array $protectedControllers, |
| 32 | 32 | private string $prefix = '' |
| 33 | - ) |
|
| 33 | + ) |
|
| 34 | 34 | { |
| 35 | 35 | } |
| 36 | 36 | |
@@ -51,17 +51,17 @@ discard block |
||
| 51 | 51 | continue; |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - $routes = $reader->read( |
|
| 54 | + $routes = $reader->read( |
|
| 55 | 55 | $class, |
| 56 | 56 | $this->defaultController, |
| 57 | 57 | $this->defaultMethod |
| 58 | 58 | ); |
| 59 | 59 | |
| 60 | - if ($routes === []) { |
|
| 60 | + if ($routes === []) { |
|
| 61 | 61 | continue; |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - $routes = $this->addMiddlewares($routes); |
|
| 64 | + $routes = $this->addMiddlewares($routes); |
|
| 65 | 65 | |
| 66 | 66 | foreach ($routes as $item) { |
| 67 | 67 | $route = $item['route'] . $item['route_params']; |
@@ -73,12 +73,12 @@ discard block |
||
| 73 | 73 | $route = $this->prefix . '/' . $route; |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | - $tbody[] = [ |
|
| 76 | + $tbody[] = [ |
|
| 77 | 77 | strtoupper($item['method']) . '(auto)', |
| 78 | 78 | $route, |
| 79 | 79 | '', |
| 80 | 80 | $item['handler'], |
| 81 | - '', |
|
| 81 | + '', |
|
| 82 | 82 | ]; |
| 83 | 83 | } |
| 84 | 84 | } |
@@ -125,7 +125,7 @@ |
||
| 125 | 125 | $i = 1; |
| 126 | 126 | |
| 127 | 127 | foreach ($route['params'] as $required) { |
| 128 | - if ($longest && ! $required) { |
|
| 128 | + if ($longest && !$required) { |
|
| 129 | 129 | $sampleUri .= '/' . $i++; |
| 130 | 130 | } |
| 131 | 131 | } |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | foreach ($reflection->getMethods(ReflectionMethod::IS_PUBLIC) as $method) { |
| 50 | 50 | $methodName = $method->getName(); |
| 51 | 51 | |
| 52 | - foreach ($this->httpMethods as $httpVerb) { |
|
| 52 | + foreach ($this->httpMethods as $httpVerb) { |
|
| 53 | 53 | if (strpos($methodName, $httpVerb) === 0) { |
| 54 | 54 | // Enleve le prefixe des verbes HTTP |
| 55 | 55 | $methodInUri = lcfirst(substr($methodName, strlen($httpVerb))); |
@@ -68,8 +68,8 @@ discard block |
||
| 68 | 68 | |
| 69 | 69 | if ($routeForDefaultController !== []) { |
| 70 | 70 | // Le contrôleur est le contrôleur par défaut. |
| 71 | - // Il n'a qu'un itinéraire pour la méthode par défaut. |
|
| 72 | - // Les autres méthodes ne seront pas routées même si elles existent. |
|
| 71 | + // Il n'a qu'un itinéraire pour la méthode par défaut. |
|
| 72 | + // Les autres méthodes ne seront pas routées même si elles existent. |
|
| 73 | 73 | $output = [...$output, ...$routeForDefaultController]; |
| 74 | 74 | |
| 75 | 75 | continue; |