Use composer to require only 1 file?

人走茶凉 提交于 2020-01-24 04:05:06

问题


Is it possible to require only 1 file from a composer package?

I need only 1 or few files from a package and it would be pointless to require the whole package which consist of hundred of files when i would use only a few.

Is it possible to do this via composer?


回答1:


It's possible to include specific files in the current package with the files autoloading strategy:

{
    "autoload": {
        "files": [
            "path/to/my/file.php"
        ]
    }
}

If you need to require specific files from a package you installed with composer, this is not possible. Not really needed either, as the files are not loaded into memory unless you use them in your code.

More about files and other autoloading stragegies can be found in the composer docs.



来源:https://stackoverflow.com/questions/35361360/use-composer-to-require-only-1-file

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