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!
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
Then We can pull it through the command line
composer require monolog/monolog
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
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.*" }
Then save the json file, enter cmd, locate the directory to the same level of the json file, and enter:
composer update
Then we enter the stage of updating the package
When
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!