Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Skip autoload files generation in composer?

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?

like image 773
Ryan Eckert Avatar asked Nov 19 '12 07:11

Ryan Eckert


People also ask

What composer dump autoload does?

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.

What is Classmap in composer json?

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.

How do I update a single package in composer?

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.


2 Answers

There are three autoload related files, each having a different purpose.

  • vendor/autoload.php initializes the autoloaders of composer. Composer offers a autoloaders to enable composer compatible libraries to be load.
  • vendor/composer/autoload_classmap.php this file is used by the classmap autoloader, this is for either libraries that are not even PSR-0 compatible, or production environments (classmap is faster than a lookup through the file system).
  • vendor/composer/autoload_namespaces.php this is the configuration for the PSR-0 autoloading that composer comes with

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.

like image 109
ppetermann Avatar answered Oct 05 '22 04:10

ppetermann


Unfortunately, It doesn't sound like Composer is going to support this feature: https://github.com/composer/composer/issues/1663

like image 22
m14t Avatar answered Oct 05 '22 03:10

m14t