How to define custom autoloader in composer?

吃可爱长大的小学妹 提交于 2019-12-10 13:15:47

问题


I am using Nette Framework which uses its own autoloader. How can I define custom autoloader or just exclude the standard one from composer so I can use my own?


回答1:


Simply don't include it if you don't want to use it. Keep in mind you'll have to handle autoloading on your own.

If your autoloader can work with it, you can use namespaces file generated by composer:

Composer provides its own autoloader. If you don't want to use that one, you can just include vendor/composer/autoload_namespaces.php, which returns an associative array mapping namespaces to directories.

Reference: Autoloading in the composer docs.




回答2:


Alternatively, if you want an additional autoloader, you can update composer.json with:

{
    "autoload": {
        "files": ["src/extra/autoloader.php"]
    }
}

Then run composer dump-autoload to rebuild it. Now when you include vendor/autoload.php it will also load your autoloader.



来源:https://stackoverflow.com/questions/12781276/how-to-define-custom-autoloader-in-composer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!