Let's use Composer!

Composer_Tatsuno Information System

Let's use Composer!

composerThis is my first blog post, Yoshino🔫 from Development. This time I would like to write an article about Composer, a dependency management tool for PHP libraries. I hope you enjoy this article as much as I do.

Click here for table of contents

  • 1. what is Composer?
  • 2. benefits of Composer
  • 3. summary

What is Composer?

Composer manages the libraries and packages that your PHP project needs"Library Dependency Management ToolWhere Composer excels is in theManage dependencies of PHP libraries in a projectThey do.

For example, a project may need a package called A. But to use A, it may need a library called B, and to use B, it may need a library called C. But in order to use A, you may need a library called B, and in order to use B, you may need a library called C. If you collect libraries by hand, you have to resolve all these dependencies by yourself. However, with Composer, if you declare A as the package to use, it will automatically install the package including B and C.


Benefits of Composer

1 . Easy to share development environment.
2 . Keeping the remote repository clean.
3 . Autoloading of own classes and libraries
I would like to explain these three advantages in turn.

Easy to share development environment

In the development process, you will need various libraries. It takes a lot of time and effort for each developer to install and update libraries individually, and it also causes problems such as not being able to standardize the library versions among the members.

But.composeris simply a matter of entering the "compoesr require" command.It automatically resolves library dependencies and downloads the package for you.After entering the "composer require" command, a file called composer.lock will be generated automatically containing the version information of the downloaded package.
You can easily share composer.lock with other members and set up the same environment for them by typing "composer install" in the directory where composer.lock exists.

Keep your remote repository clean.

The libraries installed by Composer are stored in the "vendor" directory.
By leaving the "vendor" directory out of the version control system, you can avoid giving away a large number of libraries to a remote repository. This prevents libraries that have been modified by someone else from being included in version control.

Autoloading of own classes and libraries

PHP has a mechanism called autoloading, which automatically loads files when they are used without explicitly loading them with "include_once".

 "autoload": {
  "classmap": [

composer.jsonto describe the file you want to autoload, and"composer dump-autoloadYou can call the class automatically by typing the command


Composer is a management system that provides a standard format for managing software and required library dependencies for the PHP programming language.
By using this library, theYou can write simple code or use complex processes very easily.composer makes it easy to manage your libraries, so use it actively!