This project simulates PHP autoloading system to use it in Semantic. It is composed of 3 parts:
- An EDE project,
ede-php-autoload
, that defines autoloading configuration for a project. It is able to parsecomposer.json
files to extract autoloading information from it - A SemanticDB backend that can find a tag by name using the
autoload information of the current
ede-php-autoload
project - A minor mode,
ede-php-autoload-mode
, that enables the SemanticDB backend for a buffer.
Let’s assume we have a project located at /home/me/my-project
. It
has 3 namespaces:
MyFirstNs
, located atsrc/MyFirstNs
, and uses the PSR-0 normMySecondNs
, located atsrc/MySecondNs
, and uses the PSR-4 normThirdPartyNs
, located atvendor/third-party/src
, and uses the PSR-4 norm
Defining this project and its autoload information is done like this:
(ede-php-autoload-project "My project"
:file "/home/me/my-project/main.php"
:class-autoloads '(:psr-0 (("MyFirstNs" . "src/MyFirstNs"))
:psr-4 (("MySecondNs" . "src/MySecondNs")
("ThirdPartyNs" . "vendor/third-party/src"))))
If you have a composer.json
at the root of your project, its
autoload information (and also the one in the composer dependencies)
will be merged with the information you put in :class-autoloads
.
If your composer.json
contains all the autoload information, and
you have nothing to add in :class-autoloads
, you don’t have to
define an EDE project by hand. It will be automatically created when
you visit a file in your project.
(add-hook 'php-mode-hook #'ede-php-autoload-mode)
Name | Description |
---|---|
M-x ede-php-autoload-reload-autoloads | Similar to the reindexation in IDEs. Use it when your composer configuration changed to reload the autoloads. |
This project is released under the GPL v3 license. See GPL
for details.