Initiate composer in a project:
composer installThis reads composer.json file and creates a Vendor folder with all its stuff for autoloading. Exclude this folder from git. In the entry point of the directory, inside index.php, add this:
require vendor/autoload.phpWhen you want to update the dependencies/classes subsequently, as in when you want to add new classes you might have created:
composer dump-autoloadInitiate composer in a project root folder
composer initChange vendor location by using
"config": {
"vendor-dir": "includes/vendor"
},Different methods of including files Documentation.
"autoload": {
"classmap": [
// include all folders
"./",
//include only classes in a specified folder
"myClasses"
],
"psr-4": {
"Application\\": "app/"
},
"files": [
"helpers/functions.php"
]
},require new packages
composer require webmozart/assert