Two ways to use composer to pull libraries

藏色散人
Release: 2020-12-18 15:36:09
forward
3472 people have browsed it

The following tutorial column of composer will introduce you to 2 methods of using composer to pull libraries. I hope it will be helpful to friends in need!

Two ways to use composer to pull libraries

1. There are two ways to use composer to pull the library. The first is to pull it through the command line.

For example, when you need to integrate monolog At this time, we only need to know that composer will place the library in the vendor folder under the current folder by default

So, we can locate the framework root directory through the command line, whether it is windows or linux. Generally speaking, the following command takes Windows as an example. Assume that our framework is installed in the environment directory of phpstudy, and the path is D:\phpstudy\www. We can run cmd as administrator and enter:

cd /d D:\phpstudy\www
Copy after login

Then We can pull it through the command line

composer require monolog/monolog
Copy after login

Wait for a moment, composer will automatically obtain the monolog related files to the local. If you think it is too slow, we can execute the command in the command line and switch to the domestic line:

composer config -g repo.packagist composer https://packagist.phpcomposer.com
Copy after login

2. Next, let’s talk about the second method. The second method is similar to the first one. One more thing is a json file.

In the root directory of the framework, we will find a We can open the composer.json file with an editor. We can find the require key without looking at other information. There is a "php" by default: ">=5.4.0", which means that the php version used must be greater than 5.4. .0

We can use the "library name":"version number method" to define the library list we need, the specific version constraint method, click here to learn and view

Or use Monolog is an example. We can implement this by appending require. The final require is:

"require": {
    "php": ">=5.4.0",
    "monolog/monolog": "1.2.*"
  }
Copy after login

Then save the json file, enter cmd, locate the directory to the same level of the json file, and enter:

composer update
Copy after login

Then we enter the stage of updating the package

Two ways to use composer to pull libraries

When

Two ways to use composer to pull libraries

appears, it means we have installed it. Open the vendor directory in the framework to view related files

The above is the detailed content of Two ways to use composer to pull libraries. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php300
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