简体   繁体   中英

Custom attributes in composer.json

Is possible to add/create custom attributes on composer.json?

Like this:

(...)
    "require": {
        "php": ">=7.4"
    },
    'custom': {
        "username": "RahPT",
        "foo": "bar"
    },
(...)

Is possible to add/create custom attributes on composer.json?

(Possible,) Yes, it is a file containing JSON Text (unmarshalled by Composer with json_decode() ).

If you consider to publish your package thought, consult composer validate if your own modification to the JSON Text is eligible for publication.

Also consider forward compatibility: How do you know that at a some time in the future the custom (or any other) keyword gets a meaning in Composer and then your data clashes?

Better use the extra keyword as it is already defined, can contain any data and is per package.

But only put things into composer.json that are related to the package, like the name or other metadata of your project, and keep project configuration files with your project (not in composer.json). Create your own project.json file for example.

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