Skip to content

Commit 3bb0831

Browse files
authored
Merge pull request #7611 from kenjis/refactor-config-classname
refactor: use ::class to config() param
2 parents c9b6f3d + 3bdb53f commit 3bb0831

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+136
-108
lines changed

system/CLI/BaseCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace CodeIgniter\CLI;
1313

14+
use Config\Exceptions;
1415
use Psr\Log\LoggerInterface;
1516
use ReflectionException;
1617
use Throwable;
@@ -121,7 +122,7 @@ protected function showError(Throwable $e)
121122
{
122123
$exception = $e;
123124
$message = $e->getMessage();
124-
$config = config('Exceptions');
125+
$config = config(Exceptions::class);
125126

126127
require $config->errorViewPath . '/cli/error_exception.php';
127128
}

system/CLI/GeneratorTrait.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace CodeIgniter\CLI;
1313

14+
use Config\Generators;
1415
use Config\Services;
1516
use Throwable;
1617

@@ -267,7 +268,7 @@ protected function qualifyClassName(): string
267268
protected function renderTemplate(array $data = []): string
268269
{
269270
try {
270-
return view(config('Generators')->views[$this->name], $data, ['debug' => false]);
271+
return view(config(Generators::class)->views[$this->name], $data, ['debug' => false]);
271272
} catch (Throwable $e) {
272273
log_message('error', (string) $e);
273274

system/Cache/Handlers/BaseHandler.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Closure;
1515
use CodeIgniter\Cache\CacheInterface;
16+
use Config\Cache;
1617
use Exception;
1718
use InvalidArgumentException;
1819

@@ -61,7 +62,7 @@ public static function validateKey($key, $prefix = ''): string
6162
throw new InvalidArgumentException('Cache key cannot be empty.');
6263
}
6364

64-
$reserved = config('Cache')->reservedCharacters ?? self::RESERVED_CHARACTERS;
65+
$reserved = config(Cache::class)->reservedCharacters ?? self::RESERVED_CHARACTERS;
6566
if ($reserved && strpbrk($key, $reserved) !== false) {
6667
throw new InvalidArgumentException('Cache key contains reserved characters ' . $reserved);
6768
}

system/CodeIgniter.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
use CodeIgniter\Router\Router;
2929
use Config\App;
3030
use Config\Cache;
31+
use Config\Feature;
3132
use Config\Kint as KintConfig;
3233
use Config\Services;
3334
use Exception;
@@ -268,7 +269,6 @@ private function autoloadKint(): void
268269

269270
private function configureKint(): void
270271
{
271-
/** @var \Config\Kint $config */
272272
$config = config(KintConfig::class);
273273

274274
Kint::$depth_limit = $config->maxDepth;
@@ -455,7 +455,7 @@ protected function handleRequest(?RouteCollectionInterface $routes, Cache $cache
455455
// If any filters were specified within the routes file,
456456
// we need to ensure it's active for the current request
457457
if ($routeFilter !== null) {
458-
$multipleFiltersEnabled = config('Feature')->multipleFilters ?? false;
458+
$multipleFiltersEnabled = config(Feature::class)->multipleFilters ?? false;
459459
if ($multipleFiltersEnabled) {
460460
$filters->enableFilters($routeFilter, 'before');
461461
$filters->enableFilters($routeFilter, 'after');
@@ -822,7 +822,7 @@ protected function tryToRouteIt(?RouteCollectionInterface $routes = null)
822822
$this->benchmark->stop('routing');
823823

824824
// for backward compatibility
825-
$multipleFiltersEnabled = config('Feature')->multipleFilters ?? false;
825+
$multipleFiltersEnabled = config(Feature::class)->multipleFilters ?? false;
826826
if (! $multipleFiltersEnabled) {
827827
return $this->router->getFilter();
828828
}

system/Commands/Cache/ClearCache.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use CodeIgniter\Cache\CacheFactory;
1515
use CodeIgniter\CLI\BaseCommand;
1616
use CodeIgniter\CLI\CLI;
17+
use Config\Cache;
1718

1819
/**
1920
* Clears current cache.
@@ -62,7 +63,7 @@ class ClearCache extends BaseCommand
6263
*/
6364
public function run(array $params)
6465
{
65-
$config = config('Cache');
66+
$config = config(Cache::class);
6667
$handler = $params[0] ?? $config->handler;
6768

6869
if (! array_key_exists($handler, $config->validHandlers)) {

system/Commands/Cache/InfoCache.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use CodeIgniter\CLI\BaseCommand;
1616
use CodeIgniter\CLI\CLI;
1717
use CodeIgniter\I18n\Time;
18+
use Config\Cache;
1819

1920
/**
2021
* Shows information on the cache.
@@ -54,7 +55,7 @@ class InfoCache extends BaseCommand
5455
*/
5556
public function run(array $params)
5657
{
57-
$config = config('Cache');
58+
$config = config(Cache::class);
5859
helper('number');
5960

6061
if ($config->handler !== 'file') {

system/Commands/Database/CreateDatabase.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,7 @@ public function run(array $params)
8282
}
8383

8484
try {
85-
/**
86-
* @var Database $config
87-
*/
88-
$config = config('Database');
85+
$config = config(Database::class);
8986

9087
// Set to an empty database to prevent connection errors.
9188
$group = ENVIRONMENT === 'testing' ? 'tests' : $config->defaultGroup;

system/Commands/Generators/MigrationGenerator.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
use CodeIgniter\CLI\CLI;
1616
use CodeIgniter\CLI\GeneratorTrait;
1717
use Config\App as AppConfig;
18+
use Config\Database;
19+
use Config\Migrations;
1820
use Config\Session as SessionConfig;
1921

2022
/**
@@ -107,12 +109,11 @@ protected function prepare(string $class): string
107109
$data['session'] = true;
108110
$data['table'] = is_string($table) ? $table : 'ci_sessions';
109111
$data['DBGroup'] = is_string($DBGroup) ? $DBGroup : 'default';
110-
$data['DBDriver'] = config('Database')->{$data['DBGroup']}['DBDriver'];
112+
$data['DBDriver'] = config(Database::class)->{$data['DBGroup']}['DBDriver'];
111113

112-
/** @var AppConfig $config */
113-
$config = config('App');
114+
$config = config(AppConfig::class);
114115
/** @var SessionConfig|null $session */
115-
$session = config('Session');
116+
$session = config(SessionConfig::class);
116117

117118
$data['matchIP'] = ($session instanceof SessionConfig)
118119
? $session->matchIP : $config->sessionMatchIP;
@@ -126,6 +127,6 @@ protected function prepare(string $class): string
126127
*/
127128
protected function basename(string $filename): string
128129
{
129-
return gmdate(config('Migrations')->timestampFormat) . basename($filename);
130+
return gmdate(config(Migrations::class)->timestampFormat) . basename($filename);
130131
}
131132
}

system/Commands/Generators/SessionMigrationGenerator.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
use CodeIgniter\CLI\BaseCommand;
1515
use CodeIgniter\CLI\CLI;
1616
use CodeIgniter\CLI\GeneratorTrait;
17+
use Config\App;
18+
use Config\Migrations;
1719

1820
/**
1921
* Generates a migration file for database sessions.
@@ -93,7 +95,7 @@ protected function prepare(string $class): string
9395
$data['session'] = true;
9496
$data['table'] = $this->getOption('t');
9597
$data['DBGroup'] = $this->getOption('g');
96-
$data['matchIP'] = config('App')->sessionMatchIP ?? false;
98+
$data['matchIP'] = config(App::class)->sessionMatchIP ?? false;
9799

98100
$data['table'] = is_string($data['table']) ? $data['table'] : 'ci_sessions';
99101
$data['DBGroup'] = is_string($data['DBGroup']) ? $data['DBGroup'] : 'default';
@@ -106,6 +108,6 @@ protected function prepare(string $class): string
106108
*/
107109
protected function basename(string $filename): string
108110
{
109-
return gmdate(config('Migrations')->timestampFormat) . basename($filename);
111+
return gmdate(config(Migrations::class)->timestampFormat) . basename($filename);
110112
}
111113
}

system/Commands/Utilities/Routes.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use CodeIgniter\Commands\Utilities\Routes\AutoRouterImproved\AutoRouteCollector as AutoRouteCollectorImproved;
1919
use CodeIgniter\Commands\Utilities\Routes\FilterCollector;
2020
use CodeIgniter\Commands\Utilities\Routes\SampleURIGenerator;
21+
use Config\Feature;
2122
use Config\Services;
2223

2324
/**
@@ -124,7 +125,7 @@ public function run(array $params)
124125
}
125126

126127
if ($collection->shouldAutoRoute()) {
127-
$autoRoutesImproved = config('Feature')->autoRoutesImproved ?? false;
128+
$autoRoutesImproved = config(Feature::class)->autoRoutesImproved ?? false;
128129

129130
if ($autoRoutesImproved) {
130131
$autoRouteCollector = new AutoRouteCollectorImproved(

0 commit comments

Comments
 (0)