Skip to content

Commit 6a9c113

Browse files
committed
refactor: now you can write Services::routes()->loadRoutes()
1 parent 26b2c7b commit 6a9c113

File tree

8 files changed

+13
-21
lines changed

8 files changed

+13
-21
lines changed

system/CodeIgniter.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -730,8 +730,7 @@ public function displayPerformanceMetrics(string $output): string
730730
protected function tryToRouteIt(?RouteCollectionInterface $routes = null)
731731
{
732732
if ($routes === null) {
733-
$routes = Services::routes();
734-
$routes->loadRoutes();
733+
$routes = Services::routes()->loadRoutes();
735734
}
736735

737736
// $routes is defined in Config/Routes.php

system/Commands/Utilities/FilterCheck.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ public function run(array $params)
8585
$route = $params[1];
8686

8787
// Load Routes
88-
$routes = Services::routes();
89-
$routes->loadRoutes();
88+
Services::routes()->loadRoutes();
9089

9190
$filterCollector = new FilterCollector();
9291

system/Commands/Utilities/Routes.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,7 @@ class Routes extends BaseCommand
7575
*/
7676
public function run(array $params)
7777
{
78-
$routes = Services::routes();
79-
$routes->loadRoutes();
80-
81-
$collection = $routes;
78+
$collection = Services::routes()->loadRoutes();
8279
$methods = [
8380
'get',
8481
'head',

system/Router/RouteCollection.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,16 +1496,20 @@ public function shouldUseSupportedLocalesOnly(): bool
14961496
* Loads main routes file and discover routes.
14971497
*
14981498
* Loads only once unless reset.
1499+
*
1500+
* @return $this
14991501
*/
1500-
public function loadRoutes(string $routesFile = APPPATH . 'Config/Routes.php'): void
1502+
public function loadRoutes(string $routesFile = APPPATH . 'Config/Routes.php')
15011503
{
15021504
if ($this->didDiscover) {
1503-
return;
1505+
return $this;
15041506
}
15051507

15061508
$routes = $this;
15071509
require $routesFile;
15081510

15091511
$this->discoverRoutes();
1512+
1513+
return $this;
15101514
}
15111515
}

system/Test/FeatureTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public function call(string $method, string $path, ?array $params = null)
177177
// Initialize the RouteCollection
178178
if (! $routes = $this->routes) {
179179
$routes = Services::routes();
180-
$routes->loadRoutes();
180+
$routes->loadRoutes()->loadRoutes();
181181
}
182182

183183
$routes->setHTTPVerb($method);

system/Test/FeatureTestTrait.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,7 @@ public function call(string $method, string $path, ?array $params = null)
166166

167167
// Initialize the RouteCollection
168168
if (! $routes = $this->routes) {
169-
$routes = Services::routes();
170-
$routes->loadRoutes();
169+
$routes = Services::routes()->loadRoutes();
171170
}
172171

173172
$routes->setHTTPVerb($method);

system/Test/FilterTestTrait.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,7 @@ protected function setUpFilterTestTrait(): void
102102
$this->filters ??= new Filters($this->filtersConfig, $this->request, $this->response);
103103

104104
if ($this->collection === null) {
105-
// Load the RouteCollection from Config to gather App route info
106-
// (creates $routes using the Service as a starting point)
107-
$routes = Services::routes();
108-
$routes->loadRoutes();
109-
110-
$this->collection = $routes;
105+
$this->collection = Services::routes()->loadRoutes();
111106
}
112107

113108
$this->doneFilterSetUp = true;

system/Test/bootstrap.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,5 +92,4 @@
9292
// Always load the URL helper, it should be used in most of apps.
9393
helper('url');
9494

95-
$routes = Services::routes();
96-
$routes->loadRoutes();
95+
Services::routes()->loadRoutes();

0 commit comments

Comments
 (0)