Composer is and integral part of Magento 2 development. It is used as PHP dependency manager to manage components and versions.
In this article we will take a look at dependency types and when to use them. In general dependencies define the relationship between modules and identify the reliance between components. You can read the following article for deeper understanding of module dependencies.
According to one of the core principles of Magento we wan to minimize the amount of dependencies therefore it is suggested to use soft dependencies whenever possible.
There are 2 types of dependencies - soft (suggest) and hard (require). In the past there was little to no attention to this but the recent trend is to use the appropriate type whenever possible.
- Hard dependency require should be used to identify the modules that the module cannot function without. It means that the module either directly uses or references logic (methods, classes, interfaces, etc...) from another component, uses objects defined in another module or modifies database entities used by another module.
- Soft dependencies suggest should be used to identify dependencies that are not vital to modules functionality and can function properly even if the module is not available. In general this type of dependency can be used if we are checking if the related module is available, extend the configuration or layout that does not break functionality.
The sequence node in module declaration is also a soft dependency and does not guarantee that the referenced dependency will be available (instead the relation should be defined in composer using require).
That is the basic difference between both dependency types. To cap this off we will show a usage example for each of the types:
"require": { "php": "~5.5.0|~5.6.0|~7.0", "aws/aws-sdk-php": "^3.0" },
"suggest": { "ext-openssl": "Allows working with CloudFront private distributions and verifying received SNS messages", "ext-curl": "To send requests using cURL" },