Traditionally, managing third-party code in PHP projects is not an easy maintainable task. Fortunately, the PHP community has Composer, a top-notch dependency manager.
To add dependencies you need to add it manually to the composer.json file.
If composer.lock file exists, install exactly what's specificated on this file
- Otherwise read composer.json file to look out what dependencies needs to be installed
- Write the composer.lock with the information of the project (installed dependencies)
Not any component will be updated with this command.
To add or remove dependencies you need to add it manually to the composer.json file
- The composer.lock file will be ignored
- composer.json file dependencies will be installed and updated (if a dependency is not installed it will be downloaded)
If you can't (or don't know how to add or remove a library which is in fact easy,just add the name of the dependency and version in the require property of the file) modify the composer.json file manually or you prefer use the command line instead, composer has special functions for this :
For example if we want to add a dependency with the command line we will simply execute
composer require twig/twig
- composer.json file will be modified automatically and the new dependency will be added
- the dependency will be downloaded to the project
If you want to remove an unused dependency we will execute simply :
composer remove twig/twig --update-with-dependencies
- Twig will be removed with all his dependencies
However is recommendable to remove the dependency from the require property of the file manually and then execute composer update.