简体   繁体   中英

Configuring class autoloading in composer

there is a project on Github that works stably. Below is a composer file:

{
    "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"
        }
    }
}

The problem is that after each successful installation of the project through the composer, you have to do the following command:

>>> composer dump-autoload -o

After that, all all classes will work correctly. Log from the console:

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

Question: how do I avoid entering this command every time, and everything worked correctly during normal installation?

The problem was solved by replacing the PSR-4 to classmap . Thanks @MagnusEriksson.

Composer file:

{
    "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"]
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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