Passed
Push — main ( 79ccdf...097cc9 )
by Dimitri
03:17
created
src/Router/RouteCollection.php 1 patch
Indentation   +90 added lines, -90 removed lines patch added patch discarded remove patch
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
     {
Please login to merge, or discard this patch.