-> Composer manage dependencies of PHP on it’s own, so the developer doesn’t have to worry about different version dependencies. This composer concept is not new, in fact it is inspired by NPM NodeJS. Composer is good for code reusability. Maintain dependencies of whole project.
-> For composer use in your project. There are 2 main requirements
1) Composer should be installed on the system
2) In the project folder composer.json file must be available.
-> In the project folder in command prompt and run command “composer install”.
If composer.json file is not there, then you can directly install your library using command “composer require “{Package Name}”” Package name Like :” paypal/rest-api-sdk-php:*””. It will auto generate composer.json file in the system.
After installing the packages, check the project folder. It should have created one new folder, named with “vendor”. Folder name is permanent, and it will move all packages which were installed in the project to vendor folder. Inside the vendor folder you can see “autoload.php” file.
Autoload file will be helpful in the projects. You can include autoload.php file in your code file and get access to any package by class name to get it work.
In your project using below steps:
-> mkdir “Project name”
-> cd Project name
-> Run composer command “composer require “paypal/rest-api-sdk-php:*””
Note: This command will create new composer.json and composer.lock file and vendor folder that includes all the dependency and library files of the installed packages.
-> Autoload.php file is in vendor folder. Use the file name (autoload.php) in your regular file and get access with class name of the packages.