Skip to content

Commit 4722157

Browse files
authored
Merge pull request #8981 from kenjis/change-auto-routing-improved-config
config: change default config for Auto Routing Improved
2 parents ab71e4f + f0db26f commit 4722157

File tree

21 files changed

+590
-430
lines changed

21 files changed

+590
-430
lines changed

app/Config/Feature.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
class Feature extends BaseConfig
1111
{
1212
/**
13-
* Use improved new auto routing instead of the default legacy version.
13+
* Use improved new auto routing instead of the legacy version.
1414
*/
15-
public bool $autoRoutesImproved = false;
15+
public bool $autoRoutesImproved = true;
1616

1717
/**
1818
* Use filter execution order in 4.4 or before.

app/Config/Routing.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,5 +136,5 @@ class Routing extends BaseRouting
136136
*
137137
* Default: false
138138
*/
139-
public bool $translateUriToCamelCase = false;
139+
public bool $translateUriToCamelCase = true;
140140
}

tests/system/Commands/RoutesTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use CodeIgniter\Router\RouteCollection;
1717
use CodeIgniter\Test\CIUnitTestCase;
1818
use CodeIgniter\Test\StreamFilterTrait;
19+
use Config\Feature;
1920
use Config\Services;
2021
use PHPUnit\Framework\Attributes\Group;
2122

@@ -213,6 +214,8 @@ public function testRoutesCommandRouteLegacy(): void
213214
$routes = $this->getCleanRoutes();
214215
$routes->loadRoutes();
215216

217+
$featureConfig = config(Feature::class);
218+
$featureConfig->autoRoutesImproved = false;
216219
$routes->setAutoRoute(true);
217220

218221
command('routes');

tests/system/Commands/Utilities/Routes/AutoRouterImproved/ControllerMethodReaderTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,9 @@ public function testRead(): void
7474

7575
public function testReadTranslateURIDashes(): void
7676
{
77-
$config = config(Routing::class);
78-
$config->translateURIDashes = true;
77+
$config = config(Routing::class);
78+
$config->translateURIDashes = true;
79+
$config->translateUriToCamelCase = false;
7980
Factories::injectMock('config', Routing::class, $config);
8081

8182
$reader = $this->createControllerMethodReader(

tests/system/Router/AutoRouterImprovedTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,16 @@ public function testAutoRouteFindsControllerWithSubSubfolder(): void
204204
$this->assertSame([], $params);
205205
}
206206

207+
private function disableTranslateUriToCamelCase(): void
208+
{
209+
$routingConfig = config(Routing::class);
210+
$routingConfig->translateUriToCamelCase = false;
211+
}
212+
207213
public function testAutoRouteFindsDashedSubfolder(): void
208214
{
215+
$this->disableTranslateUriToCamelCase();
216+
209217
$router = $this->createNewAutoRouter();
210218

211219
[$directory, $controller, $method, $params]
@@ -222,6 +230,8 @@ public function testAutoRouteFindsDashedSubfolder(): void
222230

223231
public function testAutoRouteFindsDashedController(): void
224232
{
233+
$this->disableTranslateUriToCamelCase();
234+
225235
$router = $this->createNewAutoRouter();
226236

227237
[$directory, $controller, $method, $params]
@@ -235,6 +245,8 @@ public function testAutoRouteFindsDashedController(): void
235245

236246
public function testAutoRouteFindsDashedMethod(): void
237247
{
248+
$this->disableTranslateUriToCamelCase();
249+
238250
$router = $this->createNewAutoRouter();
239251

240252
[$directory, $controller, $method, $params]
@@ -248,6 +260,8 @@ public function testAutoRouteFindsDashedMethod(): void
248260

249261
public function testAutoRouteFindsDefaultDashFolder(): void
250262
{
263+
$this->disableTranslateUriToCamelCase();
264+
251265
$router = $this->createNewAutoRouter();
252266

253267
[$directory, $controller, $method, $params]
@@ -438,6 +452,8 @@ public function testRejectsURIWithUnderscoreController(): void
438452
'AutoRouterImproved prohibits access to the URI containing underscores ("dash_controller")'
439453
);
440454

455+
$this->disableTranslateUriToCamelCase();
456+
441457
$router = $this->createNewAutoRouter();
442458

443459
$router->getRoute('dash-folder/dash_controller/dash-method', Method::GET);
@@ -450,6 +466,8 @@ public function testRejectsURIWithUnderscoreMethod(): void
450466
'AutoRouterImproved prohibits access to the URI containing underscores ("dash_method")'
451467
);
452468

469+
$this->disableTranslateUriToCamelCase();
470+
453471
$router = $this->createNewAutoRouter();
454472

455473
$router->getRoute('dash-folder/dash-controller/dash_method', Method::GET);

tests/system/Router/RouteCollectionTest.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use CodeIgniter\Exceptions\PageNotFoundException;
2020
use CodeIgniter\HTTP\Method;
2121
use CodeIgniter\Test\CIUnitTestCase;
22+
use Config\Feature;
2223
use Config\Modules;
2324
use Config\Routing;
2425
use PHPUnit\Framework\Attributes\DataProvider;
@@ -1768,12 +1769,12 @@ public static function provideRouteDefaultNamespace(): iterable
17681769
];
17691770
}
17701771

1771-
/**
1772-
* @param mixed $namespace
1773-
*/
17741772
#[DataProvider('provideRouteDefaultNamespace')]
1775-
public function testAutoRoutesControllerNameReturnsFQCN($namespace): void
1773+
public function testAutoRoutesControllerNameReturnsFQCN(string $namespace): void
17761774
{
1775+
$featureConfig = config(Feature::class);
1776+
$featureConfig->autoRoutesImproved = false;
1777+
17771778
$routes = $this->getCollector();
17781779
$routes->setAutoRoute(true);
17791780
$routes->setDefaultNamespace($namespace);
@@ -1788,11 +1789,8 @@ public function testAutoRoutesControllerNameReturnsFQCN($namespace): void
17881789
$this->assertSame('\\' . Product::class, $router->controllerName());
17891790
}
17901791

1791-
/**
1792-
* @param mixed $namespace
1793-
*/
17941792
#[DataProvider('provideRouteDefaultNamespace')]
1795-
public function testRoutesControllerNameReturnsFQCN($namespace): void
1793+
public function testRoutesControllerNameReturnsFQCN(string $namespace): void
17961794
{
17971795
Services::request()->setMethod(Method::GET);
17981796
$routes = $this->getCollector();

tests/system/Router/RouterTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use CodeIgniter\Router\Exceptions\RouterException;
2424
use CodeIgniter\Test\CIUnitTestCase;
2525
use Config\App;
26+
use Config\Feature;
2627
use Config\Modules;
2728
use Config\Routing;
2829
use PHPUnit\Framework\Attributes\DataProvider;
@@ -42,12 +43,19 @@ protected function setUp(): void
4243
{
4344
parent::setUp();
4445

46+
$this->disableAutoRoutesImproved();
4547
$this->createRouteCollection();
4648

4749
$this->request = Services::request();
4850
$this->request->setMethod(Method::GET);
4951
}
5052

53+
private function disableAutoRoutesImproved(): void
54+
{
55+
$featureConfig = config(Feature::class);
56+
$featureConfig->autoRoutesImproved = false;
57+
}
58+
5159
private function createRouteCollection(?Routing $routingConfig = null): void
5260
{
5361
$moduleConfig = new Modules();

tests/system/Test/FeatureTestTraitTest.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use CodeIgniter\HTTP\Response;
2121
use CodeIgniter\Test\Mock\MockCodeIgniter;
2222
use Config\App;
23+
use Config\Feature;
2324
use Config\Routing;
2425
use Config\Services;
2526
use PHPUnit\Framework\Attributes\DataProvider;
@@ -359,17 +360,19 @@ public static function provideOpenCliRoutesFromHttpGot404(): iterable
359360
];
360361
}
361362

362-
/**
363-
* @param mixed $from
364-
* @param mixed $to
365-
* @param mixed $httpGet
366-
*/
363+
private function disableAutoRoutesImproved(): void
364+
{
365+
$featureConfig = config(Feature::class);
366+
$featureConfig->autoRoutesImproved = false;
367+
}
368+
367369
#[DataProvider('provideOpenCliRoutesFromHttpGot404')]
368-
public function testOpenCliRoutesFromHttpGot404($from, $to, $httpGet): void
370+
public function testOpenCliRoutesFromHttpGot404(string $from, string $to, string $httpGet): void
369371
{
370372
$this->expectException(PageNotFoundException::class);
371373
$this->expectExceptionMessage('Cannot access CLI Route: ');
372374

375+
$this->disableAutoRoutesImproved();
373376
$collection = Services::routes();
374377
$collection->setAutoRoute(true);
375378
$collection->setDefaultNamespace('Tests\Support\Controllers');
@@ -641,6 +644,7 @@ public function testSetupRequestBodyWithBody(): void
641644

642645
public function testAutoRoutingLegacy(): void
643646
{
647+
$this->disableAutoRoutesImproved();
644648
$config = config(Routing::class);
645649
$config->autoRoute = true;
646650
Factories::injectMock('config', Routing::class, $config);

user_guide_src/source/changelogs/v4.4.0.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ Others
261261
- If a controller is found that corresponds to a URI segment and that controller
262262
does not have a method defined for the URI segment, the default method will
263263
now be executed. This addition allows for more flexible handling of URIs in
264-
auto routing. See :ref:`controller-default-method-fallback` for details.
264+
auto routing. See :ref:`auto-routing-improved-default-method-fallback` for details.
265265
- **Filters:** Now you can use Filter Arguments with :ref:`$filters property <filters-filters-filter-arguments>`.
266266
- **Request:** Added ``IncomingRequest::setValidLocales()`` method to set valid locales.
267267
- **Table:** Added ``Table::setSyncRowsWithHeading()`` method to synchronize row columns with headings. See :ref:`table-sync-rows-with-headings` for details.

user_guide_src/source/changelogs/v4.5.0.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Routing
6262

6363
- **AutoRouting Improved:** The ``$translateUriToCamelCase`` option has been added
6464
that allows using CamelCase controller and method names. See
65-
:ref:`controller-translate-uri-to-camelcase`.
65+
:ref:`translate-uri-to-camelcase`.
6666
- **Others:**
6767
- Added option ``$multipleSegmentsOneParam``. When this option is
6868
enabled, a placeholder that matches multiple segments, such as ``(:any)``, will

0 commit comments

Comments
 (0)