Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(admin): Document server autoloading and class maps #12024

Merged
merged 1 commit into from
Aug 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions developer_manual/digging_deeper/classloader.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,22 @@ Classloader

The classloader is provided by Nextcloud and loads all your classes automatically. See :ref:`the composer section<app-composer>` if you want to include and autoload 3rd party libraries.

Server autoloading
------------------

Classes of the Nextcloud server use an authoritative class map, and the class map is committed to git.

When you add, move or delete a class file you have to update the autoloaders for the class to be found. The process is slightly different for classes that belong to the server itself, and apps that are included in the server repository:

1. Use ``composer dump-autoload`` to update the server class map.
2. Use ``composer -d apps/dav/composer dump-autoload`` to update the class map of the dav app. The same applies for all other apps that are part of the server repository.

.. tip:: Use git's `patch option <https://git-scm.com/docs/git-add#Documentation/git-add.txt---patch>`_ when adding autoloader files. It allows you to pick only the lines relevant to the classes you added, moved or deleted. E.g. ``git add -p apps/dav/composer``.

.. _app-psr4-autoloader:

PSR-4 autoloading
-----------------
App autoloading
---------------

Nextcloud uses a :ref:`PSR-4 autoloader<psr4>`. The namespace **\\OCA\\MyApp**
is mapped to :file:`/apps/myapp/lib/`. Afterwards normal PSR-4 rules apply, so
Expand Down Expand Up @@ -38,7 +50,7 @@ thereby mapped to :file:`/apps/myapp/tests/`.
.. _app-custom-classloader:

Replacing Nextcloud's autoloader
--------------------------------
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Nextcloud's autoloader for apps is flexible and robust but not always the fastest. You can improve the loading speed of your app by shipping and optimizing a Composer class loader with the app.

Expand Down
Loading