Closed fedys closed 6 years ago
I don't think, the Composer's autoloader creates a map of the modules files, do it? Only the dependency packages are mapped.
I did not realize that :) I use Composer to autoload everything in my projects. It is much faster than Zend autoload implementation. This way you can let Composer generate one single classmap and avoid class map array merging which is expensive. The great feature of Composer autoloading is also caching via APCu (with fallback to classmap if APCu is not available). I use this in production environment and performance gain is really noticeable.
If you know a way to let composer include the module files in its autoloading, I'm eager to hear...
If I include
"autoload": {
"classmap": [
"module/Core/src"
]
}
to composer.json, the files are added to "autoload_static.php"
However, when adding:
"autoload": {
"psr-4": {
"Core\\": "module/Core/src"
}
}
No actual files are added to the "autoload_static.php", only a namespace mapping...
(edit: changed psr-0 to psr-4)
All you need is to add the following:
"psr-0" : {
"Core\\" : "module/Core/src/"
}
in the autoload section. Psr-4 cannot be used here due to the extra /Core directory in the /src Directory. After you call composer dump
the /vendor/composer/autoload_namespaces.php will be modified accordingly (the following line will be added 'Core\\' => array($baseDir . '/module/Core/src')
). I tested this in my development environment and it worked even if I temporarily disabled Core\Module::getAutoloaderConfig()
method.
That will create no classmap. I do not see where the performance gain is....
The classmap is generated via composer dump -o
command.
Additionally you can add:
"config" : {
"apcu-autoloader": true
}
to enable APCu cache, which is the fastest way (at least in my projects in a production mode)
I just found https://getcomposer.org/doc/articles/autoloader-optimization.md
According to that, you will need to run
composer install -o
or set
"config": { "optimize-autoloader": true }
to create the optimized autoloader (including the classmap).
When using autoload-dev section, we could completely get rid of the Zend_Autoloader.
"config" : {
"apcu-autoloader": true
}
can be safely added as well ;)
Will be dealed with in #428
All autoload_classmap.php files could be removed because YAWIK uses Composer autoloader.