如何使用 composer 自动加载文件名后缀为 .class.php 的类?

How can I autoload classes with composer where the filenames are suffixed with .class.php?

我也在为我的课程使用 composer 自动加载器,但我的问题是我的课程文件遵循模式 ClassName.class.php 并且 composer 只能使用 [=14] 加载文件=] 扩展名。

有什么方法可以在composer.json中定义文件模式吗?我正在检查 classmap,但它不支持模式。

类映射自动加载应该是你的朋友,请参阅 https://getcomposer.org/doc/04-schema.md#classmap

只需指定您的文件所在位置的路径,假设您的文件位于 src,例如 src/Foo/Bar.class.php,然后像这样更新您的 composer.json

{
    "autoload": {
        "classmap": [
            "src/"
        ]
    }
}

不过,每次添加新文件时都需要重新生成类映射:

$ composer dump-autoload