使用composer仅需要1个文件? [英] Use composer to require only 1 file?

查看:48
本文介绍了使用composer仅需要1个文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

能否仅从Composer软件包中获取1个文件?

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?

推荐答案

可以在 文件自动加载策略:

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

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

如果您需要使用composer安装的软件包中的特定文件,则不可能.同样也不需要,因为除非您在代码中使用文件,否则文件不会加载到内存中.

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.

这篇关于使用composer仅需要1个文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆