All you need to know about Composer

All composer commands, depending on your install, may need to use php composer.phar in the install folder for composer, instead of plain composer.

Updating packages

This command changes only the composer.lock file.

composer updateUpdates all packages
composer update --with-dependenciesUpdates all packages and its dependencies
composer update vendor/packageUpdates a certain package from vendor
composer update vendor/*Updates all packages from vendor
composer update --lockUpdates composer.lock hash without updating any packages

Adding packages

This command changes both the composer.json and composer.lock files.

composer require vendor/package.Adds package from vendor to composer.json’s require section and installs it
composer require vendor/package --devAdds package from vendor to composer.json’s require-dev section and installs it.

Removing packages

This command changes both the composer.json and composer.lock files.

composer remove vendor/packageRemoves vendor/package from composer.json and uninstalls it

Installing dependencies

This command doesn’t change any file. If composer.lock is not present, it will create it.

composer.lock should always be committed to the repository. It has all the information needed to bring the local dependencies to the last committed state. If that file is modified on the repository, you will need to run composer install again after fetching the changes to update your local dependencies to those on that file.

composer installDownloads and installs all the libraries and dependencies outlined in the composer.lock file. If the file does not exist it will look for composer.json and do the same, creating a composer.lock file.
composer install --dry-runSimulates the install without installing anything

Updating autoloader

composer dumpautoload -oGenerates optimized autoload files

Passing versions

composer require vendor/pkg "1.3.2"Installs 1.3.2
composer require vendor/pkg ">=1.3.2"Above or equal 1.3.2
composer require vendor/pkg "<1.3.2"Below 1.3.2
composer require vendor/pkg "1.3.*"Latest of >=1.3.0 <1.4.0
composer require vendor/pkg "~1.3.2"Latest of >=1.3.2 <1.4.0
composer require vendor/pkg "~1.3"Latest of >=1.3.0 <2.0.0
composer require vendor/pkg "^1.3.2"Latest of >=1.3.2 <2.0.0
composer require vendor/pkg "^1.3"Latest of >=1.3.0 <2.0.0
composer require vendor/pkg "^0.3.2"Latest of >=0.3.0 <0.4.0 (for pre-1.0)
composer require vendor/pkg "dev-BRANCH_NAME"From the branch BRANCH_NAME

Post a comment

Your email address will not be published. Required fields are marked *

error: Content is protected !!