How to use composer to pull libraries
This article is about how to use composer to pull libraries. The editor thought it was very practical, so I shared it with you as a reference. Let's follow the editor and have a look.
1. There are two ways to pull the library using composer. The first one is pulled from the command line.
For example, when we need to integrate monolog, we just need to know that composer defaults the library to the vendor folder under the current folder.
Therefore, we can navigate to the root directory of the framework through the command line, whether windows or linux. The following command takes windows as an example. Assuming that our framework is installed in the environment directory of phpstudy, and the path is D:\ phpstudy\ www, we can run cmd input as an administrator:
Cd / d D:\ phpstudy\ www
Then we can pull it from the command line.
Composer require monolog/monolog
After waiting for a while, composer will automatically obtain the monolog-related files locally. If you think it is too slow, we can execute the command on the command line and switch to the domestic line:
Composer config-g repo.packagist composer https://packagist.phpcomposer.com
two。 Next, let's talk about the second way, the second way is similar to the first one, and the extra one is the json file.
We will find a composer.json file in the root directory of the frame. We can open it with an editor. We can find the php key without looking at other information. By default, there is a "php": "> = 5.4.0", which means that the version of php used must be greater than 5.4.0.
We can use "library name": "version number method" to define the list of libraries we need, and the specific version constraints. Click here to learn about it.
Let's take monolog as an example. We can do this by appending require. The final require is:
"require": {"php": "> = 5.4.0", "monolog/monolog": "1.2.*"}
Then save the json file, enter cmd, locate the directory to the same level as the json file, and enter:
Composer update
And then enter the stage of updating the package.
When it appears
Thank you for reading! On how to use composer pull library to share here, I hope the above content can be of some help to you, so that you can learn more knowledge. If you think the article is good, you can share it and let more people see it.