Home > Development Tools > composer > What does Composer look like in your production environment?

What does Composer look like in your production environment?

藏色散人
Release: 2021-01-26 16:10:01
forward
2885 people have browsed it

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"
    ]
}
Copy after login

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

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

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

命令篇

详细命名请参考 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!

Related labels:
source:learnku.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template