From 46a2703e6115fd7506c22df2649afecd8550701e Mon Sep 17 00:00:00 2001 From: kenjis Date: Thu, 13 Jul 2023 16:03:34 +0900 Subject: [PATCH 1/3] refactor: use new Paths() instead of config() `new Paths()` is faster than config(), and Paths is immutable. --- app/Config/Paths.php | 2 ++ system/Config/Services.php | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/Config/Paths.php b/app/Config/Paths.php index e419477a51ec..01d5a8132db5 100644 --- a/app/Config/Paths.php +++ b/app/Config/Paths.php @@ -12,6 +12,8 @@ * share a system folder between multiple applications, and more. * * All paths are relative to the project's root folder. + * + * @immutable */ class Paths { diff --git a/system/Config/Services.php b/system/Config/Services.php index a47faf9c53ed..66d0532e5e47 100644 --- a/system/Config/Services.php +++ b/system/Config/Services.php @@ -461,7 +461,7 @@ public static function parser(?string $viewPath = null, ?ViewConfig $config = nu return static::getSharedInstance('parser', $viewPath, $config); } - $viewPath = $viewPath ?: config(Paths::class)->viewDirectory; + $viewPath = $viewPath ?: (new Paths())->viewDirectory; $config ??= config(ViewConfig::class); return new Parser($config, $viewPath, AppServices::locator(), CI_DEBUG, AppServices::logger()); @@ -480,7 +480,7 @@ public static function renderer(?string $viewPath = null, ?ViewConfig $config = return static::getSharedInstance('renderer', $viewPath, $config); } - $viewPath = $viewPath ?: config(Paths::class)->viewDirectory; + $viewPath = $viewPath ?: (new Paths())->viewDirectory; $config ??= config(ViewConfig::class); return new View($config, $viewPath, AppServices::locator(), CI_DEBUG, AppServices::logger()); From 254435e8eb20466f93c1a589496f47cc4b53c218 Mon Sep 17 00:00:00 2001 From: kenjis Date: Thu, 13 Jul 2023 16:14:59 +0900 Subject: [PATCH 2/3] docs: add notes --- app/Config/Autoload.php | 5 ++++- app/Config/Modules.php | 5 +++++ app/Config/Paths.php | 3 +++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/Config/Autoload.php b/app/Config/Autoload.php index abd9df9dfd72..e9ee6613d22b 100644 --- a/app/Config/Autoload.php +++ b/app/Config/Autoload.php @@ -13,7 +13,10 @@ * can find the files as needed. * * NOTE: If you use an identical key in $psr4 or $classmap, then - * the values in this file will overwrite the framework's values. + * the values in this file will overwrite the framework's values. + * + * NOTE: This class is required prior to Autoloader instantiation, + * and does not extend BaseConfig. */ class Autoload extends AutoloadConfig { diff --git a/app/Config/Modules.php b/app/Config/Modules.php index 5b6a639b3957..7e4916dd8f5b 100644 --- a/app/Config/Modules.php +++ b/app/Config/Modules.php @@ -4,6 +4,11 @@ use CodeIgniter\Modules\Modules as BaseModules; +/** + * Modules Configuration. + * + * NOTE: This class is required prior to Autoloader instantiation. + */ class Modules extends BaseModules { /** diff --git a/app/Config/Paths.php b/app/Config/Paths.php index 01d5a8132db5..262c745ffa95 100644 --- a/app/Config/Paths.php +++ b/app/Config/Paths.php @@ -13,6 +13,9 @@ * * All paths are relative to the project's root folder. * + * NOTE: This class is required prior to Autoloader instantiation, + * and does not extend BaseConfig. + * * @immutable */ class Paths From a2fed684946a02ce0df7e59d832ed62db7d5292c Mon Sep 17 00:00:00 2001 From: kenjis Date: Thu, 13 Jul 2023 16:15:36 +0900 Subject: [PATCH 3/3] docs: replace Note: with NOTE: For concisytency. --- app/Config/Cache.php | 3 ++- app/Config/ContentSecurityPolicy.php | 2 +- app/Config/Logger.php | 2 +- app/Config/Migrations.php | 2 +- app/Config/Modules.php | 3 ++- 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/Config/Cache.php b/app/Config/Cache.php index c19358ce8449..5ba93328110f 100644 --- a/app/Config/Cache.php +++ b/app/Config/Cache.php @@ -95,7 +95,8 @@ class Cache extends BaseConfig * A string of reserved characters that will not be allowed in keys or tags. * Strings that violate this restriction will cause handlers to throw. * Default: {}()/\@: - * Note: The default set is required for PSR-6 compliance. + * + * NOTE: The default set is required for PSR-6 compliance. */ public string $reservedCharacters = '{}()/\@:'; diff --git a/app/Config/ContentSecurityPolicy.php b/app/Config/ContentSecurityPolicy.php index 18612e15cc37..7799c476f078 100644 --- a/app/Config/ContentSecurityPolicy.php +++ b/app/Config/ContentSecurityPolicy.php @@ -39,7 +39,7 @@ class ContentSecurityPolicy extends BaseConfig // ------------------------------------------------------------------------- // Sources allowed - // Note: once you set a policy to 'none', it cannot be further restricted + // NOTE: once you set a policy to 'none', it cannot be further restricted // ------------------------------------------------------------------------- /** diff --git a/app/Config/Logger.php b/app/Config/Logger.php index 7c7414d47228..3fb341c6c04f 100644 --- a/app/Config/Logger.php +++ b/app/Config/Logger.php @@ -99,7 +99,7 @@ class Logger extends BaseConfig * An extension of 'php' allows for protecting the log files via basic * scripting, when they are to be stored under a publicly accessible directory. * - * Note: Leaving it blank will default to 'log'. + * NOTE: Leaving it blank will default to 'log'. */ 'fileExtension' => '', diff --git a/app/Config/Migrations.php b/app/Config/Migrations.php index af28e8ef508a..3c825667cf69 100644 --- a/app/Config/Migrations.php +++ b/app/Config/Migrations.php @@ -40,7 +40,7 @@ class Migrations extends BaseConfig * using the CLI command: * > php spark make:migration * - * Note: if you set an unsupported format, migration runner will not find + * NOTE: if you set an unsupported format, migration runner will not find * your migration files. * * Supported formats: diff --git a/app/Config/Modules.php b/app/Config/Modules.php index 7e4916dd8f5b..54079e771f29 100644 --- a/app/Config/Modules.php +++ b/app/Config/Modules.php @@ -7,7 +7,8 @@ /** * Modules Configuration. * - * NOTE: This class is required prior to Autoloader instantiation. + * NOTE: This class is required prior to Autoloader instantiation, + * and does not extend BaseConfig. */ class Modules extends BaseModules {