diff --git a/system/CLI/BaseCommand.php b/system/CLI/BaseCommand.php index 0618ceb237f7..0c4abd2cea98 100644 --- a/system/CLI/BaseCommand.php +++ b/system/CLI/BaseCommand.php @@ -11,6 +11,7 @@ namespace CodeIgniter\CLI; +use Config\Exceptions; use Psr\Log\LoggerInterface; use ReflectionException; use Throwable; @@ -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'; } diff --git a/system/CLI/GeneratorTrait.php b/system/CLI/GeneratorTrait.php index 21ae0c165d8a..7b6066380739 100644 --- a/system/CLI/GeneratorTrait.php +++ b/system/CLI/GeneratorTrait.php @@ -11,6 +11,7 @@ namespace CodeIgniter\CLI; +use Config\Generators; use Config\Services; use Throwable; @@ -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); diff --git a/system/Cache/Handlers/BaseHandler.php b/system/Cache/Handlers/BaseHandler.php index 0c5ef170c9e0..9f700370fc8a 100644 --- a/system/Cache/Handlers/BaseHandler.php +++ b/system/Cache/Handlers/BaseHandler.php @@ -13,6 +13,7 @@ use Closure; use CodeIgniter\Cache\CacheInterface; +use Config\Cache; use Exception; use InvalidArgumentException; @@ -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); } diff --git a/system/CodeIgniter.php b/system/CodeIgniter.php index 829b65ea952b..2a777474c56e 100644 --- a/system/CodeIgniter.php +++ b/system/CodeIgniter.php @@ -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; @@ -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; @@ -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'); @@ -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(); } diff --git a/system/Commands/Cache/ClearCache.php b/system/Commands/Cache/ClearCache.php index 648d99e42ecc..b903425ba795 100644 --- a/system/Commands/Cache/ClearCache.php +++ b/system/Commands/Cache/ClearCache.php @@ -14,6 +14,7 @@ use CodeIgniter\Cache\CacheFactory; use CodeIgniter\CLI\BaseCommand; use CodeIgniter\CLI\CLI; +use Config\Cache; /** * Clears current cache. @@ -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)) { diff --git a/system/Commands/Cache/InfoCache.php b/system/Commands/Cache/InfoCache.php index db5a51d76f91..1dc2504b0fb4 100644 --- a/system/Commands/Cache/InfoCache.php +++ b/system/Commands/Cache/InfoCache.php @@ -15,6 +15,7 @@ use CodeIgniter\CLI\BaseCommand; use CodeIgniter\CLI\CLI; use CodeIgniter\I18n\Time; +use Config\Cache; /** * Shows information on the cache. @@ -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') { diff --git a/system/Commands/Database/CreateDatabase.php b/system/Commands/Database/CreateDatabase.php index a3922bd66dee..d103d97f689a 100644 --- a/system/Commands/Database/CreateDatabase.php +++ b/system/Commands/Database/CreateDatabase.php @@ -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; diff --git a/system/Commands/Generators/MigrationGenerator.php b/system/Commands/Generators/MigrationGenerator.php index 817c16885205..5ffd259ec479 100644 --- a/system/Commands/Generators/MigrationGenerator.php +++ b/system/Commands/Generators/MigrationGenerator.php @@ -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; /** @@ -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; @@ -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); } } diff --git a/system/Commands/Generators/SessionMigrationGenerator.php b/system/Commands/Generators/SessionMigrationGenerator.php index fbfb2d3db1ff..a04527e866d1 100644 --- a/system/Commands/Generators/SessionMigrationGenerator.php +++ b/system/Commands/Generators/SessionMigrationGenerator.php @@ -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. @@ -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'; @@ -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); } } diff --git a/system/Commands/Utilities/Routes.php b/system/Commands/Utilities/Routes.php index bcd5825c649e..4ee18331f781 100644 --- a/system/Commands/Utilities/Routes.php +++ b/system/Commands/Utilities/Routes.php @@ -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; /** @@ -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( diff --git a/system/Commands/Utilities/Routes/FilterCollector.php b/system/Commands/Utilities/Routes/FilterCollector.php index 630416749115..71bbd1b083b3 100644 --- a/system/Commands/Utilities/Routes/FilterCollector.php +++ b/system/Commands/Utilities/Routes/FilterCollector.php @@ -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. @@ -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()); } diff --git a/system/Commands/Utilities/Routes/FilterFinder.php b/system/Commands/Utilities/Routes/FilterFinder.php index 0f25eebf47f1..042b3a269838 100644 --- a/system/Commands/Utilities/Routes/FilterFinder.php +++ b/system/Commands/Utilities/Routes/FilterFinder.php @@ -15,6 +15,7 @@ use CodeIgniter\Filters\Filters; use CodeIgniter\Router\Exceptions\RedirectException; use CodeIgniter\Router\Router; +use Config\Feature; use Config\Services; /** @@ -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(); diff --git a/system/Config/BaseConfig.php b/system/Config/BaseConfig.php index 300e9ffac5f9..80ae268635ef 100644 --- a/system/Config/BaseConfig.php +++ b/system/Config/BaseConfig.php @@ -59,7 +59,7 @@ class BaseConfig */ public function __construct() { - static::$moduleConfig = config('Modules'); + static::$moduleConfig = config(Modules::class); $this->registerProperties(); diff --git a/system/Config/BaseService.php b/system/Config/BaseService.php index 6b72b6ff2ce8..d517691b0c1f 100644 --- a/system/Config/BaseService.php +++ b/system/Config/BaseService.php @@ -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(); @@ -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(); diff --git a/system/Config/Factories.php b/system/Config/Factories.php index d752f55c506e..222df063196a 100644 --- a/system/Config/Factories.php +++ b/system/Config/Factories.php @@ -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); } diff --git a/system/Config/Services.php b/system/Config/Services.php index a2d13c40e80c..a47faf9c53ed 100644 --- a/system/Config/Services.php +++ b/system/Config/Services.php @@ -61,6 +61,7 @@ use CodeIgniter\View\View; use Config\App; use Config\Cache; +use Config\ContentSecurityPolicy as ContentSecurityPolicyConfig; use Config\ContentSecurityPolicy as CSPConfig; use Config\Database; use Config\Email as EmailConfig; @@ -70,8 +71,11 @@ use Config\Format as FormatConfig; use Config\Honeypot as HoneypotConfig; use Config\Images; +use Config\Logger as LoggerConfig; use Config\Migrations; +use Config\Modules; use Config\Pager as PagerConfig; +use Config\Paths; use Config\Services as AppServices; use Config\Session as SessionConfig; use Config\Toolbar as ToolbarConfig; @@ -129,7 +133,7 @@ public static function clirequest(?App $config = null, bool $getShared = true) return static::getSharedInstance('clirequest', $config); } - $config ??= config('App'); + $config ??= config(App::class); return new CLIRequest($config); } @@ -145,7 +149,7 @@ public static function codeigniter(?App $config = null, bool $getShared = true) return static::getSharedInstance('codeigniter', $config); } - $config ??= config('App'); + $config ??= config(App::class); return new CodeIgniter($config); } @@ -175,7 +179,7 @@ public static function csp(?CSPConfig $config = null, bool $getShared = true) return static::getSharedInstance('csp', $config); } - $config ??= config('ContentSecurityPolicy'); + $config ??= config(ContentSecurityPolicyConfig::class); return new ContentSecurityPolicy($config); } @@ -192,7 +196,7 @@ public static function curlrequest(array $options = [], ?ResponseInterface $resp return static::getSharedInstance('curlrequest', $options, $response, $config); } - $config ??= config('App'); + $config ??= config(App::class); $response ??= new Response($config); return new CURLRequest( @@ -217,7 +221,7 @@ public static function email($config = null, bool $getShared = true) } if (empty($config) || ! (is_array($config) || $config instanceof EmailConfig)) { - $config = config('Email'); + $config = config(EmailConfig::class); } return new Email($config); @@ -236,7 +240,7 @@ public static function encrypter(?EncryptionConfig $config = null, $getShared = return static::getSharedInstance('encrypter', $config); } - $config ??= config('Encryption'); + $config ??= config(EncryptionConfig::class); $encryption = new Encryption($config); return $encryption->initialize($config); @@ -261,7 +265,7 @@ public static function exceptions( return static::getSharedInstance('exceptions', $config, $request, $response); } - $config ??= config('Exceptions'); + $config ??= config(ExceptionsConfig::class); $request ??= AppServices::request(); $response ??= AppServices::response(); @@ -282,7 +286,7 @@ public static function filters(?FiltersConfig $config = null, bool $getShared = return static::getSharedInstance('filters', $config); } - $config ??= config('Filters'); + $config ??= config(FiltersConfig::class); return new Filters($config, AppServices::request(), AppServices::response()); } @@ -298,7 +302,7 @@ public static function format(?FormatConfig $config = null, bool $getShared = tr return static::getSharedInstance('format', $config); } - $config ??= config('Format'); + $config ??= config(FormatConfig::class); return new Format($config); } @@ -315,7 +319,7 @@ public static function honeypot(?HoneypotConfig $config = null, bool $getShared return static::getSharedInstance('honeypot', $config); } - $config ??= config('Honeypot'); + $config ??= config(HoneypotConfig::class); return new Honeypot($config); } @@ -332,7 +336,7 @@ public static function image(?string $handler = null, ?Images $config = null, bo return static::getSharedInstance('image', $handler, $config); } - $config ??= config('Images'); + $config ??= config(Images::class); assert($config instanceof Images); $handler = $handler ?: $config->defaultHandler; @@ -392,7 +396,7 @@ public static function logger(bool $getShared = true) return static::getSharedInstance('logger'); } - return new Logger(config('Logger')); + return new Logger(config(LoggerConfig::class)); } /** @@ -406,7 +410,7 @@ public static function migrations(?Migrations $config = null, ?ConnectionInterfa return static::getSharedInstance('migrations', $config, $db); } - $config ??= config('Migrations'); + $config ??= config(Migrations::class); return new MigrationRunner($config, $db); } @@ -440,7 +444,7 @@ public static function pager(?PagerConfig $config = null, ?RendererInterface $vi return static::getSharedInstance('pager', $config, $view); } - $config ??= config('Pager'); + $config ??= config(PagerConfig::class); $view ??= AppServices::renderer(); return new Pager($config, $view); @@ -457,8 +461,8 @@ public static function parser(?string $viewPath = null, ?ViewConfig $config = nu return static::getSharedInstance('parser', $viewPath, $config); } - $viewPath = $viewPath ?: config('Paths')->viewDirectory; - $config ??= config('View'); + $viewPath = $viewPath ?: config(Paths::class)->viewDirectory; + $config ??= config(ViewConfig::class); return new Parser($config, $viewPath, AppServices::locator(), CI_DEBUG, AppServices::logger()); } @@ -476,8 +480,8 @@ public static function renderer(?string $viewPath = null, ?ViewConfig $config = return static::getSharedInstance('renderer', $viewPath, $config); } - $viewPath = $viewPath ?: config('Paths')->viewDirectory; - $config ??= config('View'); + $viewPath = $viewPath ?: config(Paths::class)->viewDirectory; + $config ??= config(ViewConfig::class); return new View($config, $viewPath, AppServices::locator(), CI_DEBUG, AppServices::logger()); } @@ -536,7 +540,7 @@ public static function incomingrequest(?App $config = null, bool $getShared = tr return static::getSharedInstance('request', $config); } - $config ??= config('App'); + $config ??= config(App::class); return new IncomingRequest( $config, @@ -557,7 +561,7 @@ public static function response(?App $config = null, bool $getShared = true) return static::getSharedInstance('response', $config); } - $config ??= config('App'); + $config ??= config(App::class); return new Response($config); } @@ -573,7 +577,7 @@ public static function redirectresponse(?App $config = null, bool $getShared = t return static::getSharedInstance('redirectresponse', $config); } - $config ??= config('App'); + $config ??= config(App::class); $response = new RedirectResponse($config); $response->setProtocolVersion(AppServices::request()->getProtocolVersion()); @@ -592,7 +596,7 @@ public static function routes(bool $getShared = true) return static::getSharedInstance('routes'); } - return new RouteCollection(AppServices::locator(), config('Modules')); + return new RouteCollection(AppServices::locator(), config(Modules::class)); } /** @@ -625,7 +629,7 @@ public static function security(?App $config = null, bool $getShared = true) return static::getSharedInstance('security', $config); } - $config ??= config('App'); + $config ??= config(App::class); return new Security($config); } @@ -641,13 +645,13 @@ public static function session(?App $config = null, bool $getShared = true) return static::getSharedInstance('session', $config); } - $config ??= config('App'); + $config ??= config(App::class); assert($config instanceof App); $logger = AppServices::logger(); /** @var SessionConfig|null $sessionConfig */ - $sessionConfig = config('Session'); + $sessionConfig = config(SessionConfig::class); $driverName = $sessionConfig->driver ?? $config->sessionDriver; @@ -718,7 +722,7 @@ public static function toolbar(?ToolbarConfig $config = null, bool $getShared = return static::getSharedInstance('toolbar', $config); } - $config ??= config('Toolbar'); + $config ??= config(ToolbarConfig::class); return new Toolbar($config); } @@ -750,7 +754,7 @@ public static function validation(?ValidationConfig $config = null, bool $getSha return static::getSharedInstance('validation', $config); } - $config ??= config('Validation'); + $config ??= config(ValidationConfig::class); return new Validation($config, AppServices::renderer()); } diff --git a/system/Controller.php b/system/Controller.php index 870f15b4fc04..64de91ab2938 100644 --- a/system/Controller.php +++ b/system/Controller.php @@ -17,6 +17,7 @@ use CodeIgniter\Validation\Exceptions\ValidationException; use CodeIgniter\Validation\ValidationInterface; use Config\Services; +use Config\Validation; use Psr\Log\LoggerInterface; /** @@ -164,7 +165,7 @@ private function setValidator($rules, array $messages): void // If you replace the $rules array with the name of the group if (is_string($rules)) { - $validation = config('Validation'); + $validation = config(Validation::class); // If the rule wasn't found in the \Config\Validation, we // should throw an exception so the developer can find it. diff --git a/system/Database/Config.php b/system/Database/Config.php index 802a4da25ac6..f34d0395bc69 100644 --- a/system/Database/Config.php +++ b/system/Database/Config.php @@ -57,8 +57,7 @@ public static function connect($group = null, bool $getShared = true) $config = $group; $group = 'custom-' . md5(json_encode($config)); } else { - /** @var DbConfig $dbConfig */ - $dbConfig = config('Database'); + $dbConfig = config(DbConfig::class); if ($group === null) { $group = (ENVIRONMENT === 'testing') ? 'tests' : $dbConfig->defaultGroup; @@ -132,7 +131,7 @@ public static function utils($group = null) */ public static function seeder(?string $group = null) { - $config = config('Database'); + $config = config(DbConfig::class); return new Seeder($config, static::connect($group)); } diff --git a/system/Database/Migration.php b/system/Database/Migration.php index 6b1cf82d642d..0f1ab2c74f2f 100644 --- a/system/Database/Migration.php +++ b/system/Database/Migration.php @@ -46,7 +46,7 @@ abstract class Migration */ public function __construct(?Forge $forge = null) { - $this->forge = $forge ?? Database::forge($this->DBGroup ?? config('Database')->defaultGroup); + $this->forge = $forge ?? Database::forge($this->DBGroup ?? config(Database::class)->defaultGroup); $this->db = $this->forge->getConnection(); } diff --git a/system/Database/MigrationRunner.php b/system/Database/MigrationRunner.php index 569be22807e0..eda6bb582e80 100644 --- a/system/Database/MigrationRunner.php +++ b/system/Database/MigrationRunner.php @@ -142,7 +142,7 @@ public function __construct(MigrationsConfig $config, $db = null) $this->namespace = APP_NAMESPACE; // get default database group - $config = config('Database'); + $config = config(Database::class); $this->group = $config->defaultGroup; unset($config); @@ -844,7 +844,7 @@ protected function migrate($direction, $migration): bool } $instance = new $class(); - $group = $instance->getDBGroup() ?? config('Database')->defaultGroup; + $group = $instance->getDBGroup() ?? config(Database::class)->defaultGroup; if (ENVIRONMENT !== 'testing' && $group === 'tests' && $this->groupFilter !== 'tests') { // @codeCoverageIgnoreStart diff --git a/system/Debug/Toolbar/Collectors/Config.php b/system/Debug/Toolbar/Collectors/Config.php index b4600555442d..faf7a19b7391 100644 --- a/system/Debug/Toolbar/Collectors/Config.php +++ b/system/Debug/Toolbar/Collectors/Config.php @@ -12,6 +12,7 @@ namespace CodeIgniter\Debug\Toolbar\Collectors; use CodeIgniter\CodeIgniter; +use Config\App; use Config\Services; /** @@ -24,7 +25,7 @@ class Config */ public static function display(): array { - $config = config('App'); + $config = config(App::class); return [ 'ciVersion' => CodeIgniter::CI_VERSION, diff --git a/system/Debug/Toolbar/Collectors/Database.php b/system/Debug/Toolbar/Collectors/Database.php index c7ed6703b402..9d4099f46691 100644 --- a/system/Debug/Toolbar/Collectors/Database.php +++ b/system/Debug/Toolbar/Collectors/Database.php @@ -13,6 +13,7 @@ use CodeIgniter\Database\Query; use CodeIgniter\I18n\Time; +use Config\Toolbar; /** * Collector for the Database tab of the Debug Toolbar. @@ -78,7 +79,7 @@ public function __construct() */ public static function collect(Query $query) { - $config = config('Toolbar'); + $config = config(Toolbar::class); // Provide default in case it's not set $max = $config->maxQueries ?: 100; diff --git a/system/Encryption/Handlers/BaseHandler.php b/system/Encryption/Handlers/BaseHandler.php index 894cb81d30cf..08c0234a5d6d 100644 --- a/system/Encryption/Handlers/BaseHandler.php +++ b/system/Encryption/Handlers/BaseHandler.php @@ -24,7 +24,7 @@ abstract class BaseHandler implements EncrypterInterface */ public function __construct(?Encryption $config = null) { - $config ??= config('Encryption'); + $config ??= config(Encryption::class); // make the parameters conveniently accessible foreach (get_object_vars($config) as $key => $value) { diff --git a/system/Events/Events.php b/system/Events/Events.php index 064f01ab4104..f90af36c2e57 100644 --- a/system/Events/Events.php +++ b/system/Events/Events.php @@ -71,8 +71,7 @@ public static function initialize() return; } - /** @var Modules $config */ - $config = config('Modules'); + $config = config(Modules::class); $events = APPPATH . 'Config' . DIRECTORY_SEPARATOR . 'Events.php'; $files = []; diff --git a/system/Filters/Filters.php b/system/Filters/Filters.php index c022d7d7fda1..784c45c48be6 100644 --- a/system/Filters/Filters.php +++ b/system/Filters/Filters.php @@ -106,7 +106,7 @@ public function __construct($config, RequestInterface $request, ResponseInterfac $this->request = &$request; $this->setResponse($response); - $this->modules = $modules ?? config('Modules'); + $this->modules = $modules ?? config(Modules::class); if ($this->modules->shouldDiscover('filters')) { $this->discoverFilters(); diff --git a/system/HTTP/CURLRequest.php b/system/HTTP/CURLRequest.php index 1f467a57521f..377f51e46006 100644 --- a/system/HTTP/CURLRequest.php +++ b/system/HTTP/CURLRequest.php @@ -112,12 +112,12 @@ public function __construct(App $config, URI $uri, ?ResponseInterface $response parent::__construct('GET', $uri); - $this->responseOrig = $response ?? new Response(config('App')); + $this->responseOrig = $response ?? new Response(config(App::class)); $this->baseURI = $uri->useRawQueryString(); $this->defaultOptions = $options; /** @var ConfigCURLRequest|null $configCURLRequest */ - $configCURLRequest = config('CURLRequest'); + $configCURLRequest = config(ConfigCURLRequest::class); $this->shareOptions = $configCURLRequest->shareOptions ?? true; $this->config = $this->defaultConfig; diff --git a/system/HTTP/ContentSecurityPolicy.php b/system/HTTP/ContentSecurityPolicy.php index 3cc9b03a58db..2ff9e355a83e 100644 --- a/system/HTTP/ContentSecurityPolicy.php +++ b/system/HTTP/ContentSecurityPolicy.php @@ -11,6 +11,7 @@ namespace CodeIgniter\HTTP; +use Config\App; use Config\ContentSecurityPolicy as ContentSecurityPolicyConfig; /** @@ -241,7 +242,7 @@ class ContentSecurityPolicy */ public function __construct(ContentSecurityPolicyConfig $config) { - $appConfig = config('App'); + $appConfig = config(App::class); $this->CSPEnabled = $appConfig->CSPEnabled; foreach (get_object_vars($config) as $setting => $value) { diff --git a/system/HTTP/DownloadResponse.php b/system/HTTP/DownloadResponse.php index d5824da1cabc..d8fb8c035a03 100644 --- a/system/HTTP/DownloadResponse.php +++ b/system/HTTP/DownloadResponse.php @@ -13,6 +13,7 @@ use CodeIgniter\Exceptions\DownloadException; use CodeIgniter\Files\File; +use Config\App; use Config\Mimes; /** @@ -64,7 +65,7 @@ class DownloadResponse extends Response */ public function __construct(string $filename, bool $setMime) { - parent::__construct(config('App')); + parent::__construct(config(App::class)); $this->filename = $filename; $this->setMime = $setMime; diff --git a/system/HTTP/RequestTrait.php b/system/HTTP/RequestTrait.php index 418da59865b2..7c703c3a9c47 100644 --- a/system/HTTP/RequestTrait.php +++ b/system/HTTP/RequestTrait.php @@ -13,6 +13,7 @@ use CodeIgniter\Exceptions\ConfigException; use CodeIgniter\Validation\FormatRules; +use Config\App; /** * Request Trait @@ -63,7 +64,7 @@ public function getIPAddress(): string * @deprecated $this->proxyIPs property will be removed in the future */ // @phpstan-ignore-next-line - $proxyIPs = $this->proxyIPs ?? config('App')->proxyIPs; + $proxyIPs = $this->proxyIPs ?? config(App::class)->proxyIPs; // @phpstan-ignore-next-line if (! empty($proxyIPs) && (! is_array($proxyIPs) || is_int(array_key_first($proxyIPs)))) { throw new ConfigException( diff --git a/system/HTTP/Response.php b/system/HTTP/Response.php index 21db9acd4191..f573905d1edd 100644 --- a/system/HTTP/Response.php +++ b/system/HTTP/Response.php @@ -16,6 +16,7 @@ use CodeIgniter\Cookie\Exceptions\CookieException; use CodeIgniter\HTTP\Exceptions\HTTPException; use Config\App; +use Config\Cookie as CookieConfig; use Config\Services; /** @@ -172,7 +173,7 @@ public function __construct($config) } $this->cookieStore = new CookieStore([]); - Cookie::setDefaults(config('Cookie') ?? [ + Cookie::setDefaults(config(CookieConfig::class) ?? [ // @todo Remove this fallback when deprecated `App` members are removed 'prefix' => $config->cookiePrefix, 'path' => $config->cookiePath, diff --git a/system/HTTP/ResponseTrait.php b/system/HTTP/ResponseTrait.php index 133d1b193b3b..361c73006526 100644 --- a/system/HTTP/ResponseTrait.php +++ b/system/HTTP/ResponseTrait.php @@ -582,7 +582,7 @@ public function setCookie( } /** @var CookieConfig|null $cookieConfig */ - $cookieConfig = config('Cookie'); + $cookieConfig = config(CookieConfig::class); if ($cookieConfig instanceof CookieConfig) { $secure ??= $cookieConfig->secure; diff --git a/system/HTTP/URI.php b/system/HTTP/URI.php index 587e441ffc17..dee9365ded51 100644 --- a/system/HTTP/URI.php +++ b/system/HTTP/URI.php @@ -13,6 +13,7 @@ use BadMethodCallException; use CodeIgniter\HTTP\Exceptions\HTTPException; +use Config\App; /** * Abstraction for a uniform resource identifier (URI). @@ -622,7 +623,7 @@ public function __toString(): string private function changeSchemeAndPath(string $scheme, string $path): array { // Check if this is an internal URI - $config = config('App'); + $config = config(App::class); $baseUri = new self($config->baseURL); if ( diff --git a/system/Helpers/cookie_helper.php b/system/Helpers/cookie_helper.php index 0a11ce84b76d..cb5f227279d3 100755 --- a/system/Helpers/cookie_helper.php +++ b/system/Helpers/cookie_helper.php @@ -69,10 +69,10 @@ function get_cookie($index, bool $xssClean = false, ?string $prefix = '') { if ($prefix === '') { /** @var Cookie|null $cookie */ - $cookie = config('Cookie'); + $cookie = config(Cookie::class); // @TODO Remove Config\App fallback when deprecated `App` members are removed. - $prefix = $cookie instanceof Cookie ? $cookie->prefix : config('App')->cookiePrefix; + $prefix = $cookie instanceof Cookie ? $cookie->prefix : config(App::class)->cookiePrefix; } $request = Services::request(); diff --git a/system/Helpers/form_helper.php b/system/Helpers/form_helper.php index dfd4a64f0669..c553bddee2c3 100644 --- a/system/Helpers/form_helper.php +++ b/system/Helpers/form_helper.php @@ -10,7 +10,9 @@ */ use CodeIgniter\Validation\Exceptions\ValidationException; +use Config\App; use Config\Services; +use Config\Validation; // CodeIgniter Form Helpers @@ -50,7 +52,7 @@ function form_open(string $action = '', $attributes = [], array $hidden = []): s $attributes .= ' method="post"'; } if (stripos($attributes, 'accept-charset=') === false) { - $config = config('App'); + $config = config(App::class); $attributes .= ' accept-charset="' . strtolower($config->charset) . '"'; } @@ -718,7 +720,7 @@ function validation_errors() */ function validation_list_errors(string $template = 'list'): string { - $config = config('Validation'); + $config = config(Validation::class); $view = Services::renderer(); if (! array_key_exists($template, $config->templates)) { @@ -738,7 +740,7 @@ function validation_list_errors(string $template = 'list'): string */ function validation_show_error(string $field, string $template = 'single'): string { - $config = config('Validation'); + $config = config(Validation::class); $view = Services::renderer(); $errors = array_filter(validation_errors(), static fn ($key) => preg_match( diff --git a/system/Helpers/url_helper.php b/system/Helpers/url_helper.php index 8443c7a02980..c6c810b66da6 100644 --- a/system/Helpers/url_helper.php +++ b/system/Helpers/url_helper.php @@ -38,7 +38,7 @@ function _get_uri($relativePath = '', ?App $config = null): URI $appConfig = null; if ($config === null) { /** @var App $appConfig */ - $appConfig = config('App'); + $appConfig = config(App::class); if ($appConfig->baseURL === '') { throw new InvalidArgumentException( @@ -145,7 +145,7 @@ function site_url($relativePath = '', ?string $scheme = null, ?App $config = nul function base_url($relativePath = '', ?string $scheme = null): string { /** @var App $config */ - $config = clone config('App'); + $config = clone config(App::class); // Use the current baseURL for multiple domain support $request = Services::request(); @@ -238,7 +238,7 @@ function uri_string(): string function index_page(?App $altConfig = null): string { // use alternate config if provided, else default one - $config = $altConfig ?? config('App'); + $config = $altConfig ?? config(App::class); return $config->indexPage; } @@ -258,7 +258,7 @@ function index_page(?App $altConfig = null): string function anchor($uri = '', string $title = '', $attributes = '', ?App $altConfig = null): string { // use alternate config if provided, else default one - $config = $altConfig ?? config('App'); + $config = $altConfig ?? config(App::class); $siteUrl = is_array($uri) ? site_url($uri, null, $config) : (preg_match('#^(\w+:)?//#i', $uri) ? $uri : site_url($uri, null, $config)); // eliminate trailing slash @@ -291,7 +291,7 @@ function anchor($uri = '', string $title = '', $attributes = '', ?App $altConfig function anchor_popup($uri = '', string $title = '', $attributes = false, ?App $altConfig = null): string { // use alternate config if provided, else default one - $config = $altConfig ?? config('App'); + $config = $altConfig ?? config(App::class); $siteUrl = preg_match('#^(\w+:)?//#i', $uri) ? $uri : site_url($uri, null, $config); $siteUrl = rtrim($siteUrl, '/'); diff --git a/system/Publisher/Publisher.php b/system/Publisher/Publisher.php index 88459153188f..82948b8378c1 100644 --- a/system/Publisher/Publisher.php +++ b/system/Publisher/Publisher.php @@ -15,6 +15,7 @@ use CodeIgniter\Files\FileCollection; use CodeIgniter\HTTP\URI; use CodeIgniter\Publisher\Exceptions\PublisherException; +use Config\Publisher as PublisherConfig; use RuntimeException; use Throwable; @@ -162,7 +163,7 @@ public function __construct(?string $source = null, ?string $destination = null) $this->replacer = new ContentReplacer(); // Restrictions are intentionally not injected to prevent overriding - $this->restrictions = config('Publisher')->restrictions; + $this->restrictions = config(PublisherConfig::class)->restrictions; // Make sure the destination is allowed foreach (array_keys($this->restrictions) as $directory) { diff --git a/system/Router/RouteCollection.php b/system/Router/RouteCollection.php index 66724935e31c..965a0c746ce7 100644 --- a/system/Router/RouteCollection.php +++ b/system/Router/RouteCollection.php @@ -1265,8 +1265,7 @@ private function replaceLocale(string $route, ?string $locale = null): string // Check invalid locale if ($locale !== null) { - /** @var App $config */ - $config = config('App'); + $config = config(App::class); if (! in_array($locale, $config->supportedLocales, true)) { $locale = null; } diff --git a/system/Router/Router.php b/system/Router/Router.php index f9299fa1dd0a..be698003cbe5 100644 --- a/system/Router/Router.php +++ b/system/Router/Router.php @@ -16,6 +16,8 @@ use CodeIgniter\HTTP\Request; use CodeIgniter\Router\Exceptions\RedirectException; use CodeIgniter\Router\Exceptions\RouterException; +use Config\App; +use Config\Feature; /** * Request router. @@ -131,7 +133,7 @@ public function __construct(RouteCollectionInterface $routes, ?Request $request $this->translateURIDashes = $this->collection->shouldTranslateURIDashes(); if ($this->collection->shouldAutoRoute()) { - $autoRoutesImproved = config('Feature')->autoRoutesImproved ?? false; + $autoRoutesImproved = config(Feature::class)->autoRoutesImproved ?? false; if ($autoRoutesImproved) { $this->autoRouter = new AutoRouterImproved( $this->collection->getRegisteredControllers('*'), @@ -181,7 +183,7 @@ public function handle(?string $uri = null) // Checks defined routes if ($this->checkRoutes($uri)) { if ($this->collection->isFiltered($this->matchedRoute[0])) { - $multipleFiltersEnabled = config('Feature')->multipleFilters ?? false; + $multipleFiltersEnabled = config(Feature::class)->multipleFilters ?? false; if ($multipleFiltersEnabled) { $this->filtersInfo = $this->collection->getFiltersForRoute($this->matchedRoute[0]); } else { @@ -441,7 +443,7 @@ protected function checkRoutes(string $uri): bool ); if ($this->collection->shouldUseSupportedLocalesOnly() - && ! in_array($matched['locale'], config('App')->supportedLocales, true)) { + && ! in_array($matched['locale'], config(App::class)->supportedLocales, true)) { // Throw exception to prevent the autorouter, if enabled, // from trying to find a route throw PageNotFoundException::forLocaleNotSupported($matched['locale']); diff --git a/system/Security/Security.php b/system/Security/Security.php index 239156719260..c31cea42288f 100644 --- a/system/Security/Security.php +++ b/system/Security/Security.php @@ -172,7 +172,7 @@ class Security implements SecurityInterface public function __construct(App $config) { /** @var SecurityConfig|null $security */ - $security = config('Security'); + $security = config(SecurityConfig::class); // Store CSRF-related configurations if ($security instanceof SecurityConfig) { @@ -223,7 +223,7 @@ private function configureSession(): void private function configureCookie(App $config): void { /** @var CookieConfig|null $cookie */ - $cookie = config('Cookie'); + $cookie = config(CookieConfig::class); if ($cookie instanceof CookieConfig) { $cookiePrefix = $cookie->prefix; diff --git a/system/Session/Handlers/BaseHandler.php b/system/Session/Handlers/BaseHandler.php index f392c492cf76..9ea9df971d1e 100644 --- a/system/Session/Handlers/BaseHandler.php +++ b/system/Session/Handlers/BaseHandler.php @@ -108,7 +108,7 @@ abstract class BaseHandler implements SessionHandlerInterface public function __construct(AppConfig $config, string $ipAddress) { /** @var SessionConfig|null $session */ - $session = config('Session'); + $session = config(SessionConfig::class); // Store Session configurations if ($session instanceof SessionConfig) { @@ -123,7 +123,7 @@ public function __construct(AppConfig $config, string $ipAddress) } /** @var CookieConfig|null $cookie */ - $cookie = config('Cookie'); + $cookie = config(CookieConfig::class); if ($cookie instanceof CookieConfig) { // Session cookies have no prefix. diff --git a/system/Session/Handlers/DatabaseHandler.php b/system/Session/Handlers/DatabaseHandler.php index b566a3b04d9e..fa474faae54a 100644 --- a/system/Session/Handlers/DatabaseHandler.php +++ b/system/Session/Handlers/DatabaseHandler.php @@ -74,7 +74,7 @@ public function __construct(AppConfig $config, string $ipAddress) parent::__construct($config, $ipAddress); /** @var SessionConfig|null $session */ - $session = config('Session'); + $session = config(SessionConfig::class); // Store Session configurations if ($session instanceof SessionConfig) { diff --git a/system/Session/Handlers/MemcachedHandler.php b/system/Session/Handlers/MemcachedHandler.php index e4c8c6e8c673..e6f575e94b84 100644 --- a/system/Session/Handlers/MemcachedHandler.php +++ b/system/Session/Handlers/MemcachedHandler.php @@ -59,7 +59,7 @@ public function __construct(AppConfig $config, string $ipAddress) parent::__construct($config, $ipAddress); /** @var SessionConfig|null $session */ - $session = config('Session'); + $session = config(SessionConfig::class); $this->sessionExpiration = ($session instanceof SessionConfig) ? $session->expiration : $config->sessionExpiration; diff --git a/system/Session/Handlers/RedisHandler.php b/system/Session/Handlers/RedisHandler.php index 9910637663f5..56b725327dd7 100644 --- a/system/Session/Handlers/RedisHandler.php +++ b/system/Session/Handlers/RedisHandler.php @@ -72,7 +72,7 @@ public function __construct(AppConfig $config, string $ipAddress) parent::__construct($config, $ipAddress); /** @var SessionConfig|null $session */ - $session = config('Session'); + $session = config(SessionConfig::class); // Store Session configurations if ($session instanceof SessionConfig) { diff --git a/system/Session/Session.php b/system/Session/Session.php index 4f536ca0b0f0..efbd67d513ee 100644 --- a/system/Session/Session.php +++ b/system/Session/Session.php @@ -166,7 +166,7 @@ public function __construct(SessionHandlerInterface $driver, App $config) $this->driver = $driver; /** @var SessionConfig|null $session */ - $session = config('Session'); + $session = config(SessionConfig::class); // Store Session configurations if ($session instanceof SessionConfig) { @@ -195,7 +195,7 @@ public function __construct(SessionHandlerInterface $driver, App $config) $this->cookieSameSite = $config->cookieSameSite ?? $this->cookieSameSite; /** @var CookieConfig $cookie */ - $cookie = config('Cookie'); + $cookie = config(CookieConfig::class); $this->cookie = (new Cookie($this->sessionCookieName, '', [ 'expires' => $this->sessionExpiration === 0 ? 0 : Time::now()->getTimestamp() + $this->sessionExpiration, diff --git a/system/Test/CIUnitTestCase.php b/system/Test/CIUnitTestCase.php index bfde56faf6ff..0ed50a500c55 100644 --- a/system/Test/CIUnitTestCase.php +++ b/system/Test/CIUnitTestCase.php @@ -25,6 +25,7 @@ use CodeIgniter\Test\Mock\MockSession; use Config\App; use Config\Autoload; +use Config\Email; use Config\Modules; use Config\Services; use Exception; @@ -323,7 +324,7 @@ protected function mockCache() */ protected function mockEmail() { - Services::injectMock('email', new MockEmail(config('Email'))); + Services::injectMock('email', new MockEmail(config(Email::class))); } /** @@ -333,7 +334,7 @@ protected function mockSession() { $_SESSION = []; - $config = config('App'); + $config = config(App::class); $session = new MockSession(new ArrayHandler($config, '0.0.0.0'), $config); Services::injectMock('session', $session); diff --git a/system/Test/ControllerTestTrait.php b/system/Test/ControllerTestTrait.php index 64cbcbe175c0..828dabb9e946 100644 --- a/system/Test/ControllerTestTrait.php +++ b/system/Test/ControllerTestTrait.php @@ -96,7 +96,7 @@ protected function setUpControllerTestTrait(): void helper('url'); if (empty($this->appConfig)) { - $this->appConfig = config('App'); + $this->appConfig = config(App::class); } if (! $this->uri instanceof URI) { diff --git a/system/Test/ControllerTester.php b/system/Test/ControllerTester.php index a4b41a94c308..2fff82eeceb1 100644 --- a/system/Test/ControllerTester.php +++ b/system/Test/ControllerTester.php @@ -96,7 +96,7 @@ trait ControllerTester protected function setUpControllerTester(): void { if (empty($this->appConfig)) { - $this->appConfig = config('App'); + $this->appConfig = config(App::class); } if (! $this->uri instanceof URI) { diff --git a/system/Test/Fabricator.php b/system/Test/Fabricator.php index df1906b6416c..6c9e82ff5c00 100644 --- a/system/Test/Fabricator.php +++ b/system/Test/Fabricator.php @@ -14,6 +14,7 @@ use CodeIgniter\Exceptions\FrameworkException; use CodeIgniter\I18n\Time; use CodeIgniter\Model; +use Config\App; use Faker\Factory; use Faker\Generator; use InvalidArgumentException; @@ -114,7 +115,7 @@ public function __construct($model, ?array $formatters = null, ?string $locale = // If no locale was specified then use the App default if ($locale === null) { - $locale = config('App')->defaultLocale; + $locale = config(App::class)->defaultLocale; } // There is no easy way to retrieve the locale from Faker so we will store it diff --git a/system/Test/FeatureTestCase.php b/system/Test/FeatureTestCase.php index bf157aea52af..0bef873297e4 100644 --- a/system/Test/FeatureTestCase.php +++ b/system/Test/FeatureTestCase.php @@ -18,6 +18,7 @@ use CodeIgniter\HTTP\UserAgent; use CodeIgniter\Router\Exceptions\RedirectException; use CodeIgniter\Router\RouteCollection; +use Config\App; use Config\Services; use Exception; use ReflectionException; @@ -291,7 +292,7 @@ public function options(string $path, ?array $params = null) */ protected function setupRequest(string $method, ?string $path = null): IncomingRequest { - $config = config('App'); + $config = config(App::class); $uri = new URI(rtrim($config->baseURL, '/') . '/' . trim($path, '/ ')); $request = new IncomingRequest($config, clone $uri, null, new UserAgent()); diff --git a/system/Test/FilterTestTrait.php b/system/Test/FilterTestTrait.php index 3bcd37962941..4901a585ce20 100644 --- a/system/Test/FilterTestTrait.php +++ b/system/Test/FilterTestTrait.php @@ -98,7 +98,7 @@ protected function setUpFilterTestTrait(): void $this->response ??= clone Services::response(); // Create our config and Filters instance to reuse for performance - $this->filtersConfig ??= config('Filters'); + $this->filtersConfig ??= config(FiltersConfig::class); $this->filters ??= new Filters($this->filtersConfig, $this->request, $this->response); if ($this->collection === null) { diff --git a/system/Typography/Typography.php b/system/Typography/Typography.php index 9b72c64c1ac9..1ca7a56ff598 100644 --- a/system/Typography/Typography.php +++ b/system/Typography/Typography.php @@ -11,6 +11,8 @@ namespace CodeIgniter\Typography; +use Config\DocTypes; + /** * Typography Class */ @@ -324,7 +326,7 @@ public function nl2brExceptPre(string $str): string $newstr = ''; for ($ex = explode('pre>', $str), $ct = count($ex), $i = 0; $i < $ct; $i++) { - $xhtml = ! (config('DocTypes')->html5 ?? false); + $xhtml = ! (config(DocTypes::class)->html5 ?? false); $newstr .= (($i % 2) === 0) ? nl2br($ex[$i], $xhtml) : $ex[$i]; if ($ct - 1 !== $i) { diff --git a/system/View/ViewDecoratorTrait.php b/system/View/ViewDecoratorTrait.php index 243c229bfbde..97cdbe0a252d 100644 --- a/system/View/ViewDecoratorTrait.php +++ b/system/View/ViewDecoratorTrait.php @@ -12,6 +12,7 @@ namespace CodeIgniter\View; use CodeIgniter\View\Exceptions\ViewException; +use Config\View as ViewConfig; trait ViewDecoratorTrait { @@ -21,7 +22,7 @@ trait ViewDecoratorTrait */ protected function decorateOutput(string $html): string { - $decorators = \config('View')->decorators; + $decorators = \config(ViewConfig::class)->decorators; foreach ($decorators as $decorator) { if (! is_subclass_of($decorator, ViewDecoratorInterface::class)) {