Home > Article > Development Tools > How composer works
The meaning of Composer
1. What is Composer?
Composer is a dependency management tool for PHP. Simply put, our projects usually use other code libraries. At this time, we only declare which code libraries we depend on in the project. By default, it will not be globally Install anything.
2. What is the meaning of Composer?
For modern languages, dependency management tools are basically standard. Java has Maven, Python has pip, Ruby has gem, and Nodejs has npm. PHP is PEAR, but PEAR has many pitfalls: dependency processing is prone to problems, configuration is very complex, command line interface is difficult to use, etc.
It is precisely because of the emergence of Composer that the problem of project dependency has been solved and PHP development work has become like stacking blocks.
Related recommendations: "Composer command usage graphic tutorial"
Through a simple example, let us understand how to use Composer.
1. Create a new composer.json file in the project root directory and write the following content:
2. Execute the composer install command to install the package dependencies
3. Directory structure
4. Development using packages
Working Principle of Composer
How does Composer work? For example, when we install a software, we usually install it through the app store. When we develop PHP projects, we will also face the same problem. For example, if we need a tool to record business logs, can we download the tools we need through a PHP application store?
Packagist is Composer’s default development package repository. You can submit your installation package to packagist. In the future, if you create a new tag or update the code in your VCS (source code management software, such as Github) warehouse, packagist will automatically build a new development package. This is how packagist currently works, in the future packagist will allow you to directly upload development packages and publish your own packages.
The above is the detailed content of How composer works. For more information, please follow other related articles on the PHP Chinese website!