The Composer as a package or dependency manager plays a vital role in helping us manage some of these dependencies which our application requires for optimal performance by saving them on a folder, most times the “vendor” folder.
How to setup composer in an extension
To install Composer in your project, you need an important file called “composer.json”. This file is where you define all the dependencies/packages needed in your project. Under your extension folder create this file “composer.json”.
The “require” key
This is a set of JSON definitions used to tell the composer what packages your extension will depend on. There may be other variables you may need to define in this composer.json file, but most of the time, this “require” key is often the only content of the composer.json file.
In the above code create the “composer.json” file inside your extension. Then inside the composer.json file, goes my “require” key.
The package names consist of a vendor name and a project name. In most cases these names are identical. This naming format plays a vital role in preventing naming conflicts, as two or more persons can have a package with the same name but a different vendor name.
As seen in the above code snippet, we specified, telling Composer to download only the version of dompdf in the version range of 7.77 the composer will download the latest stable version, within the specified version range.
To install these defined dependencies to our extension, we must run the composer “install” command from the terminal in your extension directory. After this command, you will find a vendor folder under the extension, make sure you will upload the folder while creating PR for the miniCal extension.
We can also update some of these installed packages in our extension to their latest version, but this must be done with care to prevent our program from breaking. To update packages, we use the composer update command.