Skip to content

Commit

Permalink
docs: update description for app namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Oct 5, 2023
1 parent b52f770 commit 9a9a5ed
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 32 deletions.
6 changes: 3 additions & 3 deletions user_guide_src/source/changelogs/v4.5.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
***************
Expand Down
64 changes: 35 additions & 29 deletions user_guide_src/source/concepts/autoloader.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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/",
},
...
},
...
}

0 comments on commit 9a9a5ed

Please sign in to comment.