How to use composer

藏色散人
Release: 2019-08-30 13:59:38
Original
2806 people have browsed it

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

How to use composer

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/package
Copy after login

So when we install symfony/var-dumper, the command line input:

composer require symfony/var-dumper
Copy after login

Composer will automatically find the stable version of var-dumper for us to install. We can see the successful installation prompt:

How to use composer

When we open the directory, we can see that three files were generated in the directory

How to use composer

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([&#39;1&#39;,&#39;2&#39;,&#39;3&#39;]);
dump(123);
Copy after login

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:

How to use composer

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!

Related labels:
source:php.cn
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!