繁体   English   中英

在 Composer 中配置类自动加载

[英]Configuring class autoloading in composer

Github 上有一个稳定运行的项目 下面是一个作曲家文件:

{
    "name": "wnull/userbars-warface-generator",
    "description": "Simple and free library to generate userbars game Warface",
    "keywords": [
        "wf",
        "warface",
        "generator",
        "userbars"
    ],
    "type": "library",
    "license": "MIT",
    "require": {
        "php": ">=7.1"
    },
    "autoload": {
        "psr-4": {
            "WF\\": "src/WF"
        }
    }
}

问题是每次通过composer成功安装项目后,都要执行如下命令:

>>> composer dump-autoload -o

之后,所有类都将正常工作。 从控制台登录:

C:\hangry>composer require wnull/userbars-warface-generator
Using version ^1.0 for wnull/userbars-warface-generator
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
  - Installing wnull/userbars-warface-generator (v1.0): Loading from cache
Writing lock file
Generating autoload files

C:\hangry>
C:\hangry>composer dump-autoload -o
Generated optimized autoload files containing 6 classes

问题:如何避免每次都输入此命令,并且在正常安装过程中一切正常?

通过将PSR-4替换为classmap解决了该问题。 谢谢@MagnusEriksson。

作曲家文件:

{
    "name": "wnull/userbars-warface-generator",
    "description": "Simple and free library to generate userbars game Warface",
    "keywords": [
        "wf",
        "warface",
        "generator",
        "userbars"
    ],
    "type": "library",
    "license": "MIT",
    "require": {
        "php": ">=7.1"
    },
    "autoload": {
        "classmap": ["src/WF"]
    }
}

暂无
暂无

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

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