Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/4.5' into 4.5
Browse files Browse the repository at this point in the history
  • Loading branch information
michalsn committed Sep 17, 2023
2 parents 4fcaf2c + 2daf762 commit bc5bcac
Show file tree
Hide file tree
Showing 26 changed files with 232 additions and 167 deletions.
6 changes: 3 additions & 3 deletions app/Config/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ class Database extends Config
'DBPrefix' => '',
'pConnect' => false,
'DBDebug' => true,
'charset' => 'utf8',
'DBCollat' => 'utf8_general_ci',
'charset' => 'utf8mb4',
'DBCollat' => 'utf8mb4_general_ci',
'swapPre' => '',
'encrypt' => false,
'compress' => false,
Expand All @@ -60,7 +60,7 @@ class Database extends Config
'pConnect' => false,
'DBDebug' => true,
'charset' => 'utf8',
'DBCollat' => 'utf8_general_ci',
'DBCollat' => '',
'swapPre' => '',
'encrypt' => false,
'compress' => false,
Expand Down
14 changes: 0 additions & 14 deletions app/Config/Feature.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,6 @@
*/
class Feature extends BaseConfig
{
/**
* Enable multiple filters for a route or not.
*
* If you enable this:
* - CodeIgniter\CodeIgniter::handleRequest() uses:
* - CodeIgniter\Filters\Filters::enableFilters(), instead of enableFilter()
* - CodeIgniter\CodeIgniter::tryToRouteIt() uses:
* - CodeIgniter\Router\Router::getFilters(), instead of getFilter()
* - CodeIgniter\Router\Router::handle() uses:
* - property $filtersInfo, instead of $filterInfo
* - CodeIgniter\Router\RouteCollection::getFiltersForRoute(), instead of getFilterForRoute()
*/
public bool $multipleFilters = false;

/**
* Use improved new auto routing instead of the default legacy version.
*/
Expand Down
5 changes: 0 additions & 5 deletions phpstan-baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -2346,11 +2346,6 @@
'count' => 2,
'path' => __DIR__ . '/system/Router/Router.php',
];
$ignoreErrors[] = [
'message' => '#^Call to an undefined method CodeIgniter\\\\Router\\\\RouteCollectionInterface\\:\\:getFilterForRoute\\(\\)\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Router/Router.php',
];
$ignoreErrors[] = [
'message' => '#^Call to an undefined method CodeIgniter\\\\Router\\\\RouteCollectionInterface\\:\\:getFiltersForRoute\\(\\)\\.$#',
'count' => 1,
Expand Down
18 changes: 2 additions & 16 deletions system/CodeIgniter.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
use CodeIgniter\Router\Router;
use Config\App;
use Config\Cache;
use Config\Feature;
use Config\Kint as KintConfig;
use Config\Services;
use Exception;
Expand Down Expand Up @@ -452,15 +451,8 @@ protected function handleRequest(?RouteCollectionInterface $routes, Cache $cache
// If any filters were specified within the routes file,
// we need to ensure it's active for the current request
if ($routeFilter !== null) {
$multipleFiltersEnabled = config(Feature::class)->multipleFilters ?? false;
if ($multipleFiltersEnabled) {
$filters->enableFilters($routeFilter, 'before');
$filters->enableFilters($routeFilter, 'after');
} else {
// for backward compatibility
$filters->enableFilter($routeFilter, 'before');
$filters->enableFilter($routeFilter, 'after');
}
$filters->enableFilters($routeFilter, 'before');
$filters->enableFilters($routeFilter, 'after');
}

// Run "before" filters
Expand Down Expand Up @@ -810,12 +802,6 @@ protected function tryToRouteIt(?RouteCollectionInterface $routes = null)

$this->benchmark->stop('routing');

// for backward compatibility
$multipleFiltersEnabled = config(Feature::class)->multipleFilters ?? false;
if (! $multipleFiltersEnabled) {
return $this->router->getFilter();
}

return $this->router->getFilters();
}

Expand Down
8 changes: 0 additions & 8 deletions system/Commands/Utilities/Routes/FilterFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use CodeIgniter\Filters\Filters;
use CodeIgniter\HTTP\Exceptions\RedirectException;
use CodeIgniter\Router\Router;
use Config\Feature;
use Config\Services;

/**
Expand All @@ -38,13 +37,6 @@ private function getRouteFilters(string $uri): array
{
$this->router->handle($uri);

$multipleFiltersEnabled = config(Feature::class)->multipleFilters ?? false;
if (! $multipleFiltersEnabled) {
$filter = $this->router->getFilter();

return $filter === null ? [] : [$filter];
}

return $this->router->getFilters();
}

Expand Down
8 changes: 6 additions & 2 deletions system/Database/BaseConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,16 +136,20 @@ abstract class BaseConnection implements ConnectionInterface
/**
* Character set
*
* This value must be updated by Config\Database if the driver use it.
*
* @var string
*/
protected $charset = 'utf8';
protected $charset = 'utf8mb4';

/**
* Collation
*
* This value must be updated by Config\Database if the driver use it.
*
* @var string
*/
protected $DBCollat = 'utf8_general_ci';
protected $DBCollat = 'utf8mb4_general_ci';

/**
* Swap Prefix
Expand Down
8 changes: 1 addition & 7 deletions system/Filters/Filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -335,12 +335,8 @@ public function addFilter(string $class, ?string $alias = null, string $when = '
* are passed to the filter when executed.
*
* @param string $name filter_name or filter_name:arguments like 'role:admin,manager'
*
* @return $this
*
* @deprecated Use enableFilters(). This method will be private.
*/
public function enableFilter(string $name, string $when = 'before')
private function enableFilter(string $name, string $when = 'before'): void
{
// Get arguments and clean name
[$name, $arguments] = $this->getCleanName($name);
Expand All @@ -362,8 +358,6 @@ public function enableFilter(string $name, string $when = 'before')
$this->filters[$when][] = $name;
$this->filtersClass[$when] = array_merge($this->filtersClass[$when], $classNames);
}

return $this;
}

/**
Expand Down
19 changes: 0 additions & 19 deletions system/Router/RouteCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -1228,25 +1228,6 @@ public function isFiltered(string $search, ?string $verb = null): bool
return isset($options[$search]['filter']);
}

/**
* Returns the filter that should be applied for a single route, along
* with any parameters it might have. Parameters are found by splitting
* the parameter name on a colon to separate the filter name from the parameter list,
* and the splitting the result on commas. So:
*
* 'role:admin,manager'
*
* has a filter of "role", with parameters of ['admin', 'manager'].
*
* @deprecated Use getFiltersForRoute()
*/
public function getFilterForRoute(string $search, ?string $verb = null): string
{
$options = $this->loadRoutesOptions($verb);

return $options[$search]['filter'] ?? '';
}

/**
* Returns the filters that should be applied for a single route, along
* with any parameters it might have. Parameters are found by splitting
Expand Down
31 changes: 1 addition & 30 deletions system/Router/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,6 @@ class Router implements RouterInterface
*/
protected $detectedLocale;

/**
* The filter info from Route Collection
* if the matched route should be filtered.
*
* @var string|null
*
* @deprecated Use $filtersInfo
*/
protected $filterInfo;

/**
* The filter info from Route Collection
* if the matched route should be filtered.
Expand Down Expand Up @@ -179,19 +169,12 @@ public function handle(?string $uri = null)
$uri = urldecode($uri);

// Restart filterInfo
$this->filterInfo = null;
$this->filtersInfo = [];

// Checks defined routes
if ($this->checkRoutes($uri)) {
if ($this->collection->isFiltered($this->matchedRoute[0])) {
$multipleFiltersEnabled = config(Feature::class)->multipleFilters ?? false;
if ($multipleFiltersEnabled) {
$this->filtersInfo = $this->collection->getFiltersForRoute($this->matchedRoute[0]);
} else {
// for backward compatibility
$this->filterInfo = $this->collection->getFilterForRoute($this->matchedRoute[0]);
}
$this->filtersInfo = $this->collection->getFiltersForRoute($this->matchedRoute[0]);
}

return $this->controller;
Expand All @@ -212,18 +195,6 @@ public function handle(?string $uri = null)
return $this->controllerName();
}

/**
* Returns the filter info for the matched route, if any.
*
* @return string|null
*
* @deprecated Use getFilters()
*/
public function getFilter()
{
return $this->filterInfo;
}

/**
* Returns the filter info for the matched route, if any.
*
Expand Down
12 changes: 6 additions & 6 deletions tests/_support/Config/Registrar.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ class Registrar
'DBPrefix' => 'db_',
'pConnect' => false,
'DBDebug' => true,
'charset' => 'utf8',
'DBCollat' => 'utf8_general_ci',
'charset' => 'utf8mb4',
'DBCollat' => 'utf8mb4_general_ci',
'swapPre' => '',
'encrypt' => false,
'compress' => false,
Expand All @@ -54,7 +54,7 @@ class Registrar
'pConnect' => false,
'DBDebug' => true,
'charset' => 'utf8',
'DBCollat' => 'utf8_general_ci',
'DBCollat' => '',
'swapPre' => '',
'encrypt' => false,
'compress' => false,
Expand All @@ -73,7 +73,7 @@ class Registrar
'pConnect' => false,
'DBDebug' => true,
'charset' => 'utf8',
'DBCollat' => 'utf8_general_ci',
'DBCollat' => '',
'swapPre' => '',
'encrypt' => false,
'compress' => false,
Expand All @@ -93,7 +93,7 @@ class Registrar
'pConnect' => false,
'DBDebug' => true,
'charset' => 'utf8',
'DBCollat' => 'utf8_general_ci',
'DBCollat' => '',
'swapPre' => '',
'encrypt' => false,
'compress' => false,
Expand All @@ -112,7 +112,7 @@ class Registrar
'pConnect' => false,
'DBDebug' => true,
'charset' => 'AL32UTF8',
'DBCollat' => 'utf8_general_ci',
'DBCollat' => '',
'swapPre' => '',
'encrypt' => false,
'compress' => false,
Expand Down
4 changes: 0 additions & 4 deletions tests/system/Commands/Utilities/Routes/FilterFinderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,6 @@ public function testFindGlobalsAndRouteClassnameFilters(): void

public function testFindGlobalsAndRouteMultipleFilters(): void
{
config('Feature')->multipleFilters = true;

$collection = $this->createRouteCollection();
$collection->get('admin', ' AdminController::index', ['filter' => ['honeypot', InvalidChars::class]]);
$router = $this->createRouter($collection);
Expand All @@ -187,7 +185,5 @@ public function testFindGlobalsAndRouteMultipleFilters(): void
'after' => ['honeypot', InvalidChars::class, 'toolbar'],
];
$this->assertSame($expected, $filters);

config('Feature')->multipleFilters = false;
}
}
14 changes: 7 additions & 7 deletions tests/system/Database/BaseConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ final class BaseConnectionTest extends CIUnitTestCase
'DBPrefix' => 'test_',
'pConnect' => true,
'DBDebug' => true,
'charset' => 'utf8',
'DBCollat' => 'utf8_general_ci',
'charset' => 'utf8mb4',
'DBCollat' => 'utf8mb4_general_ci',
'swapPre' => '',
'encrypt' => false,
'compress' => false,
Expand All @@ -51,8 +51,8 @@ final class BaseConnectionTest extends CIUnitTestCase
'DBPrefix' => 'test_',
'pConnect' => true,
'DBDebug' => true,
'charset' => 'utf8',
'DBCollat' => 'utf8_general_ci',
'charset' => 'utf8mb4',
'DBCollat' => 'utf8mb4_general_ci',
'swapPre' => '',
'encrypt' => false,
'compress' => false,
Expand All @@ -71,8 +71,8 @@ public function testSavesConfigOptions(): void
$this->assertSame('MockDriver', $db->DBDriver);
$this->assertTrue($db->pConnect);
$this->assertTrue($db->DBDebug);
$this->assertSame('utf8', $db->charset);
$this->assertSame('utf8_general_ci', $db->DBCollat);
$this->assertSame('utf8mb4', $db->charset);
$this->assertSame('utf8mb4_general_ci', $db->DBCollat);
$this->assertSame('', $db->swapPre);
$this->assertFalse($db->encrypt);
$this->assertFalse($db->compress);
Expand Down Expand Up @@ -153,7 +153,7 @@ public function testMagicGet(): void
{
$db = new MockConnection($this->options);

$this->assertSame('utf8', $db->charset);
$this->assertSame('utf8mb4', $db->charset);
}

public function testMagicGetMissing(): void
Expand Down
Loading

0 comments on commit bc5bcac

Please sign in to comment.