简体   繁体   English

psr-4如何在没有类/名称空间的情况下加载文件

[英]psr-4 how to load files without class / namespace

I have a bunch of php files 我有一堆php文件

each file contains one function 每个文件包含一个功能

no class 没课

no namespace 没有名称空间

just global functions. 只是全局功能。

How can I load those files easily with composer? 如何使用Composer轻松加载这些文件? with psr-4 autoloader or any similar option so I don't have to require() all the time all files 使用psr-4自动装带器或任何类似的选项,因此我不必一直都require()所有文件

Composer has support for autoloading functions. Composer支持自动加载功能。 The only caveat is the functions are always included, they aren't loaded on demand. 唯一需要注意的是,这些功能始终包含在内,而并非按需加载。

{
    "autoload": {
        "files": ["src/MyLibrary/functions.php", "foo/bar/baz.php"]
    }
}

https://getcomposer.org/doc/04-schema.md#files https://getcomposer.org/doc/04-schema.md#files

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM