Will you use composer to add automatic loading function to your own class library?

藏色散人
Release: 2020-07-18 13:13:01
forward
2946 people have browsed it

下面由composer教程栏目给大家介绍用composer给自己的类库加上自动加载功能的方法,希望对需要的朋友有所帮助!

Will you use composer to add automatic loading function to your own class library?

最近在搞api架构设计,要与之前的代码隔离开来,之前的代码种种原因没有不是用的类似的自动加载,用了composer发现真的做的非常方便,自动加载功能及其好用,所以在想能不能直接利用composer的自动加载来为自己写的类库提供自动加载功能!

百度谷歌StackOverflow,该有的答案总是会有的!

假设你已经会composer的基本使用。

方法:

在composer.json中添加类似代码:

    "autoload": { //自动加载
        "psr-4": { //申明遵循psr-4规范
            "api\\": "api" // namespace(根): 文件夹映射目录(基于composer.json所在文件夹)
        }
    }
Copy after login

到composer.json所在目录,运行:

$ composer dump-autoload
Copy after login

之后你就可以使用composer的类自动加载自己的类库了。

The above is the detailed content of Will you use composer to add automatic loading function to your own class library?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template