Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Correctly install the Composer expansion pack

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces the correct installation of Composer expansion package, the article is very detailed, has a certain reference value, interested friends must read it!

Problem description

We often add extension packs to existing projects, sometimes due to misguided documentation, as shown in the following figure from this document:

The composer update command, in our current logic, could do a lot of damage to the project.

Because the logic of composer update is to update all expansion packs to the latest version according to the expansion pack version rules specified by composer.json, note that all expansion packs, for example, you used monolog at the beginning of the project, and the configuration information at that time was

"monolog/monolog": "1.*"

Install is monolog version 1.1, and now, more than a month later, monolog is 1.2, run the command directly updated to 1.2, then the project has not been tested, the project suddenly become very unstable, the situation is sometimes worse than this, especially in a huge project, you do not write a complete coverage of the project test, what is broken you do not know.

Which command should be used? Install, update or require?

Let's explain them one by one.

Simple explanation

Composer install-if you have composer.lock files, install them directly, otherwise install the latest expansion packs and dependencies from composer.json; composer update-install the latest expansion packs and dependencies from composer.json; composer update vendor/package-from composer.json or corresponding package configuration and update to the latest; composer require new/package-add installation new/package, you can specify a version, such as composer require new/package ~ 2.5.

Process flow

Let's introduce a few daily production processes to help deepen your understanding.

Process 1: new project process

Create composer.json and add dependent extension packs

Run composer install, install the expansion pack, and generate composer.lock

Submit the composer.lock to the code version controller, such as git

Process 2: the project collaborator installs the existing project

After cloning the project, run composer install directly from the root directory to install the specified version of the extension package from composer.lock and its dependencies

This process applies to the deployment of code in a production environment.

Process 3: add a new expansion pack to the project

Add an expansion pack using composer require vendor/package

Submit the updated composer.json and composer.lock to the code version controller, such as git

About composer.lock Fil

The version record of the dependence on each code is kept in the composer.lock file (see figure below), which is submitted to the version controller and used with composer install to ensure the consistency of the version of the code running in the development environment and online production environment of all team collaborators.

About the installation method of the expansion package

So, ready to add an expansion pack, install, update, require three commands can be used to install the expansion pack, which is the right choice?

The answer is: use the composer require command

In addition, in the manual modification of composer.json to add the expansion package, composer update new/package to specify the expansion package update way, can also be correctly installed, but this method is not recommended, because, once you forget to finalize the name of the expansion package, it will enter an irrevocable state, do not leave a pit for yourself.

The above concepts are confusing for both beginners and veterans. Keep this concept in mind:

Composer require new/package is used to install new extensions added to the original project.

If you need to add a version

Composer require "foo/bar:1.0.0"

Update the specified extension to the specified version

Sometimes you have used the expansion pack, added new features, you want to update a separate extension package to the specified version, you can also use require to operate.

As in the following example, you need to update "sami/sami": "3. 0." To "sami/sami": "3.2."

Run on the command line:

The above is all the contents of the article "correctly installing the Composer expansion Pack". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report