Home >Development Tools >composer >How to use composer
How to use composer?
The above describes how to install composer. This chapter will explain how to use composer.
We first simulate downloading a PHP component. First, we search dump on the Packagist website. We can see a list This list displays the query All the dump components are packaged. We see the first symfony/var-dumper. An agreement has been reached between composer and the component. The first information of the component name. Taking the above example, symfony represents the manufacturer name and var-dumper represents Package names. When we install components on the command line, we should use this form:// vendor:厂商名 package:包名 composer require vendor/packageSo when we install symfony/var-dumper, the command line input:
composer require symfony/var-dumperComposer will automatically find the stable version of var-dumper for us to install. We can see the successful installation prompt: When we open the directory, we can see that three files were generated in the directory
The vendor directory is our component directory, the result file of composer.json execution command, composer.lock lists all php components, and the specific version number. Now let’s use this dump component and create a new php file in the root directory:
<?php require "vendor/autoload.php"; dump(['1','2','3']); dump(123);First introduce the automatic loader, and then use the dump method to output variables. The dump method is what we A function that outputs variables in the dump component package. The following picture is the result seen after running the file, which outputs different printing styles: More composer usage techniques Article, please visit the
composer tutorial column to learn!
The above is the detailed content of How to use composer. For more information, please follow other related articles on the PHP Chinese website!