如何为作曲家使用多个自动加载功能?

How to use multiple autoload functions for composer?

我在 autoload-my-func.php 文件中有自定义自动加载器功能。

我想将 vendor/autoload.php - 用于作曲家文件,但只有我的 autoload-my-func.php 用于 类 和我的自定义命名空间。 (My_Custom_Namespace)

I want to use vendor/autoload.php - for composer files, but only my autoload-my-func.php for classes with my custom namespace. (My_Custom_Namespace)

你应该为两者使用 composer 的自动加载器,并在你的 composer.json 文件中定义你的自定义命名空间。如果您受困于设计不佳的遗留系统,并且需要一些东西来弥合愚蠢的鸿沟,直到您可以创建更好的解决方案,那么您应该查看 spl_autoload_register 的文档。具体来说,关于 "if there must be multiple autoload functions, spl_autoload_register() allows for this. It effectively creates a queue of autoload functions, and runs through each of them in the order they are defined." 当您包含作曲家 autoload.php 时,您最终会收到一些对 spl_autoload_register() 的调用,因此只需在包含作曲家后注册您的自定义自动加载器即可。