cross-solution / YAWIK

YAWIK is a web application. It can be used as an ATS applicant tracking system or as a jobboard.
https://yawik.org
MIT License
124 stars 67 forks source link

Do we still need autoload_classmap.php files? #419

Closed fedys closed 6 years ago

fedys commented 7 years ago

All autoload_classmap.php files could be removed because YAWIK uses Composer autoloader.

TiSiE commented 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.

fedys commented 6 years ago

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.

TiSiE commented 6 years ago

If you know a way to let composer include the module files in its autoloading, I'm eager to hear...

TiSiE commented 6 years ago

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)

fedys commented 6 years ago

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.

TiSiE commented 6 years ago

That will create no classmap. I do not see where the performance gain is....

fedys commented 6 years ago

The classmap is generated via composer dump -o command.

fedys commented 6 years ago

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)

TiSiE commented 6 years ago

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.

fedys commented 6 years ago
"config" : {
    "apcu-autoloader": true
}

can be safely added as well ;)

TiSiE commented 6 years ago

Will be dealed with in #428