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.
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!

本文由composer教程栏目给大家介绍关于在Debian11上是怎么一步步安装,以及使用Composer的 ,非常详细哦~希望对需要的朋友有所帮助!

Composer是PHP的依赖管理工具,它允许开发者将第三方库和框架与自己的项目进行集成。它的主要功能包括:1、依赖管理;2、版本控制;3、自动加载;4、扩展开发;5、集成其他工具。它简化了PHP项目的依赖管理过程,确保项目的稳定性和可维护性。通过使用Composer,开发者可以更加高效地管理自己的项目和集成第三方库和框架。

composer修改php路径的方法:1、搜索“composer.bat”并复制到项目文件夹;2、编辑“composer.bat”,将内容修改为“@ECHO OFF php "%~dp0composer.phar" %*”即可。

在PHP开发中,我们经常要处理各种依赖包,这些依赖包可能是其他开发者编写的PHP库文件,也可能是一些第三方工具和框架。为了方便管理这些依赖包,我们可以使用Composer来进行相关的安装和管理工作。Composer是一个开源的PHP依赖管理工具,它可以帮助我们自动化安装、更新和卸载PHP依赖包。通过Composer,我们可以轻松地管理我们应用中的不同依赖,同

随着PHP的日益流行,PHP开发人员面临着许多挑战,其中包括代码管理、可重用性和依赖性管理。这些问题可以使用包管理器来解决,而Composer是PHP最受欢迎的包管理器之一。在本文中,我们将探讨使用Composer和PHP包管理器的最佳实践,从而提高您的PHP开发效率和代码质量。何为Composer?Composer是一款PHP包管理器,它可以轻松管理PHP

Composer是一个PHP的依赖管理工具,可以帮助开发者有效地管理项目中的依赖关系。通过Composer,我们可以轻松地引入第三方库、框架以及其他项目所需的各种资源。创建一个Composer项目非常简单,只需按照以下步骤进行操作:首先需要确保在本地已经安装了Composer。可以在终端中运行composer-v命令来确认是否已经安装成功。在项目的根目录中

Composer是一个PHP的依赖管理工具,它可以帮助开发者在PHP项目中管理和安装依赖的库文件。Composer通过一个中央化的存储库来管理所有的依赖库文件,这个存储库包含了各种可用的依赖库的信息和版本信息。开发人员可以在项目中使用Composer来声明所需的依赖库,然后Composer会自动从存储库中获取并安装这些依赖库的最新版本到项目中的某个目录中。

随着现代Web开发技术的迅速发展,依赖管理成为了一个越来越重要的议题。无论是前端还是后端开发,我们需要引入各种各样的库和框架来达到更高的开发效率和更好的应用性能。而这些库和框架的组织、版本控制和安装管理问题则成为了一个值得思考和解决的难题。Composer就是为了解决PHP应用开发中依赖管理问题而推出的一个开源工具。它的作用类似于Node.js


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Zend Studio 13.0.1
Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 English version
Recommended: Win version, supports code prompts!
