search
HomeDevelopment ToolscomposerDetailed explanation of composer.json file

Detailed explanation of composer.json file

Aug 03, 2019 pm 05:11 PM
composerjson

In the current mainstream PHP framework, we will find a file named composer.json. You can see the composer.json file in the downloaded composer package. The following column is composer usage tutorial. We will introduce the function, properties and functions of each property of the composer.json file.

Detailed explanation of composer.json file

Function:

The composer.json file defines the dependencies of your current project, as well as some related information about the dependencies

Common Attribute description:

1: name

represents the name of the package, consisting of the author name and the project name, separated by /

For example:

yiisoft/ yii2-app-basic

The package name can contain any characters, including spaces, and is not case sensitive (yiisoft/yii2-app-basic and Yiisoft/Yii2-app-basic will be considered the same package) . To simplify installation, it is recommended to define a short name that does not contain non-alphanumeric characters or spaces

The name attribute is a required attribute of the composer.json file

2: description

Indicates a short description of the package, usually this is a one-line introduction.

description This attribute is a necessary attribute of the composer.json file

3: version

Indicates the version of the package

The format of the version must follow X.Y.Z or vX.Y.Z, optional suffix -dev, -patch (-p), -alpha (-a), -beta (-b) or -RC, patch, alpha, beta and RC suffix can also be followed by a number

For example:

1.0.0

1.0.0-dev

version This attribute is the composer.json file Non-essential attributes, generally can be omitted

4: type

indicates the type of package, the default is library

Composer natively supports the following 4 types:

library: Default type, it only requires copying files to the vendor directory.

project: The current package is a project, not a library. For example, the type value of the composer.json file in the Yii framework is project

metapackage: An empty package that contains requirements and will trigger its installation, but does not contain files and will not write anything to the system. Therefore this type of installation does not require a dist or source.

composer-plugin: A package with the installation type composer-plugin, which has a custom installation type and can provide an installler for other packages

We can also define a custom type

The type attribute is a non-essential attribute of the composer.json file

5: keywords

Represents a set of package-related keywords used for search and filtering

keywords This attribute is a non-essential attribute of the composer.json file

6: homepage

Represents the URL address of the project website

Homepage This attribute is the composer.json file Non-mandatory attributes

7: readme

represents the absolute path of the README document

The readme attribute is a non-mandatory attribute of the composer.json file

8 : time

indicates the version release time of the package

must be YYYY-MM-DD or YYYY-MM-DD HH:MM:SS format

time This attribute is composer Optional attributes of the .json file

9: license

represents the license of the package, which can be a string or a string array

The most common license The recommended notation is as follows:

Apache-2.0
BSD-2-Clause
BSD-3-Clause
BSD-4-Clause
GPL-2.0-only / GPL-2.0-or-later
GPL-3.0-only / GPL-3.0-or-later
LGPL-2.1-only / LGPL-2.1-or-later
LGPL-3.0-only / LGPL-3.0-or-later
MIT

If you want to know the license related information, you can refer to: https://spdx.org/licenses/

license This attribute is a non-specific property of the composer.json file Required attribute, but it is recommended to provide this information

10: authors

represents the author of the package, which is an object array.

Each author object can contain the following attributes:

name: The name of the author. Usually the real name.

email: The author’s email address.

homepage: URL address of the author’s personal website.

role: The role the author plays in the project (such as developer or translator).

Example:

"authors": [
        {
            "name": "huaweichenai",
            "email": "243681093@qq.com",
            "homepage": "https://www.wj0511.com/",
            "role": "Developer"
        }
    ],

The authors attribute is a non-essential attribute of the composer.json file, but it is recommended to provide this information

11: support

means Get the information object supporting the project.

Object information must include the following attributes:

email: The project supports email addresses.

issues: The URL address of the tracking issue.

forum: Forum URL address.

wiki: Wiki URL address.

irc: IRC chat channel address, as irc://server/channel.

source: URL browsing or download source.

docs: URL of the file.

rss: URL of RSS feed.

Example:

"support": {
        "issues": "https://github.com/yiisoft/yii2/issues?state=open",
        "forum": "http://www.yiiframework.com/forum/",
        "wiki": "http://www.yiiframework.com/wiki/",
        "irc": "irc://irc.freenode.net/yii",
        "source": "https://github.com/yiisoft/yii2"
    },

The support attribute is a non-essential attribute of the composer.json file

12: require

means it is required List of installed dependent packages. These packages must meet the conditions, otherwise they will not be installed.

Example:

"require": {
        "yiisoft/yii2": "*"
    },

requireThis attribute is a non-essential attribute of the composer.json file

13 :require-dev

Indicates the list of dependent packages when developing or running tests

require-dev This attribute is a non-essential attribute of the composer.json file

14: autoload

Indicates PHP auto-loading mapping

Supports PSR-4 and PSR-0 auto-loading, class mapping and files references.

推荐使用 PSR-4 规范(添加类时,无需重新生成自动加载映射)

例:

"autoload": {
        "psr-4": {
            "huaweichenai\\discern\\": "src"
        }
    }

表示自动加载当前的src目录

autoload这个属性是composer.json文件的非必须属性

15:minimum-stability

这个属性定义了按稳定性过滤包的默认值,默认为stable。所以如果你依赖dev 包,你应该在你的文件中指定。

所有包都将根据稳定性检出相应的版本,那些低于 minimum-stability 设置的版本将被自动忽略。

minimum-stability这个属性是composer.json文件的非必须属性

16:repositories 

表示使用自定义的安装源

Composer 默认只使用 packagist 的安装源。通过定义 repositories 你可以从任何其他地方获取包

例:

"repositories": {
        "0": {
            "type": "composer",
            "url": "https://asset-packagist.org"
        },
        "packagist": {
            "type": "composer",
            "url": "https://packagist.phpcomposer.com"
        }
    }

repositories 这个属性是composer.json文件的非必须属性

20:config

表示一组配置选项。它仅用于项目

config属性向有很多的属性,了解config下面的相关属性,参考:https://laravel-china.org/docs/composer/2018/06-config/2087

config属性中有一个常见的属性

process-timeout:请求过程超时设置

config 这个属性是composer.json文件的非必须属性

21:scripts 

表示Composer 允许再安装过程的各个部分中执行脚本

script相关信息参考:https://laravel-china.org/docs/composer/2018/scripts/2095

例:

"scripts": {
            //当项目里有 composer.lock 文件的情况下调用 install 命令后执行
        "post-install-cmd": [
            "yii\\composer\\Installer::postInstall"
        ],
        //当 create-project  命令被执行后执行
        "post-create-project-cmd": [
            "yii\\composer\\Installer::postCreateProject",
            "yii\\composer\\Installer::postInstall"
        ]
    },

scripts  这个属性是composer.json文件的非必须属性

22:extra

表示scripts 使用的任意扩展数据

例:

"extra": {
        "yii\\composer\\Installer::postCreateProject": {
            "setPermission": [
                {
                    "runtime": "0777",
                    "web/assets": "0777",
                    "yii": "0755"
                }
            ]
        },
        "yii\\composer\\Installer::postInstall": {
            "generateCookieValidationKey": [
                "config/web.php"
            ]
        }
    },

extra这个属性是composer.json文件的非必须属性

The above is the detailed content of Detailed explanation of composer.json file. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:wj0511. If there is any infringement, please contact admin@php.cn delete
Composer with AI: Code Suggestions and InsightsComposer with AI: Code Suggestions and InsightsApr 22, 2025 am 12:05 AM

ComposerwithAI is a tool that uses AI to improve the programming experience. 1) It provides real-time suggestions and bug fixes by analyzing code structure, syntax and pattern. 2) Advanced features include code refactoring, performance optimization and security checking. 3) When using, you can adjust the configuration, provide feedback and combine other tools to solve common problems.

Composer: An Introduction to the PHP Dependency ManagerComposer: An Introduction to the PHP Dependency ManagerApr 21, 2025 am 12:02 AM

Composer is a dependency management tool for PHP, which is used to manage libraries and packages required by projects. 1) It defines dependencies through composer.json file, 2) installs and updates using command line tools, 3) automates the dependency management process, improves development efficiency, 4) supports advanced functions such as dynamically adding dependencies and automatic loading, 5) Ensures consistency of the team environment through composer.lock file.

The Purpose of Composer: Managing Dependencies EfficientlyThe Purpose of Composer: Managing Dependencies EfficientlyApr 20, 2025 am 12:04 AM

Composer is a dependency management tool for PHP, and manages project dependencies through composer.json and composer.lock files. 1. Create the composer.json file and run the composerinstall installation dependency. 2. Use composerrequire to add new dependencies. 3. Configure autoload to implement automatic loading of classes. 4. Use composerdiagnose to check the health status of the project. 5. Optimize dependency management: specify the package name update, use composerdump-autoload-o to optimize the autoloader, use composerinstall--no-d in the production environment

Composer and AI: New Possibilities in PHP DevelopmentComposer and AI: New Possibilities in PHP DevelopmentApr 19, 2025 am 12:03 AM

The combination of AI and Composer can improve PHP development efficiency and security. Specifically reflected in: 1. Dependency analysis and optimization: AI can predict dependencies and reduce conflicts. 2. Automated security checks: AI can identify security vulnerabilities, and it is recommended to update them. 3. Code generation and optimization: AI can automatically generate and optimize related code.

Using Dicr/Yii2-Google to integrate Google API in YII2Using Dicr/Yii2-Google to integrate Google API in YII2Apr 18, 2025 am 11:54 AM

VprocesserazrabotkiveB-enclosed, Мнепришлостольностьсясзадачейтерациигооглапидляпапакробоглесхетсigootrive. LEAVALLYSUMBALLANCEFRIABLANCEFAUMDOPTOMATIFICATION, ČtookazaLovnetakProsto, Kakaožidal.Posenesko

How to use Composer to resolve JSON Schema verification issuesHow to use Composer to resolve JSON Schema verification issuesApr 18, 2025 am 11:51 AM

I'm having a tricky problem when developing a Symfony-based application: how to effectively validate JSON data format. Initially, I tried using manual verification code, but this was not only complicated, but also error-prone. After some exploration, I discovered a Composer package called ptyhard/json-schema-bundle, which brought great convenience and efficiency to my project.

Use Composer to solve the dilemma of recommendation systems: andres-montanez/recommendations-bundleUse Composer to solve the dilemma of recommendation systems: andres-montanez/recommendations-bundleApr 18, 2025 am 11:48 AM

When developing an e-commerce website, I encountered a difficult problem: how to provide users with personalized product recommendations. Initially, I tried some simple recommendation algorithms, but the results were not ideal, and user satisfaction was also affected. In order to improve the accuracy and efficiency of the recommendation system, I decided to adopt a more professional solution. Finally, I installed andres-montanez/recommendations-bundle through Composer, which not only solved my problem, but also greatly improved the performance of the recommendation system. You can learn composer through the following address:

How to quickly build Fecmall advanced project templates using ComposerHow to quickly build Fecmall advanced project templates using ComposerApr 18, 2025 am 11:45 AM

When developing an e-commerce platform, it is crucial to choose the right framework and tools. Recently, when I was trying to build a feature-rich e-commerce website, I encountered a difficult problem: how to quickly build a scalable and fully functional e-commerce platform. I tried multiple solutions and ended up choosing Fecmall's advanced project template (fecmall/fbbcbase-app-advanced). By using Composer, this process becomes very simple and efficient. Composer can be learned through the following address: Learning address

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor