Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

config: change default config for Auto Routing Improved #8981

Merged
merged 27 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
ecfc323
test: define param types
kenjis Jun 21, 2024
ab49378
config: change default config for Auto Routing Improved
kenjis Jun 21, 2024
5d139c3
docs: create new page auto_routing_improved.rst
kenjis Jun 21, 2024
e51627a
docs: move contents in controllers.rst to auto_routing_improved.rst
kenjis Jun 21, 2024
7ce5484
docs: fix section title marks
kenjis Jun 21, 2024
51607f8
docs: add section title "What is Auto Routing (Improved) ?" and rewrite
kenjis Jun 21, 2024
38d8f72
docs: add sectioin "Differences from Auto Routing (Legacy)"
kenjis Jun 21, 2024
27b420c
docs: change section title
kenjis Jun 21, 2024
2e3bf1d
docs: rewrite "Auto Routing (Improved)" contents
kenjis Jun 21, 2024
af227b8
test: update test code for config changes
kenjis Jun 21, 2024
dd33f98
docs: add note
kenjis Jun 23, 2024
580a59b
docs: add "Examples of Controller/Methods and URIs"
kenjis Jun 23, 2024
fd00dfa
docs: update :ref: ids
kenjis Jun 23, 2024
ecfbc2f
docs: add notes
kenjis Jun 23, 2024
23ae69c
docs: add upgrade_460
kenjis Jun 24, 2024
50baedd
docs: change note
kenjis Jun 24, 2024
c481d2e
docs: improved descriptions
kenjis Jun 24, 2024
c953a68
docs: remove `index.php` in sample URLs
kenjis Jun 24, 2024
c267bc0
docs: improve explanation
kenjis Jun 24, 2024
02e645c
docs: add sub section titles and explanations
kenjis Jun 24, 2024
75861b0
docs: add section "Check the Routes"
kenjis Jun 24, 2024
939766e
docs: add `http://` to example URLs
kenjis Jun 24, 2024
990e89e
docs: fix FQCN
kenjis Jun 24, 2024
70ebb33
docs: improve section titles
kenjis Jun 24, 2024
9494c40
docs: replace "This is"
kenjis Jun 25, 2024
0ad823c
docs: fix description
kenjis Jun 25, 2024
f0db26f
docs: add section "Applying Filters"
kenjis Jun 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/Config/Feature.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
class Feature extends BaseConfig
{
/**
* Use improved new auto routing instead of the default legacy version.
* Use improved new auto routing instead of the legacy version.
*/
public bool $autoRoutesImproved = false;
public bool $autoRoutesImproved = true;

/**
* Use filter execution order in 4.4 or before.
Expand Down
2 changes: 1 addition & 1 deletion app/Config/Routing.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,5 +136,5 @@ class Routing extends BaseRouting
*
* Default: false
*/
public bool $translateUriToCamelCase = false;
public bool $translateUriToCamelCase = true;
}
3 changes: 3 additions & 0 deletions tests/system/Commands/RoutesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use CodeIgniter\Router\RouteCollection;
use CodeIgniter\Test\CIUnitTestCase;
use CodeIgniter\Test\StreamFilterTrait;
use Config\Feature;
use Config\Services;
use PHPUnit\Framework\Attributes\Group;

Expand Down Expand Up @@ -213,6 +214,8 @@ public function testRoutesCommandRouteLegacy(): void
$routes = $this->getCleanRoutes();
$routes->loadRoutes();

$featureConfig = config(Feature::class);
$featureConfig->autoRoutesImproved = false;
$routes->setAutoRoute(true);

command('routes');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ public function testRead(): void

public function testReadTranslateURIDashes(): void
{
$config = config(Routing::class);
$config->translateURIDashes = true;
$config = config(Routing::class);
$config->translateURIDashes = true;
$config->translateUriToCamelCase = false;
Factories::injectMock('config', Routing::class, $config);

$reader = $this->createControllerMethodReader(
Expand Down
18 changes: 18 additions & 0 deletions tests/system/Router/AutoRouterImprovedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,16 @@ public function testAutoRouteFindsControllerWithSubSubfolder(): void
$this->assertSame([], $params);
}

private function disableTranslateUriToCamelCase(): void
{
$routingConfig = config(Routing::class);
$routingConfig->translateUriToCamelCase = false;
}

public function testAutoRouteFindsDashedSubfolder(): void
{
$this->disableTranslateUriToCamelCase();

$router = $this->createNewAutoRouter();

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

public function testAutoRouteFindsDashedController(): void
{
$this->disableTranslateUriToCamelCase();

$router = $this->createNewAutoRouter();

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

public function testAutoRouteFindsDashedMethod(): void
{
$this->disableTranslateUriToCamelCase();

$router = $this->createNewAutoRouter();

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

public function testAutoRouteFindsDefaultDashFolder(): void
{
$this->disableTranslateUriToCamelCase();

$router = $this->createNewAutoRouter();

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

$this->disableTranslateUriToCamelCase();

$router = $this->createNewAutoRouter();

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

$this->disableTranslateUriToCamelCase();

$router = $this->createNewAutoRouter();

$router->getRoute('dash-folder/dash-controller/dash_method', Method::GET);
Expand Down
14 changes: 6 additions & 8 deletions tests/system/Router/RouteCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use CodeIgniter\Exceptions\PageNotFoundException;
use CodeIgniter\HTTP\Method;
use CodeIgniter\Test\CIUnitTestCase;
use Config\Feature;
use Config\Modules;
use Config\Routing;
use PHPUnit\Framework\Attributes\DataProvider;
Expand Down Expand Up @@ -1768,12 +1769,12 @@ public static function provideRouteDefaultNamespace(): iterable
];
}

/**
* @param mixed $namespace
*/
#[DataProvider('provideRouteDefaultNamespace')]
public function testAutoRoutesControllerNameReturnsFQCN($namespace): void
public function testAutoRoutesControllerNameReturnsFQCN(string $namespace): void
{
$featureConfig = config(Feature::class);
$featureConfig->autoRoutesImproved = false;

$routes = $this->getCollector();
$routes->setAutoRoute(true);
$routes->setDefaultNamespace($namespace);
Expand All @@ -1788,11 +1789,8 @@ public function testAutoRoutesControllerNameReturnsFQCN($namespace): void
$this->assertSame('\\' . Product::class, $router->controllerName());
}

/**
* @param mixed $namespace
*/
#[DataProvider('provideRouteDefaultNamespace')]
public function testRoutesControllerNameReturnsFQCN($namespace): void
public function testRoutesControllerNameReturnsFQCN(string $namespace): void
{
Services::request()->setMethod(Method::GET);
$routes = $this->getCollector();
Expand Down
8 changes: 8 additions & 0 deletions tests/system/Router/RouterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use CodeIgniter\Router\Exceptions\RouterException;
use CodeIgniter\Test\CIUnitTestCase;
use Config\App;
use Config\Feature;
use Config\Modules;
use Config\Routing;
use PHPUnit\Framework\Attributes\DataProvider;
Expand All @@ -42,12 +43,19 @@ protected function setUp(): void
{
parent::setUp();

$this->disableAutoRoutesImproved();
$this->createRouteCollection();

$this->request = Services::request();
$this->request->setMethod(Method::GET);
}

private function disableAutoRoutesImproved(): void
{
$featureConfig = config(Feature::class);
$featureConfig->autoRoutesImproved = false;
}

private function createRouteCollection(?Routing $routingConfig = null): void
{
$moduleConfig = new Modules();
Expand Down
16 changes: 10 additions & 6 deletions tests/system/Test/FeatureTestTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use CodeIgniter\HTTP\Response;
use CodeIgniter\Test\Mock\MockCodeIgniter;
use Config\App;
use Config\Feature;
use Config\Routing;
use Config\Services;
use PHPUnit\Framework\Attributes\DataProvider;
Expand Down Expand Up @@ -359,17 +360,19 @@ public static function provideOpenCliRoutesFromHttpGot404(): iterable
];
}

/**
* @param mixed $from
* @param mixed $to
* @param mixed $httpGet
*/
private function disableAutoRoutesImproved(): void
{
$featureConfig = config(Feature::class);
$featureConfig->autoRoutesImproved = false;
}

#[DataProvider('provideOpenCliRoutesFromHttpGot404')]
public function testOpenCliRoutesFromHttpGot404($from, $to, $httpGet): void
public function testOpenCliRoutesFromHttpGot404(string $from, string $to, string $httpGet): void
{
$this->expectException(PageNotFoundException::class);
$this->expectExceptionMessage('Cannot access CLI Route: ');

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

public function testAutoRoutingLegacy(): void
{
$this->disableAutoRoutesImproved();
$config = config(Routing::class);
$config->autoRoute = true;
Factories::injectMock('config', Routing::class, $config);
Expand Down
2 changes: 1 addition & 1 deletion user_guide_src/source/changelogs/v4.4.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ Others
- If a controller is found that corresponds to a URI segment and that controller
does not have a method defined for the URI segment, the default method will
now be executed. This addition allows for more flexible handling of URIs in
auto routing. See :ref:`controller-default-method-fallback` for details.
auto routing. See :ref:`auto-routing-improved-default-method-fallback` for details.
- **Filters:** Now you can use Filter Arguments with :ref:`$filters property <filters-filters-filter-arguments>`.
- **Request:** Added ``IncomingRequest::setValidLocales()`` method to set valid locales.
- **Table:** Added ``Table::setSyncRowsWithHeading()`` method to synchronize row columns with headings. See :ref:`table-sync-rows-with-headings` for details.
Expand Down
2 changes: 1 addition & 1 deletion user_guide_src/source/changelogs/v4.5.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Routing

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