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?


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.


    不幸的是,听起来Composer不会支持这个功能:https://github.com/composer/composer/issues/1663


    就我个人而言,我将这些文件添加到.gitignore,因为我正在处理的项目有一个自动加载器,可以正常工作

    链接地址: http://www.djcxy.com/p/66254.html

    上一篇: 带轨的mongodb,通过数组中的id查找

    下一篇: 在作曲家中跳过自动载入文件的生成?