So - I have a simple PCR0 auto-loader in my bootstrap.php, that should load any PCR0 compatible library class from vendors directory...
spl_autoload_register( function( $classname ) {
$path = preg_match( '/\\\\/', $classname )
? str_replace( '\\', DIRECTORY_SEPARATOR, $classname )
: str_replace( '_', DIRECTORY_SEPARATOR, $classname );
$file = VENDORS_PATH . DIRECTORY_SEPARATOR . $path . '.php';
if ( file_exists( $file ) ) {
require_once( $file );
}
});
I'm not sure if I understand why composer generates auto-loading files in vendors directory (namely composer directory and autoload.php file) ?
Can I stop Composer from generating those auto-loader files? or am I missing something? I don't think I need them?
Composer dump-autoload: The composer dump-autoload will not download any new thing, all it does is looking for all the classes and files it needs to include again.
This map is built by scanning for classes in all . php and . inc files in the given directories/files. You can use the classmap generation support to define autoloading for all libraries that do not follow PSR-0/4. To configure this you specify all directories or files to search for classes.
To update your packagesNavigate to the root of your git repo, where your composer. json file is. Run composer update (on your local machine) to update the required packages and re-generate a composer. lock file.
There are three autoload related files, each having a different purpose.
Now you mentioned that you have your own PSR-0 classloader, which you are not supposed to use for composer dependencies - you are simply supposed to require/include the vendor/autoload.php and have composer take care of the rest.
This is why there is no option to disable the generation of the autoloading files. In the end composer is supposed to enable you to use the library installed, and enables you by providing all loading you need.
Unfortunately, It doesn't sound like Composer is going to support this feature: https://github.com/composer/composer/issues/1663
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With