From ed25c835e1031cb8bf68657c8c1bdfb6c558c922 Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 4 Oct 2023 20:03:10 +0900 Subject: [PATCH 01/16] config: move Config namespace to AutoloadConfig We can't customize `Config` namespace name. --- app/Config/Autoload.php | 1 - system/Config/AutoloadConfig.php | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Config/Autoload.php b/app/Config/Autoload.php index 22f05ecdab26..34d234631949 100644 --- a/app/Config/Autoload.php +++ b/app/Config/Autoload.php @@ -46,7 +46,6 @@ class Autoload extends AutoloadConfig */ public $psr4 = [ APP_NAMESPACE => APPPATH, // For custom app namespace - 'Config' => APPPATH . 'Config', ]; /** diff --git a/system/Config/AutoloadConfig.php b/system/Config/AutoloadConfig.php index da08dd6f6640..1417b6096a10 100644 --- a/system/Config/AutoloadConfig.php +++ b/system/Config/AutoloadConfig.php @@ -93,6 +93,7 @@ class AutoloadConfig protected $corePsr4 = [ 'CodeIgniter' => SYSTEMPATH, 'App' => APPPATH, // To ensure filters, etc still found, + 'Config' => APPPATH . 'Config', ]; /** From 2431b5b2d090058dbaf0e22170fe93f5c9be3b51 Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 4 Oct 2023 20:04:18 +0900 Subject: [PATCH 02/16] refactor: remove `App` namespace in AutoloadConfig It is set in Config\Autoload, and it may be renamed. --- system/Config/AutoloadConfig.php | 1 - 1 file changed, 1 deletion(-) diff --git a/system/Config/AutoloadConfig.php b/system/Config/AutoloadConfig.php index 1417b6096a10..3f0dc494f0a9 100644 --- a/system/Config/AutoloadConfig.php +++ b/system/Config/AutoloadConfig.php @@ -92,7 +92,6 @@ class AutoloadConfig */ protected $corePsr4 = [ 'CodeIgniter' => SYSTEMPATH, - 'App' => APPPATH, // To ensure filters, etc still found, 'Config' => APPPATH . 'Config', ]; From 092989f68be3d8978cc3579b88517f090fc3da9d Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 4 Oct 2023 20:06:00 +0900 Subject: [PATCH 03/16] perf: use Composer autoloader first - When we use Composer, we use Composer autoloader first. So no need to load Composer classmap to CI4 autoloader. - Add `App` and `Config` namespaces to composer.json. So we can use composer dump-autoload for app classes. --- composer.json | 2 ++ system/Autoloader/Autoloader.php | 20 +++++++++++--------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/composer.json b/composer.json index aeac6801da1b..a3e8e3028c8c 100644 --- a/composer.json +++ b/composer.json @@ -58,6 +58,8 @@ }, "autoload": { "psr-4": { + "App\\": "app/", + "Config\\": "app/Config/", "CodeIgniter\\": "system/" }, "exclude-from-classmap": [ diff --git a/system/Autoloader/Autoloader.php b/system/Autoloader/Autoloader.php index a06ffc2c6252..a7832a190e31 100644 --- a/system/Autoloader/Autoloader.php +++ b/system/Autoloader/Autoloader.php @@ -137,8 +137,6 @@ private function loadComposerInfo(Modules $modules): void */ $composer = include COMPOSER_PATH; - $this->loadComposerClassmap($composer); - // Should we load through Composer's namespaces, also? if ($modules->discoverInComposer) { // @phpstan-ignore-next-line @@ -155,11 +153,11 @@ private function loadComposerInfo(Modules $modules): void */ public function register() { - // Prepend the PSR4 autoloader for maximum performance. - spl_autoload_register([$this, 'loadClass'], true, true); + // Register classmap loader for the files in our class map. + spl_autoload_register([$this, 'loadClassmap'], true); - // Now prepend another loader for the files in our class map. - spl_autoload_register([$this, 'loadClassmap'], true, true); + // Register the PSR-4 autoloader. + spl_autoload_register([$this, 'loadClass'], true); // Load our non-class files foreach ($this->files as $file) { @@ -362,9 +360,13 @@ private function loadComposerNamespaces(ClassLoader $composer, array $composerPa { $namespacePaths = $composer->getPrefixesPsr4(); - // Get rid of CodeIgniter so we don't have duplicates - if (isset($namespacePaths['CodeIgniter\\'])) { - unset($namespacePaths['CodeIgniter\\']); + // Get rid of duplicated namespaces. + $duplicatedNamespaces = ['CodeIgniter', APP_NAMESPACE, 'Config']; + + foreach ($duplicatedNamespaces as $ns) { + if (isset($namespacePaths[$ns . '\\'])) { + unset($namespacePaths[$ns . '\\']); + } } if (! method_exists(InstalledVersions::class, 'getAllRawData')) { From 7ad5d96ca87536823c06e2636bf223970bd17546 Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 4 Oct 2023 20:21:13 +0900 Subject: [PATCH 04/16] refactor: remove unused method --- system/Autoloader/Autoloader.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/system/Autoloader/Autoloader.php b/system/Autoloader/Autoloader.php index a7832a190e31..967543c3e9b3 100644 --- a/system/Autoloader/Autoloader.php +++ b/system/Autoloader/Autoloader.php @@ -430,13 +430,6 @@ private function loadComposerNamespaces(ClassLoader $composer, array $composerPa $this->addNamespace($newPaths); } - private function loadComposerClassmap(ClassLoader $composer): void - { - $classes = $composer->getClassMap(); - - $this->classmap = array_merge($this->classmap, $classes); - } - /** * Locates autoload information from Composer, if available. * From 90481ba500d2b855d755c6daca93c67dc36569d2 Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 4 Oct 2023 20:21:54 +0900 Subject: [PATCH 05/16] chore: composer normalize --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index a3e8e3028c8c..925f1678068e 100644 --- a/composer.json +++ b/composer.json @@ -59,8 +59,8 @@ "autoload": { "psr-4": { "App\\": "app/", - "Config\\": "app/Config/", - "CodeIgniter\\": "system/" + "CodeIgniter\\": "system/", + "Config\\": "app/Config/" }, "exclude-from-classmap": [ "**/Database/Migrations/**" From 6d6512f65c53926b9583d11e3c234421d2043c65 Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 4 Oct 2023 20:29:19 +0900 Subject: [PATCH 06/16] test: update assertion --- tests/system/Commands/Utilities/NamespacesTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/system/Commands/Utilities/NamespacesTest.php b/tests/system/Commands/Utilities/NamespacesTest.php index 755dd70f7cc6..d700dd666ec6 100644 --- a/tests/system/Commands/Utilities/NamespacesTest.php +++ b/tests/system/Commands/Utilities/NamespacesTest.php @@ -56,8 +56,8 @@ public function testNamespacesCommandCodeIgniterOnly(): void | Namespace | Path | Found? | +---------------+-------------------------+--------+ | CodeIgniter | ROOTPATH/system | Yes | - | App | ROOTPATH/app | Yes | | Config | APPPATH/Config | Yes | + | App | ROOTPATH/app | Yes | | Tests\Support | ROOTPATH/tests/_support | Yes | +---------------+-------------------------+--------+ EOL; From dbca19cace2dea4d2551053189cd9efbf9f199c6 Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 4 Oct 2023 21:22:46 +0900 Subject: [PATCH 07/16] test: remove failed test for deprecated Config class 1) CodeIgniter\Config\ConfigTest::testCreateNonConfig ErrorException: Constant EVENT_PRIORITY_LOW already defined /home/runner/work/CodeIgniter4/CodeIgniter4/app/Config/Constants.php:84 /home/runner/work/CodeIgniter4/CodeIgniter4/system/Config/Factories.php:271 /home/runner/work/CodeIgniter4/CodeIgniter4/system/Config/Factories.php:148 /home/runner/work/CodeIgniter4/CodeIgniter4/system/Config/Config.php:31 /home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Config/ConfigTest.php:51 --- tests/system/Config/ConfigTest.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tests/system/Config/ConfigTest.php b/tests/system/Config/ConfigTest.php index 6bd4103a7aa2..b00bc2b9f699 100644 --- a/tests/system/Config/ConfigTest.php +++ b/tests/system/Config/ConfigTest.php @@ -46,13 +46,6 @@ public function testCreateSharedInstance(): void $this->assertSame($Config2, $Config); } - public function testCreateNonConfig(): void - { - $Config = Config::get('Constants', false); - - $this->assertNull($Config); - } - /** * @runInSeparateProcess * @preserveGlobalState disabled From 6bba15ade30615909dc26a319e53e7a16b5c9744 Mon Sep 17 00:00:00 2001 From: kenjis Date: Thu, 5 Oct 2023 08:17:18 +0900 Subject: [PATCH 08/16] chore: remove `App` from composer.json It may be customized. --- composer.json | 1 - 1 file changed, 1 deletion(-) diff --git a/composer.json b/composer.json index 925f1678068e..f72ecc7f548c 100644 --- a/composer.json +++ b/composer.json @@ -58,7 +58,6 @@ }, "autoload": { "psr-4": { - "App\\": "app/", "CodeIgniter\\": "system/", "Config\\": "app/Config/" }, From 5aecfd1a80a81427a45dfe3c20a1b40614df3853 Mon Sep 17 00:00:00 2001 From: kenjis Date: Thu, 5 Oct 2023 08:33:34 +0900 Subject: [PATCH 09/16] docs: update comments in Config/Autoload.php --- app/Config/Autoload.php | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/app/Config/Autoload.php b/app/Config/Autoload.php index 34d234631949..85e0d9919d2b 100644 --- a/app/Config/Autoload.php +++ b/app/Config/Autoload.php @@ -30,22 +30,18 @@ class Autoload extends AutoloadConfig * their location on the file system. These are used by the autoloader * to locate files the first time they have been instantiated. * - * The '/app' and '/system' directories are already mapped for you. - * you may change the name of the 'App' namespace if you wish, + * The 'Config' (APPPATH . 'Config') and 'CodeIgniter' (SYSTEMPATH) are + * already mapped for you. + * + * You may change the name of the 'App' namespace if you wish, * but this should be done prior to creating any namespaced classes, * else you will need to modify all of those classes for this to work. * - * Prototype: - * $psr4 = [ - * 'CodeIgniter' => SYSTEMPATH, - * 'App' => APPPATH - * ]; - * * @var array|string> * @phpstan-var array> */ public $psr4 = [ - APP_NAMESPACE => APPPATH, // For custom app namespace + APP_NAMESPACE => APPPATH, ]; /** From 13282524b207568c7af51753b4f1ed704780cf7e Mon Sep 17 00:00:00 2001 From: kenjis Date: Thu, 5 Oct 2023 08:42:33 +0900 Subject: [PATCH 10/16] docs: update description --- user_guide_src/source/concepts/autoloader.rst | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/user_guide_src/source/concepts/autoloader.rst b/user_guide_src/source/concepts/autoloader.rst index 22722716661b..5fdf4e89bfee 100644 --- a/user_guide_src/source/concepts/autoloader.rst +++ b/user_guide_src/source/concepts/autoloader.rst @@ -90,9 +90,14 @@ The key of each row is the name of the class that you want to locate. The value Composer Support **************** -Composer support is automatically initialized by default. By default, it looks for Composer's autoload file at +Composer support is automatically initialized by default. + +By default, it looks for Composer's autoload file at ``ROOTPATH . 'vendor/autoload.php'``. If you need to change the location of that file for any reason, you can modify the value defined in **app/Config/Constants.php**. -.. note:: If the same namespace is defined in both CodeIgniter and Composer, CodeIgniter's autoloader will be +If the same namespace is defined in both CodeIgniter and Composer, Composer's +autoloader will be the first one to get a chance to locate the file. + +.. note:: Prior to v4.5.0, if the same namespace was defined in both CodeIgniter and Composer, CodeIgniter's autoloader was the first one to get a chance to locate the file. From be9204e34d30c292578a74cbb295135b3784462c Mon Sep 17 00:00:00 2001 From: kenjis Date: Thu, 5 Oct 2023 08:43:36 +0900 Subject: [PATCH 11/16] docs: add *** for headings --- user_guide_src/source/concepts/autoloader.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/user_guide_src/source/concepts/autoloader.rst b/user_guide_src/source/concepts/autoloader.rst index 5fdf4e89bfee..ff522732669c 100644 --- a/user_guide_src/source/concepts/autoloader.rst +++ b/user_guide_src/source/concepts/autoloader.rst @@ -13,6 +13,7 @@ classes that your project is using. Keeping track of where every single file is, hard-coding that location into your files in a series of ``requires()`` is a massive headache and very error-prone. That's where autoloaders come in. +*********************** CodeIgniter4 Autoloader *********************** @@ -36,12 +37,14 @@ beginning of the framework's execution. file name case is incorrect, the autoloader cannot find the file on the server. +************* Configuration ************* Initial configuration is done in **app/Config/Autoload.php**. This file contains two primary arrays: one for the classmap, and one for PSR-4 compatible namespaces. +********** Namespaces ********** @@ -76,6 +79,7 @@ You will need to modify any existing files that are referencing the current name expect. This allows the core system files to always be able to locate them, even when the application namespace has changed. +******** Classmap ******** @@ -87,6 +91,7 @@ third-party libraries that are not namespaced: The key of each row is the name of the class that you want to locate. The value is the path to locate it at. +**************** Composer Support **************** From e5d7d3f38ed2a9dc79fe34ecc30d0344e03fad3b Mon Sep 17 00:00:00 2001 From: kenjis Date: Thu, 5 Oct 2023 08:45:30 +0900 Subject: [PATCH 12/16] docs: update sample code --- user_guide_src/source/concepts/autoloader/001.php | 3 +-- user_guide_src/source/dbmgmt/migration.rst | 1 + user_guide_src/source/dbmgmt/migration/004.php | 4 ++-- user_guide_src/source/general/modules/001.php | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/user_guide_src/source/concepts/autoloader/001.php b/user_guide_src/source/concepts/autoloader/001.php index 68eeaddd625f..d6da1bce5389 100644 --- a/user_guide_src/source/concepts/autoloader/001.php +++ b/user_guide_src/source/concepts/autoloader/001.php @@ -8,8 +8,7 @@ class Autoload extends AutoloadConfig { // ... public $psr4 = [ - APP_NAMESPACE => APPPATH, // For custom app namespace - 'Config' => APPPATH . 'Config', + APP_NAMESPACE => APPPATH, ]; // ... diff --git a/user_guide_src/source/dbmgmt/migration.rst b/user_guide_src/source/dbmgmt/migration.rst index 4af207164b73..3f7a17e71024 100644 --- a/user_guide_src/source/dbmgmt/migration.rst +++ b/user_guide_src/source/dbmgmt/migration.rst @@ -93,6 +93,7 @@ For example, assume that we have the following namespaces defined in our Autoloa configuration file: .. literalinclude:: migration/004.php + :lines: 2- This will look for any migrations located at both **APPPATH/Database/Migrations** and **ROOTPATH/MyCompany/Database/Migrations**. This makes it simple to include migrations in your diff --git a/user_guide_src/source/dbmgmt/migration/004.php b/user_guide_src/source/dbmgmt/migration/004.php index 1e4c831c8219..24c684088a4b 100644 --- a/user_guide_src/source/dbmgmt/migration/004.php +++ b/user_guide_src/source/dbmgmt/migration/004.php @@ -1,6 +1,6 @@ APPPATH, - 'MyCompany' => ROOTPATH . 'MyCompany', + APP_NAMESPACE => APPPATH, + 'MyCompany' => ROOTPATH . 'MyCompany', ]; diff --git a/user_guide_src/source/general/modules/001.php b/user_guide_src/source/general/modules/001.php index 1f93e213359f..dcc1fbe3a9e4 100644 --- a/user_guide_src/source/general/modules/001.php +++ b/user_guide_src/source/general/modules/001.php @@ -6,9 +6,9 @@ class Autoload extends AutoloadConfig { + // ... public $psr4 = [ - APP_NAMESPACE => APPPATH, // For custom namespace - 'Config' => APPPATH . 'Config', + APP_NAMESPACE => APPPATH, 'Acme\Blog' => ROOTPATH . 'acme/Blog', ]; From 1ac4ff67fbb7eb384cbd44782c0d2c67d63630c5 Mon Sep 17 00:00:00 2001 From: kenjis Date: Thu, 5 Oct 2023 09:07:07 +0900 Subject: [PATCH 13/16] docs: add "Improve Performance" --- user_guide_src/source/concepts/autoloader.rst | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/user_guide_src/source/concepts/autoloader.rst b/user_guide_src/source/concepts/autoloader.rst index ff522732669c..eaec9eaf8693 100644 --- a/user_guide_src/source/concepts/autoloader.rst +++ b/user_guide_src/source/concepts/autoloader.rst @@ -101,8 +101,36 @@ By default, it looks for Composer's autoload file at ``ROOTPATH . 'vendor/autoload.php'``. If you need to change the location of that file for any reason, you can modify the value defined in **app/Config/Constants.php**. +Priority of Autoloaders +======================= + If the same namespace is defined in both CodeIgniter and Composer, Composer's autoloader will be the first one to get a chance to locate the file. .. note:: Prior to v4.5.0, if the same namespace was defined in both CodeIgniter and Composer, CodeIgniter's autoloader was the first one to get a chance to locate the file. + +.. _autoloader-composer-support-improve-performance: + +Improve Performance +=================== + +.. versionadded:: 4.5.0 + +When you use Composer, you could improve the performance of autoloading with +Composer's classmap dump. + +Add your ``App`` namespace in your **composer.json**, and run ``composer dump-autoload``. + +.. code-block:: text + + { + ... + "autoload": { + "psr-4": { + "App\\": "app/", + }, + ... + }, + ... + } From 1199b4c4dbb3c8a83dad1ccb59dace31af7c815b Mon Sep 17 00:00:00 2001 From: kenjis Date: Thu, 5 Oct 2023 09:26:45 +0900 Subject: [PATCH 14/16] docs: add changelog --- user_guide_src/source/changelogs/v4.5.0.rst | 4 ++++ user_guide_src/source/concepts/autoloader.rst | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/user_guide_src/source/changelogs/v4.5.0.rst b/user_guide_src/source/changelogs/v4.5.0.rst index 3f509d73431f..282ec793767d 100644 --- a/user_guide_src/source/changelogs/v4.5.0.rst +++ b/user_guide_src/source/changelogs/v4.5.0.rst @@ -116,6 +116,10 @@ Helpers and Functions Others ====== +- **Autoloader:** Autoloading performance when using Composer has been improved; + changing the ``autoload.psr4`` setting in **composer.json** may also improve + the performance of your app. See :ref:`autoloader-composer-support-improve-performance`. + Message Changes *************** diff --git a/user_guide_src/source/concepts/autoloader.rst b/user_guide_src/source/concepts/autoloader.rst index eaec9eaf8693..993f72ab3ddc 100644 --- a/user_guide_src/source/concepts/autoloader.rst +++ b/user_guide_src/source/concepts/autoloader.rst @@ -117,7 +117,7 @@ Improve Performance .. versionadded:: 4.5.0 -When you use Composer, you could improve the performance of autoloading with +When you use Composer, you may improve the performance of autoloading with Composer's classmap dump. Add your ``App`` namespace in your **composer.json**, and run ``composer dump-autoload``. From b52f770e70990f3883d6b67fcbae7f4e9013eccc Mon Sep 17 00:00:00 2001 From: kenjis Date: Fri, 6 Oct 2023 06:11:33 +0900 Subject: [PATCH 15/16] chore: add App namespace in autoload.psr-4 in appstarter composer.json --- admin/starter/composer.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/admin/starter/composer.json b/admin/starter/composer.json index 37c3e5642f29..35b791c3f050 100644 --- a/admin/starter/composer.json +++ b/admin/starter/composer.json @@ -19,6 +19,9 @@ "phpunit/phpunit": "^9.1" }, "autoload": { + "psr-4": { + "App\\": "app/" + }, "exclude-from-classmap": [ "**/Database/Migrations/**" ] From 9a9a5edaf558b04e5387c09f54cfcebef6b482ff Mon Sep 17 00:00:00 2001 From: kenjis Date: Fri, 6 Oct 2023 06:12:20 +0900 Subject: [PATCH 16/16] docs: update description for app namespace --- user_guide_src/source/changelogs/v4.5.0.rst | 6 +- user_guide_src/source/concepts/autoloader.rst | 64 ++++++++++--------- 2 files changed, 38 insertions(+), 32 deletions(-) diff --git a/user_guide_src/source/changelogs/v4.5.0.rst b/user_guide_src/source/changelogs/v4.5.0.rst index 282ec793767d..f109180c8009 100644 --- a/user_guide_src/source/changelogs/v4.5.0.rst +++ b/user_guide_src/source/changelogs/v4.5.0.rst @@ -116,9 +116,9 @@ Helpers and Functions Others ====== -- **Autoloader:** Autoloading performance when using Composer has been improved; - changing the ``autoload.psr4`` setting in **composer.json** may also improve - the performance of your app. See :ref:`autoloader-composer-support-improve-performance`. +- **Autoloader:** Autoloading performance when using Composer has been improved. + Adding the ``App`` namespace in the ``autoload.psr4`` setting in **composer.json** + may also improve the performance of your app. See :ref:`autoloader-application-namespace`. Message Changes *************** diff --git a/user_guide_src/source/concepts/autoloader.rst b/user_guide_src/source/concepts/autoloader.rst index 993f72ab3ddc..cc47162e5c0c 100644 --- a/user_guide_src/source/concepts/autoloader.rst +++ b/user_guide_src/source/concepts/autoloader.rst @@ -64,20 +64,51 @@ The value is the location to the directory the classes can be found in. php spark namespaces +.. _autoloader-application-namespace: + +Application Namespace +===================== + By default, the application directory is namespace to the ``App`` namespace. You must namespace the controllers, libraries, or models in the application directory, and they will be found under the ``App`` namespace. +Config Namespace +---------------- + +Config files are namespaced in the ``Config`` namespace, not in ``App\Config`` as you might +expect. This allows the core system files to always be able to locate them, even when the application +namespace has changed. + +Changing App Namespace +---------------------- + You may change this namespace by editing the **app/Config/Constants.php** file and setting the new namespace value under the ``APP_NAMESPACE`` setting: .. literalinclude:: autoloader/002.php :lines: 2- -You will need to modify any existing files that are referencing the current namespace. +And if you use Composer autoloader, you also need to change the ``App`` namespace +in your **composer.json**, and run ``composer dump-autoload``. -.. important:: Config files are namespaced in the ``Config`` namespace, not in ``App\Config`` as you might - expect. This allows the core system files to always be able to locate them, even when the application - namespace has changed. +.. code-block:: text + + { + ... + "autoload": { + "psr-4": { + "App\\": "app/" <-- Change + }, + ... + }, + ... + } + +.. note:: Since v4.5.0 appstarter, the ``App\\`` namespace has been added to + **composer.json**'s ``autoload.psr-4``. If your **composer.json** does not + have it, adding it may improve your app's autoloading performance. + +You will need to modify any existing files that are referencing the current namespace. ******** Classmap @@ -109,28 +140,3 @@ autoloader will be the first one to get a chance to locate the file. .. note:: Prior to v4.5.0, if the same namespace was defined in both CodeIgniter and Composer, CodeIgniter's autoloader was the first one to get a chance to locate the file. - -.. _autoloader-composer-support-improve-performance: - -Improve Performance -=================== - -.. versionadded:: 4.5.0 - -When you use Composer, you may improve the performance of autoloading with -Composer's classmap dump. - -Add your ``App`` namespace in your **composer.json**, and run ``composer dump-autoload``. - -.. code-block:: text - - { - ... - "autoload": { - "psr-4": { - "App\\": "app/", - }, - ... - }, - ... - }