From fb3d5301268ba4fc51a26ad066bc401611d2dc89 Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 27 Mar 2024 13:17:49 +0900 Subject: [PATCH 1/4] docs: fix section title marks --- user_guide_src/source/concepts/autoloader.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/user_guide_src/source/concepts/autoloader.rst b/user_guide_src/source/concepts/autoloader.rst index 1a354208bf17..5fb281a1b67e 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,6 +37,7 @@ beginning of the framework's execution. file name case is incorrect, the autoloader cannot find the file on the server. +************* Configuration ************* @@ -97,6 +99,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 43b81c46e2c6a6068941ed5f252021f027a56dc9 Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 27 Mar 2024 13:43:49 +0900 Subject: [PATCH 2/4] docs: add empty line --- user_guide_src/source/concepts/autoloader.rst | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/user_guide_src/source/concepts/autoloader.rst b/user_guide_src/source/concepts/autoloader.rst index 5fb281a1b67e..e21245317599 100644 --- a/user_guide_src/source/concepts/autoloader.rst +++ b/user_guide_src/source/concepts/autoloader.rst @@ -49,9 +49,10 @@ arrays: one for the classmap, and one for PSR-4 compatible namespaces. Namespaces ========== -The recommended method for organizing your classes is to create one or more namespaces for your -application's files. This is most important for any business-logic related classes, entity classes, -etc. The ``$psr4`` array in the configuration file allows you to map the namespace to the directory +The recommended method for organizing your classes is to create one or more namespaces +for your application's files. + +The ``$psr4`` array in the configuration file allows you to map the namespace to the directory those classes can be found in: .. literalinclude:: autoloader/001.php From 9f9634a5e2528d057a0ebc673906d136373914a0 Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 27 Mar 2024 13:44:18 +0900 Subject: [PATCH 3/4] docs: add explanation --- user_guide_src/source/concepts/autoloader.rst | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/user_guide_src/source/concepts/autoloader.rst b/user_guide_src/source/concepts/autoloader.rst index e21245317599..3c9f1f6ceb44 100644 --- a/user_guide_src/source/concepts/autoloader.rst +++ b/user_guide_src/source/concepts/autoloader.rst @@ -19,8 +19,9 @@ CodeIgniter4 Autoloader CodeIgniter provides a very flexible autoloader that can be used with very little configuration. It can locate individual namespaced classes that adhere to -`PSR-4 `_ autoloading -directory structures. +`PSR-4`_ autoloading directory structures. + +.. _PSR-4: https://www.php-fig.org/psr/psr-4/ The autoloader works great by itself, but can also work with other autoloaders, like `Composer `_, or even your own custom autoloaders, if needed. @@ -60,6 +61,12 @@ those classes can be found in: The key of each row is the namespace itself. This does not need a trailing back slash. The value is the location to the directory the classes can be found in. +By default, the namespace ``App`` is located in the **app** directory, and the +namespace ``Config`` is located in the ``app/Config`` directory. + +If you create class files in the locations and according to `PSR-4`_, the autoloader +will autoload them. + .. _confirming-namespaces: Confirming Namespaces From d99eba7b7d2f1dc554a2ff899fc61eb71da6eb58 Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 27 Mar 2024 13:44:38 +0900 Subject: [PATCH 4/4] docs: replace description CodeIgniter seems to use the classmap only for the third-party libraries that are included in CI4 core. --- user_guide_src/source/concepts/autoloader.rst | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/user_guide_src/source/concepts/autoloader.rst b/user_guide_src/source/concepts/autoloader.rst index 3c9f1f6ceb44..5b4daab518a5 100644 --- a/user_guide_src/source/concepts/autoloader.rst +++ b/user_guide_src/source/concepts/autoloader.rst @@ -99,9 +99,8 @@ You will need to modify any existing files that are referencing the current name Classmap ======== -The classmap is used extensively by CodeIgniter to eke the last ounces of performance out of the system -by not hitting the file-system with extra ``is_file()`` calls. You can use the classmap to link to -third-party libraries that are not namespaced: +If you use third-party libraries that are not Composer packages and are not namespaced, +you can load those classes using the classmap: .. literalinclude:: autoloader/003.php