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

refactor: use ::class to config() param #7611

Merged
merged 1 commit into from
Jun 26, 2023
Merged
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
3 changes: 2 additions & 1 deletion system/CLI/BaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace CodeIgniter\CLI;

use Config\Exceptions;
use Psr\Log\LoggerInterface;
use ReflectionException;
use Throwable;
Expand Down Expand Up @@ -121,7 +122,7 @@ protected function showError(Throwable $e)
{
$exception = $e;
$message = $e->getMessage();
$config = config('Exceptions');
$config = config(Exceptions::class);

require $config->errorViewPath . '/cli/error_exception.php';
}
Expand Down
3 changes: 2 additions & 1 deletion system/CLI/GeneratorTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace CodeIgniter\CLI;

use Config\Generators;
use Config\Services;
use Throwable;

Expand Down Expand Up @@ -267,7 +268,7 @@ protected function qualifyClassName(): string
protected function renderTemplate(array $data = []): string
{
try {
return view(config('Generators')->views[$this->name], $data, ['debug' => false]);
return view(config(Generators::class)->views[$this->name], $data, ['debug' => false]);
} catch (Throwable $e) {
log_message('error', (string) $e);

Expand Down
3 changes: 2 additions & 1 deletion system/Cache/Handlers/BaseHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Closure;
use CodeIgniter\Cache\CacheInterface;
use Config\Cache;
use Exception;
use InvalidArgumentException;

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

$reserved = config('Cache')->reservedCharacters ?? self::RESERVED_CHARACTERS;
$reserved = config(Cache::class)->reservedCharacters ?? self::RESERVED_CHARACTERS;
if ($reserved && strpbrk($key, $reserved) !== false) {
throw new InvalidArgumentException('Cache key contains reserved characters ' . $reserved);
}
Expand Down
6 changes: 3 additions & 3 deletions system/CodeIgniter.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
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 @@ -268,7 +269,6 @@ private function autoloadKint(): void

private function configureKint(): void
{
/** @var \Config\Kint $config */
$config = config(KintConfig::class);

Kint::$depth_limit = $config->maxDepth;
Expand Down Expand Up @@ -455,7 +455,7 @@ 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')->multipleFilters ?? false;
$multipleFiltersEnabled = config(Feature::class)->multipleFilters ?? false;
if ($multipleFiltersEnabled) {
$filters->enableFilters($routeFilter, 'before');
$filters->enableFilters($routeFilter, 'after');
Expand Down Expand Up @@ -822,7 +822,7 @@ protected function tryToRouteIt(?RouteCollectionInterface $routes = null)
$this->benchmark->stop('routing');

// for backward compatibility
$multipleFiltersEnabled = config('Feature')->multipleFilters ?? false;
$multipleFiltersEnabled = config(Feature::class)->multipleFilters ?? false;
if (! $multipleFiltersEnabled) {
return $this->router->getFilter();
}
Expand Down
3 changes: 2 additions & 1 deletion system/Commands/Cache/ClearCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use CodeIgniter\Cache\CacheFactory;
use CodeIgniter\CLI\BaseCommand;
use CodeIgniter\CLI\CLI;
use Config\Cache;

/**
* Clears current cache.
Expand Down Expand Up @@ -62,7 +63,7 @@ class ClearCache extends BaseCommand
*/
public function run(array $params)
{
$config = config('Cache');
$config = config(Cache::class);
$handler = $params[0] ?? $config->handler;

if (! array_key_exists($handler, $config->validHandlers)) {
Expand Down
3 changes: 2 additions & 1 deletion system/Commands/Cache/InfoCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use CodeIgniter\CLI\BaseCommand;
use CodeIgniter\CLI\CLI;
use CodeIgniter\I18n\Time;
use Config\Cache;

/**
* Shows information on the cache.
Expand Down Expand Up @@ -54,7 +55,7 @@ class InfoCache extends BaseCommand
*/
public function run(array $params)
{
$config = config('Cache');
$config = config(Cache::class);
helper('number');

if ($config->handler !== 'file') {
Expand Down
5 changes: 1 addition & 4 deletions system/Commands/Database/CreateDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,7 @@ public function run(array $params)
}

try {
/**
* @var Database $config
*/
$config = config('Database');
$config = config(Database::class);

// Set to an empty database to prevent connection errors.
$group = ENVIRONMENT === 'testing' ? 'tests' : $config->defaultGroup;
Expand Down
11 changes: 6 additions & 5 deletions system/Commands/Generators/MigrationGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
use CodeIgniter\CLI\CLI;
use CodeIgniter\CLI\GeneratorTrait;
use Config\App as AppConfig;
use Config\Database;
use Config\Migrations;
use Config\Session as SessionConfig;

/**
Expand Down Expand Up @@ -107,12 +109,11 @@ protected function prepare(string $class): string
$data['session'] = true;
$data['table'] = is_string($table) ? $table : 'ci_sessions';
$data['DBGroup'] = is_string($DBGroup) ? $DBGroup : 'default';
$data['DBDriver'] = config('Database')->{$data['DBGroup']}['DBDriver'];
$data['DBDriver'] = config(Database::class)->{$data['DBGroup']}['DBDriver'];

/** @var AppConfig $config */
$config = config('App');
$config = config(AppConfig::class);
/** @var SessionConfig|null $session */
$session = config('Session');
$session = config(SessionConfig::class);

$data['matchIP'] = ($session instanceof SessionConfig)
? $session->matchIP : $config->sessionMatchIP;
Expand All @@ -126,6 +127,6 @@ protected function prepare(string $class): string
*/
protected function basename(string $filename): string
{
return gmdate(config('Migrations')->timestampFormat) . basename($filename);
return gmdate(config(Migrations::class)->timestampFormat) . basename($filename);
}
}
6 changes: 4 additions & 2 deletions system/Commands/Generators/SessionMigrationGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
use CodeIgniter\CLI\BaseCommand;
use CodeIgniter\CLI\CLI;
use CodeIgniter\CLI\GeneratorTrait;
use Config\App;
use Config\Migrations;

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

$data['table'] = is_string($data['table']) ? $data['table'] : 'ci_sessions';
$data['DBGroup'] = is_string($data['DBGroup']) ? $data['DBGroup'] : 'default';
Expand All @@ -106,6 +108,6 @@ protected function prepare(string $class): string
*/
protected function basename(string $filename): string
{
return gmdate(config('Migrations')->timestampFormat) . basename($filename);
return gmdate(config(Migrations::class)->timestampFormat) . basename($filename);
}
}
3 changes: 2 additions & 1 deletion system/Commands/Utilities/Routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use CodeIgniter\Commands\Utilities\Routes\AutoRouterImproved\AutoRouteCollector as AutoRouteCollectorImproved;
use CodeIgniter\Commands\Utilities\Routes\FilterCollector;
use CodeIgniter\Commands\Utilities\Routes\SampleURIGenerator;
use Config\Feature;
use Config\Services;

/**
Expand Down Expand Up @@ -124,7 +125,7 @@ public function run(array $params)
}

if ($collection->shouldAutoRoute()) {
$autoRoutesImproved = config('Feature')->autoRoutesImproved ?? false;
$autoRoutesImproved = config(Feature::class)->autoRoutesImproved ?? false;

if ($autoRoutesImproved) {
$autoRouteCollector = new AutoRouteCollectorImproved(
Expand Down
3 changes: 2 additions & 1 deletion system/Commands/Utilities/Routes/FilterCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use CodeIgniter\Filters\Filters;
use CodeIgniter\HTTP\Request;
use CodeIgniter\Router\Router;
use Config\Filters as FiltersConfig;

/**
* Collects filters for a route.
Expand Down Expand Up @@ -72,7 +73,7 @@ private function createRouter(Request $request): Router

private function createFilters(Request $request): Filters
{
$config = config('Filters');
$config = config(FiltersConfig::class);

return new Filters($config, $request, Services::response());
}
Expand Down
3 changes: 2 additions & 1 deletion system/Commands/Utilities/Routes/FilterFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use CodeIgniter\Filters\Filters;
use CodeIgniter\Router\Exceptions\RedirectException;
use CodeIgniter\Router\Router;
use Config\Feature;
use Config\Services;

/**
Expand All @@ -35,7 +36,7 @@ private function getRouteFilters(string $uri): array
{
$this->router->handle($uri);

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

Expand Down
2 changes: 1 addition & 1 deletion system/Config/BaseConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class BaseConfig
*/
public function __construct()
{
static::$moduleConfig = config('Modules');
static::$moduleConfig = config(Modules::class);

$this->registerProperties();

Expand Down
4 changes: 2 additions & 2 deletions system/Config/BaseService.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ public static function injectMock(string $name, $mock)
protected static function discoverServices(string $name, array $arguments)
{
if (! static::$discovered) {
$config = config('Modules');
$config = config(Modules::class);

if ($config->shouldDiscover('services')) {
$locator = static::locator();
Expand Down Expand Up @@ -360,7 +360,7 @@ protected static function discoverServices(string $name, array $arguments)
protected static function buildServicesCache(): void
{
if (! static::$discovered) {
$config = config('Modules');
$config = config(Modules::class);

if ($config->shouldDiscover('services')) {
$locator = static::locator();
Expand Down
2 changes: 1 addition & 1 deletion system/Config/Factories.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ public static function getOptions(string $component): array
// Handle Config as a special case to prevent logic loops
? self::$configOptions
// Load values from the best Factory configuration (will include Registrars)
: config('Factory')->{$component} ?? [];
: config(Factory::class)->{$component} ?? [];

return self::setOptions($component, $values);
}
Expand Down
Loading