Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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 system/Router/RouteCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -656,8 +656,8 @@ public function getRedirectCode(string $routeKey): int
* $route->resource('users');
* });
*
* @param string $name The name to group/prefix the routes with.
* @param array<string, mixed>|(callable(self): void) ...$params
* @param string $name The name to group/prefix the routes with.
* @param array<string, mixed>|(callable(static): void) ...$params
*
* @return void
*/
Expand Down
20 changes: 20 additions & 0 deletions tests/_support/Router/RouteCollectionSubclass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

/**
* This file is part of CodeIgniter 4 framework.
*
* (c) CodeIgniter Foundation <admin@codeigniter.com>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/

namespace Tests\Support\Router;

use CodeIgniter\Router\RouteCollection;

final class RouteCollectionSubclass extends RouteCollection
{
}
33 changes: 33 additions & 0 deletions tests/system/Router/RouteCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Group;
use Tests\Support\Controllers\Hello;
use Tests\Support\Router\RouteCollectionSubclass;

/**
* @internal
Expand Down Expand Up @@ -314,6 +315,38 @@ static function ($routes): void {
$this->assertSame($expected, $routes->getRoutes());
}

public function testGroupingPassesSubclassToNestedCallbacks(): void
{
$modules = new Modules();
$modules->enabled = false;
$config = new Routing();
$config->defaultNamespace = '\\';
$routes = new RouteCollectionSubclass(service('locator'), $modules, $config);
$routes->setHTTPVerb(Method::GET);

$routes->group('admin', ['namespace' => 'Admin', 'filter' => ['csrf']], function (RouteCollectionSubclass $group) use ($routes): void {
$this->assertSame($routes, $group);

$group->group('profile', ['filter' => ['honeypot']], function (RouteCollectionSubclass $nested) use ($routes): void {
$this->assertSame($routes, $nested);
$nested->get('show', 'Profile::show');
});

$group->get('dashboard', 'Dashboard::index');
});

$routes->get('home', 'Home::index');

$this->assertSame([
'admin/profile/show' => '\\Admin\\Profile::show',
'admin/dashboard' => '\\Admin\\Dashboard::index',
'home' => '\\Home::index',
], $routes->getRoutes(Method::GET));
$this->assertSame(['csrf', 'honeypot'], $routes->getFiltersForRoute('admin/profile/show'));
$this->assertSame(['csrf'], $routes->getFiltersForRoute('admin/dashboard'));
$this->assertFalse($routes->isFiltered('home'));
}

public function testGroupGetsSanitized(): void
{
$routes = $this->getCollector();
Expand Down
3 changes: 3 additions & 0 deletions user_guide_src/source/changelogs/v4.7.6.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ Bugs Fixed
**********

- **Commands:** Fixed a bug where generator commands did not sort the imports of a template with CRLF line endings.
- **Routing:** Corrected the PHPDoc callback type of ``RouteCollection::group()``

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Align this alphabetically.

to preserve the concrete collection type, allowing callbacks typed to a
``RouteCollection`` subclass to pass static analysis.
- **Format:** Fixed ``XMLFormatter`` so that an array key that becomes empty after
sanitization no longer triggers a ``ValueError``; the fallback tag name ``item``
is used instead. Values that cannot be converted to a string, such as objects
Expand Down
Loading