search
HomeDevelopment ToolscomposerWhat does Composer look like in your production environment?

The following column will introduce you to the Composer generation environment from the composer tutorial column, I hope it will be helpful to friends in need!

What does Composer look like in your production environment?

composer analysis

If you are in a hurry, please go directly to the last command

composer configuration items

For specific details of each configuration item, please refer to the Composer official website

Configuration list

##Installation Type5Keywords6Project Homepage7Version Release Time8License Agreement 9author10Support, obtain the related information objects supported by the project. 11Auto-loaded package##12require-dev13conflict 15autoloadpsr-4psr-0classmapfile##1617##target-dirminimum-stabilityalphabetaRCstable20repositoriesconfigvendor -dirextra24binarchiveDevelopment configuration details11. Meaning
ID Configuration Item Description
1 name The name of the package, It includes the vendor name and project name, separated by /.
2 description Package description
3 version Version
4 type
keywords
homepage
time
license
authors
support
require
Package automatically loaded under DEV
The packages in this list conflict with this version of the current package. They will not be allowed to be installed at the same time Package good work. These are just messages and are displayed after the dependent packages have been installed to give your users a suggestion as to which more packages they can add.
Automatic loading, there are four loading mechanisms
include-pathRetain tradition, it is not recommended to use
to define the current package Installation target folder 18
When installing the package, filter the package by stability by default Behavior, dev
Optional 19prefer-stableWhen installing packages, give priority to using more stable package versions, "prefer-stable": true
Use custom package resource libraries. By default composer only uses packagist as the package repository. By specifying a resource library, you can obtain resource bundles from elsewhere. 21
Configuration parameters, eg: process-timeout
22 scripts Composer allows you to hook scripts at various stages during the installation process . 23
Any extra data for use by scripts.
This attribute is used to mark a group of files that should be considered binary scripts. They will It is soft-linked to the directory marked by the bin-dir attribute (in the config object) for calling by other dependent packages. 25
These options are used when creating a package archive.
require Identifier
Instance

##^The latest installed Version Install the latest version of laravel-cors~ Install laravel-cors

12. require-dev

  1. composer install 会安装require-dev中的包,require中的包
  2. composer install --no-dev 只会安装require中的包

22. scripts

"scripts": {
    "post-root-package-install": [
        "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
    ],
    "post-create-project-cmd": [
        "@php artisan key:generate"
    ],
    "post-autoload-dump": [
        "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
        "@php artisan package:discover"
    ]
}

scripts 是自定义执行SHELL命令,如上代码中,执行post-root-package-install 执行复制文件。

15 autoload

PHP 自动加载文件,分别有四种加载机制 psr-4 psr-0 classmap file

修改完 autoload 的内容之后要记得执行composer dump-autoload 来重新生成加载文件

prs-4
  1. 该目录下的 PHP 文件 采用 PSR-4 自动加载标准
  2. Composer会将该结构下的文件映射关系写入 autoload_classmap.php
"autoload": {
    "psr-4": {
        "App\\": "app/"
    }

}
prs-0
  1. 该目录下的 PHP 文件 采用 PSR-0 自动加载标准
  2. Composer会将该结构下的文件映射关系写入 autoload_namespaces.php
"autoload": {
    "psr-4": {
        "Cx\\": "prs0/"
    }

}
classmap
  1. Composer 加载 lib/ 目录下的所有文件,放入到 autoload_classmap.php
{
    "classmap":["lib/"]
}
file
  1. Composer 加载 src/test.php 该文件,放入到 autoload_files.php
{
    "files":["src/test.php"]
}

命令篇

详细命名请参考 Composer 命令行

composer install

先安装composer.lock 文件中packages中的版本;即使composer.jsoncomposer.lock 中版本不一致

What does Composer look like in your production environment?

What does Composer look like in your production environment?

composer update

先安装composer.json的版本,并且更新composer.lockpackages 中的版本

What does Composer look like in your production environment?

你生产环境的 composer 是这样吗?

composer dump-autoload

"barryvdh/laravel-cors": "^0.10.0"
Identifies the last interval version installed "barryvdh/laravel-cors": "~0.10.0", 0.10.0-0.10.9
CMD 说明 应用场景
composer dump-autoload 打印自动加载索引,就是将 autoload 中的各项加载到本该指定的目录。 开发环境 你更新了 autoload 中的各项,
composer dump-autoload -o 转换 PSR-0/4 autoloading 到 classmap 获得更快的载入速度 适用于生产环境
composer dump-autoload -o --no-dev 禁用 autoload-dev 规则 适用于生产环境
composer dump-autoload --classmap-authoritative 只加载 ClassMap中的文件,必到磁盘文件系统进行任何检查 适用于生产环境

因此生产请使用 composer dump-autoload -o --no-dev --classmap-authoritative

The above is the detailed content of What does Composer look like in your production environment?. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:learnku. If there is any infringement, please contact admin@php.cn delete
The Integration of AI into Composer: Exploring PotentialThe Integration of AI into Composer: Exploring PotentialMay 01, 2025 am 12:02 AM

AI can show its strengths in the field of music creation. 1) AI generates music through machine learning and deep learning, enhancing diversity and innovation. 2) AI composers can assist composers and provide inspiration and creativity. 3) In actual applications, performance needs to be optimized to solve the problems of coherence and innovation in the generation of music.

Composer's Purpose: Managing Project Dependencies in PHPComposer's Purpose: Managing Project Dependencies in PHPApr 30, 2025 am 12:01 AM

We need Composer because it can effectively manage dependencies of PHP projects and avoid the hassle of version conflicts and manual library management. Composer declares dependencies through composer.json and uses composer.lock to ensure the version consistency, simplifying the dependency management process and improving project stability and development efficiency.

Composer: Aiding PHP Development Through AIComposer: Aiding PHP Development Through AIApr 29, 2025 am 12:27 AM

AI can help optimize the use of Composer. Specific methods include: 1. Dependency management optimization: AI analyzes dependencies, recommends the best version combination, and reduces conflicts. 2. Automated code generation: AI generates composer.json files that conform to best practices. 3. Improve code quality: AI detects potential problems, provides optimization suggestions, and improves code quality. These methods are implemented through machine learning and natural language processing technologies to help developers improve efficiency and code quality.

Becoming a Composer: Training, Education, and ExperienceBecoming a Composer: Training, Education, and ExperienceApr 28, 2025 am 12:11 AM

To become a composer, you need to master music theory, harmonization, counterpoint, and be familiar with the tone and performance skills of the instrument. Composers express emotions and stories through music, and the creative process involves the construction and improvement of ideas to works.

Identifying a Composer: The Essential ElementsIdentifying a Composer: The Essential ElementsApr 27, 2025 am 12:27 AM

The key steps to identifying a composer include: 1) analyzing the composer's stylistic characteristics, such as Beethoven's drama and power; 2) understanding the composer's historical background and cultural influence, such as Bach's Baroque style; 3) comprehensively analyzing the melody, harmony, rhythm and structure of the work to avoid misjudgment caused by relying solely on a single element.

Composer: The Future of AI in PHP DevelopmentComposer: The Future of AI in PHP DevelopmentApr 26, 2025 am 12:10 AM

Composer'sfutureinPHPdevelopmentwithAIincludes:1)AI-enhanceddependencymanagementforsuggestinglibraries,2)AI-drivencodegenerationfortailoredboilerplate,and3)predictivemaintenanceforupdatesandpatches,butfaceschallengeslikedataprivacyandAIbias.

The Skills and Qualities of a Composer: An OverviewThe Skills and Qualities of a Composer: An OverviewApr 25, 2025 am 12:03 AM

Becoming a successful composer requires skills such as music theory, instrumental performance and sound design, as well as keen inspiration to capture and constant work modification. Composers use these skills and traits to transform emotions and thoughts into musical works, which resonates with their listeners.

Composer's Qualifications: Assessing ProficiencyComposer's Qualifications: Assessing ProficiencyApr 24, 2025 am 12:15 AM

Composer proficiency can be evaluated in the following four aspects: 1) Understand basic concepts, such as packages, dependencies and version control; 2) Master core functions, including parsing composer.json, solving dependencies, downloading packages and generating autoload files; 3) Proficient in using basic and advanced commands, such as composerinstall, update, require, and dump-autoload; 4) Apply best practices, such as using composer.lock files, optimizing autoload configuration, and regularly cleaning caches.

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

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

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 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.