Skip to content

Commit 1046de8

Browse files
authored
Merge pull request #8666 from kenjis/docs-autoloader.rst
docs: add and update Autoloader descriptions
2 parents e22b0c5 + d99eba7 commit 1046de8

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

user_guide_src/source/concepts/autoloader.rst

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ classes that your project is using. Keeping track of where every single file is,
1313
hard-coding that location into your files in a series of ``requires()`` is a massive
1414
headache and very error-prone. That's where autoloaders come in.
1515

16+
***********************
1617
CodeIgniter4 Autoloader
1718
***********************
1819

1920
CodeIgniter provides a very flexible autoloader that can be used with very little configuration.
2021
It can locate individual namespaced classes that adhere to
21-
`PSR-4 <https://www.php-fig.org/psr/psr-4/>`_ autoloading
22-
directory structures.
22+
`PSR-4`_ autoloading directory structures.
23+
24+
.. _PSR-4: https://www.php-fig.org/psr/psr-4/
2325

2426
The autoloader works great by itself, but can also work with other autoloaders, like
2527
`Composer <https://getcomposer.org>`_, or even your own custom autoloaders, if needed.
@@ -36,6 +38,7 @@ beginning of the framework's execution.
3638
file name case is incorrect, the autoloader cannot find the file on the
3739
server.
3840

41+
*************
3942
Configuration
4043
*************
4144

@@ -47,16 +50,23 @@ arrays: one for the classmap, and one for PSR-4 compatible namespaces.
4750
Namespaces
4851
==========
4952

50-
The recommended method for organizing your classes is to create one or more namespaces for your
51-
application's files. This is most important for any business-logic related classes, entity classes,
52-
etc. The ``$psr4`` array in the configuration file allows you to map the namespace to the directory
53+
The recommended method for organizing your classes is to create one or more namespaces
54+
for your application's files.
55+
56+
The ``$psr4`` array in the configuration file allows you to map the namespace to the directory
5357
those classes can be found in:
5458

5559
.. literalinclude:: autoloader/001.php
5660

5761
The key of each row is the namespace itself. This does not need a trailing back slash.
5862
The value is the location to the directory the classes can be found in.
5963

64+
By default, the namespace ``App`` is located in the **app** directory, and the
65+
namespace ``Config`` is located in the ``app/Config`` directory.
66+
67+
If you create class files in the locations and according to `PSR-4`_, the autoloader
68+
will autoload them.
69+
6070
.. _confirming-namespaces:
6171

6272
Confirming Namespaces
@@ -89,14 +99,14 @@ You will need to modify any existing files that are referencing the current name
8999
Classmap
90100
========
91101

92-
The classmap is used extensively by CodeIgniter to eke the last ounces of performance out of the system
93-
by not hitting the file-system with extra ``is_file()`` calls. You can use the classmap to link to
94-
third-party libraries that are not namespaced:
102+
If you use third-party libraries that are not Composer packages and are not namespaced,
103+
you can load those classes using the classmap:
95104

96105
.. literalinclude:: autoloader/003.php
97106

98107
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.
99108

109+
****************
100110
Composer Support
101111
****************
102112

0 commit comments

Comments
 (0)